simulator.simulator¶
The simulator: simulations and scans of models, serially or in a pool.
Simulator.run(model, scan) runs every point of a scan in four steps:
- Compile: a plan per combination of the simulations and the models of the
scan (one plan without a dimension of simulations or of models), with
compile_simulation; the values of the dimensions of values in the units of their targets in every model, once; the times of the dimensions withatin the time unit of every model; the selections and the grid of the output; the observables of the run, ordered, checked against the first model and with their kinds and units, seesbmlsim.simulator.observables. - Points: a point is a tuple of indices, nothing is built per point in the
parent. The points are cut into chunks which share a plan, at most
ceil(n_points / (4 * n_workers))and at mostMAX_CHUNKpoints each. - Worker: a chunk applies the values of each point to its plan and runs it,
see
sbmlsim.simulator.worker; the same function runs serially in the calling process and in a worker of a pool ofsbmlsim.parallel; the observables are evaluated on the native solutions of the points of a chunk before the kept timecourses are interpolated onto a grid. - Assembly: the arrays of the chunks are written into the arrays of the
result, a
ScanResult, and reshaped into the dimensions of the scan.
The result does not depend on the number of workers or the size of the chunks: the values of a scan are fixed before the run. A run which raises raises the error of the first point in the order of the scan which fails, and a run which flags the points which fail keeps their errors in that order.
The integrator settings of a simulator apply to every model it runs: the model of a run, every model of a dimension of models and every model a worker loads, each with its own tolerance per state. A setting of a model which the simulator does not set stays, and a worker loads the model with the integrator and the settings the model has in the calling process.
ScanError
¶
Bases: RuntimeError
A point of a scan failed; the message names its labels and values.
Simulator
¶
Runs simulations and scans of models, see the module.
Attributes:
| Name | Type | Description |
|---|---|---|
n_workers |
the processes of a run, see
|
|
integrator_settings |
dict[str, IntegratorSetting]
|
the settings of the integrator of every model. |
Create a simulator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_workers
|
int | None
|
|
None
|
**integrator_settings
|
IntegratorSetting
|
every setting of the integrator of
roadrunner by its name, e.g. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
set_integrator_settings
¶
Set settings of the integrator for every model run after.
A name the integrator does not have raises when a model is loaded, i.e. before a pool starts.
load
¶
Get a loaded model with the integrator settings of the simulator.
A RoadrunnerSBMLModel is used as it is and gets the settings; an
AbstractModel, with its selections, or a path is loaded.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model is of no supported type, or the integrator has no setting of a name. |
compile
¶
Compile a simulation against a model.
The changes of the model are defaults of the pre-initialization
changes, see Simulation.with_preinit_defaults: a change of the model
applies unless the simulation sets the target.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the simulation does not fit the model, see
|
simulate
¶
Run one simulation with the selections of the model.
The native solution of one simulation, which the fit and the test
suites use; a scan is run.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the simulation does not fit the model. |
RuntimeError
|
if roadrunner fails to integrate. |
run
¶
Run every point of a scan, see the module.
The variables of the result are the kept observables; without observables they are the selections of the model, of the first model of a dimension of models, each a timecourse of its own name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ModelLike | None
|
the model of the run; |
required |
scan
|
Scan | Simulation
|
the scan, a simulation is a scan without dimensions. |
required |
observables
|
Sequence[Observable] | None
|
what the run computes from every simulation, see
|
None
|
time
|
ArrayLike | Quantity | None
|
a grid of times every timecourse is interpolated onto,
numbers in the time unit of the model or a quantity, see
|
None
|
keep
|
Sequence[str] | None
|
the observables of the result, every one by default; the id of a PK observable keeps all its parameters; without observables the selections of the result. The others are evaluated where a kept one needs them and dropped. |
None
|
on_error
|
OnError
|
|
'raise'
|
progress
|
bool | None
|
show a progress bar; |
None
|
Returns:
| Type | Description |
|---|---|
ScanResult
|
The result, see |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the scan does not fit its models, see |
ScanError
|
for a point which fails with |
RuntimeError
|
if a worker of the pool dies. |
scan_point_plans
¶
Get the plans of points of a scan of value dimensions on a compiled plan.
The plan of a point is the plan with the values and times of the point,
scan_point_values, applied by point_plan, the function the workers of a
run apply them with. The fit computes the values once per simulation group
and applies them to the plan of every evaluation, which carries the fitted
values first, so the values of a dimension win over a fitted value of the
same target, as in a run of the scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan
|
Scan
|
the scan, whose dimensions all set values. |
required |
model
|
RoadrunnerSBMLModel
|
the loaded model, whose units the values are converted to. |
required |
plan
|
Plan
|
the compiled plan of |
required |
positions
|
ndarray
|
the index of every point along every dimension, a row per point; the one point of a scan without dimensions is a row of length 0. |
required |
Returns:
| Type | Description |
|---|---|
list[Plan]
|
The plan of every point, in the order of |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a dimension of simulations or models, values which do
not fit the model, a time of a dimension with |
scan_point_values
¶
Get the values and times of points of a scan of value dimensions.
The values are in the units of the model and the times in its time unit,
computed as a run of the scan computes them. point_plan(plan, values,
timed, k) applies them to a plan, see scan_point_plans; the fit computes
them once per simulation group and applies them to the plan of every
evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan
|
Scan
|
the scan, whose dimensions all set values. |
required |
model
|
RoadrunnerSBMLModel
|
the loaded model, whose units the values are converted to. |
required |
plan
|
Plan
|
the compiled plan of |
required |
positions
|
ndarray
|
the index of every point along every dimension, a row per point; the one point of a scan without dimensions is a row of length 0. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
target -> the value of every point, and time -> target -> the value of |
dict[float, dict[str, ndarray]]
|
every point for the dimensions with |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a dimension of simulations or models, values which do
not fit the model, a time of a dimension with |