Skip to content

simulator.plans

The plans of simulations and scans, compiled by sbmlsim-core.

Every engine runs plans which sbmlsim-core compiled: compile_scan writes the request scan/1 of a scan (the scan as Scan.to_dict() and the changes of the models of a dimension of models), hands it with the compiled model of every model of the scan to sbmlsim_core.scan.compile_plans and reads its answer, the plans plan/1: per simulation and model the Plan (every time in the time unit of the model, every quantity in the unit of its target, the kinds of the targets, the changes merged into one event per time and the output times), the values of the dimensions of values in the units of the model and the times of the dimensions with at in its time unit. The executors of roadrunner, COPASI and AMICI run these plans, and so does the fit; a scan of the engine core is planned and run by sbmlsim-core as a whole, see sbmlsim.simulator.scan_core.

The model a plan is compiled against is the model of the engine as sbmlsim-core describes it (SBMLModel.planning_model), so the units and the symbols of a plan are the ones of the engine core for every engine. A Plan holds numbers, strings and the symbols of the model, which the values of a point, of a fit or of a subject replace with Plan.with_values, a step on numbers in the units of the model which needs no compiler.

PlannedModel

Bases: Protocol

A model plans are compiled against, e.g. an SBMLModel of any engine.

symbols property

symbols

Get the symbols of the model, which a plan carries.

uinfo property

uinfo

Get the units of the model, which a plan is checked against.

changes property

changes

Get the changes of the model, the defaults of its pre-initialization.

planning_model

planning_model()

Get the model sbmlsim-core compiles the plans against, see planning_model.

SBMLPlanned dataclass

SBMLPlanned(
    sbml, symbols, uinfo, label="model", changes=dict()
)

An SBML which plans are compiled against without loading it in an engine.

Attributes:

Name Type Description
sbml str

the SBML as an engine loads it, see model_sbml.engine_sbml.

symbols ModelSymbols

the symbols of the model.

uinfo UnitsInformation

the units of the model.

label str

the name of the model in a message.

changes Mapping[str, Any]

the changes of the model.

planning_model

planning_model()

Get the model sbmlsim-core compiles the plans against.

CompiledScan dataclass

CompiledScan(plans, vectors, at_times)

A scan compiled against its models, see the module.

Attributes:

Name Type Description
plans dict[tuple[int, int], Plan]

(index of the simulation, index of the model) -> its plan, in the order of the simulations and of the models.

vectors list[list[dict[str, ndarray]]]

model -> dimension -> target -> the values of the dimension in the unit of the target in the model, none for a dimension of simulations or of models.

at_times dict[tuple[int, int], list[float | None]]

plan -> dimension -> the time of its values in the time unit of the model, None for a dimension without at.

jsonable

jsonable(value)

Get a value as JSON types, the numbers as the planner reads them.

A NaN is None and an infinity the string "inf" or "-inf", which the planner reads as the numbers they are, also as the value of a change, where such a text is a number and no formula; the keys of a mapping keep their order, which is semantic in a request (the order of the pre-initialization, of the simulations of a dimension).

Parameters:

Name Type Description Default
value Any

the value, numbers, strings, sequences, mappings and arrays.

required

Returns:

Type Description
Any

The value of JSON types.

Raises:

Type Description
TypeError

for a value of another type.

planning_model

planning_model(sbml, label, engine=None)

Compile an SBML with sbmlsim-core for its plans, once per SBML.

The description of the compiled model is what compile_plans reads of a model: the kinds of its entities, which ones a change sets, their units and the unit of its time. The module is compiled without the optimizer, which changes nothing of the description, and is not loaded. The models are kept by their SBML alone, the label and the engine only name the model in a message.

Parameters:

Name Type Description Default
sbml str

the SBML of the model as its engine loads it, level 3, flat and with the added parameters.

required
label str

the name of the model in a message.

required
engine str | None

the engine whose runs need the plans, for a message, None for a model of no engine.

None

Returns:

Type Description
Any

The CompiledModel of the bindings.

Raises:

Type Description
UnsupportedModelError

for a model sbmlsim-core cannot compile, which no engine runs then.

compile_scan

compile_scan(
    scan, models, keys=None, *, model_changes=True
)

Compile every simulation of a scan against every one of its models.

The changes of a model (AbstractModel.changes) are the defaults of the pre-initialization of every simulation of it, which the planner applies, see changes_of_models, unless model_changes is false.

Parameters:

Name Type Description Default
scan Scan | Simulation

the scan, a simulation is a scan without dimensions.

required
models Sequence[PlannedModel]

the model of the run, or the model of every key of the dimension of models in its order.

required
keys Sequence[str] | None

the keys of the dimension of models (Dimension.models) of models, None for the model of the run.

None
model_changes bool

whether the changes of the models apply.

True

Returns:

Type Description
CompiledScan

The plans, the values and the times.

Raises:

Type Description
ValueError

if a simulation, a value or a time does not fit a model, e.g. a target which is no target of a model or a quantity which cannot be converted into the unit of its target.

UnsupportedModelError

for a model sbmlsim-core cannot compile.

changes_of_models

changes_of_models(models, keys=None)

Get the changes of the models of a request scan/1, as JSON types.

The changes of a model (AbstractModel.changes) are the defaults of the pre-initialization of every simulation of it, which the planner applies (Simulation.with_preinit_defaults): changes of the model of the run, or model_changes of the model of every key of a dimension of models. A model without changes adds nothing.

Parameters:

Name Type Description Default
models Sequence[PlannedModel]

the model of the run, or the model of every key of the dimension of models in its order.

required
keys Sequence[str] | None

the keys of the dimension of models, None for the model of the run.

None

Returns:

Type Description
dict[str, Any]

The fields of the request.

simulation_plan

simulation_plan(model, simulation, *, model_changes=True)

Compile a simulation against a model, see compile_scan.

A simulation on its own is no simulation of a scan, so the message of an error does not name it (The simulation: ... of the planner).

Raises:

Type Description
ValueError

if the simulation does not fit the model.

UnsupportedModelError

for a model sbmlsim-core cannot compile.

planner

planner()

Get the planner of the bindings, the module sbmlsim_core.scan.

scan_error

scan_error(err)

Get the error of sbmlsim of a ScanError of the planner.

The failed point of a scan of on_error="raise" (the kind point) is the ScanError of sbmlsim.simulator.simulator with the labels and values of the point, a simulation the engine does not simulate as roadrunner does (unsupported) an UnsupportedModelError, and a request which does not fit itself or its models (request, units) a ValueError.