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 hands every repeat of the fit to the worker which is free.
The OptimizationProblem is pickled and sent to the workers, so it must be
picklable: every worker initializes it once and runs repeats on it. The start
values are created by the runner, so a fit with a seed gives the same result
for any number of workers.
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.
TotalTimeColumn
¶
Bases: ProgressColumn
The estimated total runtime, ~ H:MM:SS behind the elapsed time.
The estimate is estimate_total_time with the workers field of the
task, so it is corrected for the runs a pool processes at once.
resolve_n_cores
¶
Resolve the number of worker processes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_cores
|
int | None
|
requested number of workers, |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of workers, at least one and at most the number of available cores. |
estimate_total_time
¶
Estimate the total runtime from the runs which are done.
The runs are handed to the workers in batches of workers, so the time of
a batch is what the elapsed time measures: the estimate is the time per
batch times the number of batches. With a single worker this is the mean
time per run times the number of runs. The rate of the progress bar is
not used, it is measured over a window of seconds and a run takes minutes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elapsed
|
float
|
seconds since the start. |
required |
completed
|
float
|
runs which are done. |
required |
total
|
float
|
runs in total. |
required |
workers
|
int
|
runs which are processed at once. |
1
|
Returns:
| Type | Description |
|---|---|
float | None
|
The estimated total runtime in seconds, |
float | None
|
is done. |
optimization_progress
¶
Show the progress of the optimization runs on the console.
The bar shows the count, the elapsed time and the estimated total runtime,
see TotalTimeColumn.
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 |
True
|
unit
|
str
|
what is counted, behind the count. |
'runs'
|
workers
|
int
|
runs which are processed at once, for the estimate. |
1
|
Yields:
| Type | Description |
|---|---|
Progress | None
|
The progress with a single task, or |
run_optimization
¶
run_optimization(
problem,
settings=None,
size=5,
algorithm=LEAST_SQUARE,
seed=None,
n_cores=1,
serial=False,
show_progress=True,
timeout=None,
runs_dir=None,
**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
|
problem to optimize (picklable); it does not have to be
initialized, |
required |
settings
|
FitSettings | None
|
settings of the fit, the defaults of |
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, |
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
|
timeout
|
float | None
|
seconds a single optimization may run, no limit if |
None
|
runs_dir
|
Path | None
|
directory the single runs are written to while the fit runs,
so a fit which is interrupted or crashes leaves the runs which
finished; they are read back with
|
None
|
kwargs
|
Any
|
additional arguments for the optimizer, e.g. xtol. |
{}
|
Returns:
| Type | Description |
|---|---|
OptimizationResult
|
OptimizationResult with the fits of all repeats. A repeat which failed |
OptimizationResult
|
is part of the result and carries its message. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for the removed parameters |
worker_problem
¶
Get the initialized problem of the worker process.
Returns:
| Type | Description |
|---|---|
OptimizationProblem
|
The problem the worker was initialized with. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the worker could not initialize the problem, with the error of the initialization. |
worker_pool
¶
Create the pool of workers of a parallel fit.
Every worker initializes the problem once, see _worker_initialize, and
a task of the pool gets it from worker_problem. The profile likelihood of
sbmlsim.fit.identifiability runs its scans in the same pool.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the workers cannot be started, which is what a script
without the |