sbmlsim¶
Simulation of SBML models with sbmlsim-core.
sbmlsim-core compiles an SBML model to WebAssembly and simulates it with its
engine (CVODE of SUNDIALS). It is part of the simulate extra and imported
when a simulation runs, so the rest of the package works without it. See
SBMLSIM_INSTALL.
The compiler reads flat SBML level 3 (version 1 or 2) without a required
package, while the converters read every level: compilable_sbml converts a
level 1 or 2 model and flattens the comp package of a model before it is
compiled.
runtime
¶
The runtime of this process, created on first use.
The engine is compiled once and shared by every model of the process.
Returns:
| Type | Description |
|---|---|
Any
|
The |
compilable_sbml
¶
The model as flat SBML level 3, converted when it is not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml
|
str
|
SBML document as string. |
required |
base_path
|
Path | None
|
directory the |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The document, converted to level 3 version 2 when its level is lower |
str
|
and flattened when it requires the |
str
|
when neither applies. |
Raises:
| Type | Description |
|---|---|
SimulationError
|
if the document has no model or cannot be converted. |
state_scale
¶
Smallest nonzero magnitude of the initial value of a state.
The states of the solver of an SBML model are the amounts of its
species and the compartments and parameters a rate rule determines; the
compiler lists them in the description of the model and the loaded model
evaluates their initial values. An absolute tolerance above the
magnitude of a state makes its trajectory meaningless, and the amounts
of a model with a small compartment are small: a species with a
concentration of 1 in a compartment of 1e-13 litre has the amount
1e-13. run_timecourse therefore scales the absolute tolerance with
this magnitude, as roadrunner does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
a |
required |
Returns:
| Type | Description |
|---|---|
float
|
The smallest nonzero magnitude of an initial value of a state, |
float
|
when the model has no state with a finite value other than zero. |
solver_settings
¶
Solver settings of a request of simulation/1.
Every field of the settings of a request is explicit, so the defaults are
spelled out here: CVODE with the time steps it chooses itself
(maximum_time_step and initial_time_step 0.0) and the linear solver
and the jacobian the compiler chose (auto).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relative_tolerance
|
float | None
|
relative tolerance of CVODE,
|
None
|
absolute_tolerance
|
float | None
|
absolute tolerance of CVODE,
|
None
|
maximum_number_of_steps
|
int | None
|
internal steps of CVODE between two time
points, |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The settings of the request. |
load_model
¶
Compile and load an SBML model, from the cache when it is there.
The model is compiled to WebAssembly and loaded into the runtime of the process; the result is kept by the hash of the SBML text, so a model simulated again is neither converted with libsbml nor compiled a second time (libopencor caches a CellML file the same way). An instance of the loaded model is cheap and simulates on a store of its own, so the cached model is shared without a simulation seeing another one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml
|
str
|
SBML document as string, every level. |
required |
base_path
|
Path | None
|
directory the |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Raises:
| Type | Description |
|---|---|
ImportError
|
if sbmlsim-core is not installed. |
SimulationError
|
if the model cannot be made compilable. |
SbmlsimCoreError
|
if sbmlsim-core cannot compile or load the model. |
run_timecourse
¶
run_timecourse(
sbml,
selections=None,
start=0.0,
end=1.0,
steps=100,
relative_tolerance=None,
absolute_tolerance=None,
maximum_number_of_steps=None,
scale_tolerance=True,
warmup=False,
units=None,
timings=None,
base_path=None,
)
Uniform timecourse of an SBML model.
The call is the one of sbml2cellml.simulate.run_timecourse, which
simulates the CellML model of the same conversion: the same arguments
in the same order, a frame with time in the first column and the
selected variables after it, and the units of the columns in units
when a dictionary is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml
|
str | Path
|
path of an SBML file, or the document as a string. |
required |
selections
|
list[str] | None
|
the variables of the result after |
None
|
start
|
float
|
start time. |
0.0
|
end
|
float
|
end time. |
1.0
|
steps
|
int
|
number of intervals, the result has |
100
|
relative_tolerance
|
float | None
|
relative tolerance of CVODE, see
|
None
|
absolute_tolerance
|
float | None
|
absolute tolerance of CVODE, see
|
None
|
maximum_number_of_steps
|
int | None
|
internal steps of CVODE between two time
points, see |
None
|
scale_tolerance
|
bool
|
multiply the absolute tolerance with the smallest
initial value of a state when it is below one ( |
True
|
warmup
|
bool
|
simulate the model once on an instance of its own before the simulation of the result and keep the discarded simulation out of the integration time, as on the CellML side, where libopencor generates the code of a model when it runs it the first time. |
False
|
units
|
dict[str, str] | None
|
filled with the units of every column when a dictionary is
given, by the name of the column ( |
None
|
timings
|
dict[str, float] | None
|
filled with the wall time of the phases when given:
|
None
|
base_path
|
Path | None
|
directory the |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The timecourse with |
DataFrame
|
it, every variable of the model when none are given, one row per |
DataFrame
|
time point. |
Raises:
| Type | Description |
|---|---|
ImportError
|
if sbmlsim-core is not installed. |
SimulationError
|
if the model cannot be made compilable. |
SbmlsimCoreError
|
if sbmlsim-core cannot compile, load or simulate the model. |