experiment.runner¶
Runner for SimulationExperiments.
The ExperimentRunner is used to execute simulation experiments. This includes - loading of datasets - loading of models - running tasks (simulation on models) - creating outputs
The experiments of a run are independent of each other, a run of several
experiments runs them in a pool of worker processes (n_workers of
ExperimentRunner.run_experiments): every worker initializes an experiment
again from its class, loads its models once and keeps them for the next
experiment, runs it serially (its scans included, a worker starts no pool) and
writes its outputs; the parent keeps its own initialized experiments, which
the report is created from, and logs the messages of the workers in the order
of the experiments. A run is serial when an experiment cannot be sent to a
worker, see ExperimentRunner._serial_reason.
The models of the experiments are loaded in the engine of the simulator of the
runner, roadrunner without one, see ExperimentRunner.engine: a simulator of
another engine loads them again, and a worker loads them in the engine of the
run.
A run shows its progress on the console and ends with a table of the seconds
every experiment took in every phase, see sbmlsim.experiment.progress: the
phases are measured where they run, in a worker too, and the result of every
experiment carries them (ExperimentResult.timings). The workers of a run
with progress send what their experiments do through a queue, which a thread
of the parent forwards to the display.
ModelKey
¶
Bases: NamedTuple
The model of an experiment in an engine, see model_key.
It decides whether two experiments can share one loaded model.
ExperimentRunner
¶
ExperimentRunner(
experiment_classes,
base_path=None,
data_path=None,
simulator=None,
ureg=None,
on_error="log",
jit_optimization=None,
**kwargs,
)
Class for running simulation experiments.
Initialize the runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_classes
|
type[SimulationExperiment] | Iterable[type[SimulationExperiment]]
|
the simulation experiments. |
required |
base_path
|
Path | None
|
base path of the simulation experiments, |
None
|
data_path
|
Path | Iterable[Path] | None
|
path or paths of the datasets of the simulation
experiments, |
None
|
simulator
|
Simulator | None
|
the simulator of the tasks, the models are loaded in
its engine, see |
None
|
ureg
|
UnitRegistry | None
|
the unit registry of the experiments. |
None
|
on_error
|
Literal['raise', 'log']
|
what an error in the definition of an experiment does (its
models, datasets, simulations, tasks, data, figures, fit mappings
and their checks). |
'log'
|
jit_optimization
|
JitOptimization | str | None
|
the optimization level every model is compiled
with, see |
None
|
**kwargs
|
Any
|
settings of the experiments, |
{}
|
engine
property
¶
Get the engine the models are loaded in: the one of the simulator.
Roadrunner without a simulator.
set_simulator
¶
Set the simulator on the runner and the experiments.
A simulator of another engine than the one of the loaded models loads
them again in its engine, the models of the runner and of every
experiment, see sbmlsim.model.model_sbml.load_model; a state set on
a model of the other engine is not carried over. A simulator of the
same engine keeps them. None keeps the simulator.
initialize
¶
Initialize ExperimentRunner.
Initialization is required in addition to construction to allow serialization of information for parallelization.
run_experiments
¶
run_experiments(
output_path,
show_figures=False,
save_results=False,
figure_formats=None,
reduced_selections=True,
keep_results=False,
raise_on_failure=False,
figure_settings=None,
n_workers=None,
progress=None,
)
Run the experiments and write their outputs.
The run shows its progress on the console of the package, a bar over
the experiments and a row per running experiment with what it does,
and ends with a table of the seconds every experiment took in every
phase, see sbmlsim.experiment.progress. The seconds are in the
results as well, ExperimentResult.timings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
directory of the outputs, one directory per experiment. |
required |
show_figures
|
bool
|
show the matplotlib figures. |
False
|
save_results
|
bool
|
write the results of the tasks. |
False
|
figure_formats
|
list[str] | None
|
formats of the figures. |
None
|
reduced_selections
|
bool
|
simulate only the selections an experiment uses. |
True
|
keep_results
|
bool
|
keep the results of every experiment after its outputs
are written. By default they are released, so a run holds only
the results of the experiment it runs and not of all experiments
until its end; |
False
|
raise_on_failure
|
bool
|
raise an |
False
|
figure_settings
|
FigureSettings | Mapping[str, Any] | None
|
the settings of the figures of every experiment,
a |
None
|
n_workers
|
int | None
|
the processes which run the experiments: |
None
|
progress
|
bool | None
|
show the progress and the timings on the console; |
None
|
Returns:
| Type | Description |
|---|---|
list[ExperimentResult]
|
The results of the experiments, which the report is created from. |
Raises:
| Type | Description |
|---|---|
ExperimentRunError
|
with |
ValueError
|
if a key of |
model_key
¶
Get the key a loaded model is cached under.
Two experiments share a loaded model when they resolve to the same source,
the same language, the same changes, the same added parameters and the
same selections in the same engine; the changes and the selections are
part of it because they are applied to the model when it is loaded. The source
of a file is its resolved path, the one of inline SBML its content and, for
a hierarchical model, the directory its external models are resolved
against, see SBMLModel. The key is
the description of the model and not the object: an experiment builds its
own AbstractModel, which has no equality of its own, so caching on the
object would never find anything and every experiment would load and
compile the model again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
abstract_model
|
AbstractModel
|
the model of an experiment. |
required |
engine
|
Engine | str
|
the engine the model is loaded in. |
ROADRUNNER
|
Returns:
| Type | Description |
|---|---|
ModelKey
|
The key, hashable and equal for two descriptions of the same model in |
ModelKey
|
the same engine. |
run_experiments
¶
run_experiments(
experiments,
output_path,
base_path=None,
data_path=None,
show_report=False,
raise_on_failure=False,
figure_settings=None,
n_workers=None,
progress=None,
simulator=None,
figure_formats=None,
save_results=False,
reduced_selections=True,
jit_optimization=None,
uncertainty=None,
)
Run simulation experiments and write their report to the output path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiments
|
type[SimulationExperiment] | list[type[SimulationExperiment]]
|
the simulation experiments. |
required |
output_path
|
Path
|
directory of the results and the report. |
required |
base_path
|
Path | None
|
base path of the simulation experiments. |
None
|
data_path
|
Path | Iterable[Path] | None
|
path or paths of the datasets of the simulation experiments. |
None
|
show_report
|
bool
|
open the report in a web browser. |
False
|
raise_on_failure
|
bool
|
raise an |
False
|
figure_settings
|
FigureSettings | Mapping[str, Any] | None
|
the settings of the figures of every experiment, see
|
None
|
n_workers
|
int | None
|
the processes which run the experiments, see
|
None
|
progress
|
bool | None
|
show the progress and the timings of the run, see
|
None
|
simulator
|
Simulator | None
|
the simulator of the tasks, |
None
|
figure_formats
|
list[str] | None
|
the formats of the figures, see
|
None
|
save_results
|
bool
|
write the results of the tasks. |
False
|
reduced_selections
|
bool
|
simulate only the selections an experiment uses. |
True
|
jit_optimization
|
JitOptimization | str | None
|
the optimization level every model is compiled
with, see |
None
|
uncertainty
|
UncertaintyRun | None
|
run every experiment over the draws of the fitted
parameters, its setting |
None
|
Returns:
| Type | Description |
|---|---|
list[ExperimentResult]
|
The results of the experiments. |
Raises:
| Type | Description |
|---|---|
ExperimentRunError
|
with |