Skip to content

fit.runner

Module for running parameter optimizations.

The optimization runs either serial or in parallel. The parallel optimization uses multiprocessing, i.e., the runner starts one worker process per core and every worker runs a part of the repeats of the problem.

The OptimizationProblem is pickled and sent to the workers, so it must be picklable: it is initialized in the worker, not before. The workers report every finished run through a queue, which drives the progress display of the runner.

The runner only optimizes. Its result carries the fitted parameters and the settings of the fit, and sbmlsim.fit.report.FitReport turns them into figures and reports, see sbmlsim.fit.parameters.

resolve_n_cores

resolve_n_cores(n_cores)

Resolve the number of worker processes.

Parameters:

Name Type Description Default
n_cores int | None

requested number of workers, None uses all available cores but one.

required

Returns:

Type Description
int

Number of workers, at least one and at most the number of available cores.

optimization_progress

optimization_progress(description, size, enabled=True)

Show the progress of the optimization runs on the console.

Parameters:

Name Type Description Default
description str

text in front of the progress bar.

required
size int

total number of optimization runs.

required
enabled bool

show the progress, a plain context without display if False.

True

Yields:

Type Description
Progress | None

The progress with a single task, or None if it is disabled.

run_optimization

run_optimization(
    problem,
    settings=None,
    size=5,
    algorithm=LEAST_SQUARE,
    seed=None,
    n_cores=1,
    serial=False,
    show_progress=True,
    **kwargs,
)

Run the optimization of the problem.

The runner executes the given OptimizationProblem size times, every repeat starting from its own sample of the parameters, and returns the OptimizationResult with the fitted parameters and the settings of the fit.

Parameters:

Name Type Description Default
problem OptimizationProblem

uninitialized problem to optimize (picklable).

required
settings FitSettings | None

settings of the fit, the defaults of FitSettings are used if none are given.

None
size int

number of optimizations.

5
algorithm OptimizationAlgorithmType

optimization algorithm to use.

LEAST_SQUARE
seed int | None

random seed (for sampling of the start values).

None
n_cores int | None

number of workers, None uses all available cores but one.

1
serial bool

run the optimization in a serial fashion (debugging).

False
show_progress bool

show the progress of the runs on the console.

True
kwargs Any

additional arguments for the optimizer, e.g. xtol.

{}

Returns:

Type Description
OptimizationResult

OptimizationResult with the fits of all repeats.

Raises:

Type Description
ValueError

for the removed parameters fitting_type and weighting_local.

worker

worker(kwargs)

Run a part of the optimizations in a worker process.

Every worker initializes the same problem and would report the same messages about the data, once per core. Only errors of a worker are shown, the runner reports the problem itself.