engine¶
The engines which simulate a model.
UnsupportedModelError
¶
Bases: ValueError, NotImplementedError
An engine does not simulate a model or a plan as roadrunner does.
The feature checks of COPASI and AMICI raise it before the engine loads,
compiles or runs what it would simulate otherwise, e.g. a fast reaction
or a delayed event; it is a limitation of the engine, not an error of the
model. It is a ValueError (the checks of a model) and a
NotImplementedError (the checks of a plan) alike.
Engine
¶
Bases: StrEnum
The engine which integrates a model.
JitOptimization
¶
Bases: StrEnum
The optimization level LLJIT compiles the code of a model of roadrunner with (#331).
Defined here, with the engines, so a module which names a level, e.g. a
project, does not import roadrunner; sbmlsim.model.model_roadrunner
resolves it, see resolve_jit_optimization.
The levels of LLVM, -O0 to -O3, which roadrunner calls NONE,
LESS, DEFAULT and AGGRESSIVE (LoadSBMLOptions). A level trades
the time of the compilation against the speed of the simulation, measured
with libroadrunner 2.11 on the dulaglutide model of pkdb_models: O0
compiles in 1.1 s, O1 to O3 in 3.9 to 4.2 s and MCJIT, roadrunner's
default JIT, in 6.7 s, while a serial scan of 300 doses takes 4.5 s at
O0 and 3.9 s at O2 and with MCJIT (the midazolam model 0.94 s and
0.75 s). O0 gives the results of MCJIT bitwise, the other levels differ
from them in the last bits, so a fit can take another path.
O2 is the default (DEFAULT_JIT_OPTIMIZATION), it simulates as fast as
MCJIT. O0 pays for a run which compiles more than it simulates, e.g.
the initialization of experiments: the run of all experiments of
dulaglutide takes about 30 s at O0 against 34 s at O2.
installed_roadrunner
¶
Get the version of the installed libroadrunner.
The version of the distribution libroadrunner, read from the metadata of
the environment, which does not import roadrunner.
:return: the version, None when libroadrunner is not installed
roadrunner_requirement
¶
Get the requirement of libroadrunner of the package.
The requirement of the metadata of the installed sbmlsim, e.g.
libroadrunner>=2.12.0.dev714, so the requirement of pyproject.toml is
the only place the build is named.
:return: the requirement, None when the metadata of sbmlsim or the
requirement is missing, e.g. in a checkout which is not installed
roadrunner_problem
¶
Report an installed libroadrunner which does not satisfy the requirement.
The simulations of the package rely on fixes of libroadrunner which are not released yet (roadrunner #1381, #1382, #1383, #1384, #1420, #1430,
1445, #1446, #1460), so it¶
needs a build of the develop branch of libroadrunner, which the index
ROADRUNNER_INDEX serves and PyPI does not have. The release of PyPI
loads the models and simulates them, with other rows at the events and
the changes of a simulation, i.e. it gives wrong results instead of an
error, which is why the install is checked.
:param installed: the version of the installed libroadrunner, None when
it is not installed
:param requirement: the requirement of the package, e.g.
libroadrunner>=2.12.0.dev714
:return: the message which names the install, None when the installed
version satisfies the requirement
satisfies_requirement
¶
Compare an installed version with the requirement of the package.
The floor of a requirement of the form libroadrunner>=<version> is
compared with packaging.version, which costs 2 ms of the import of the
package; a requirement of another form is parsed with
packaging.requirements, which imports packaging.tags and costs 30 ms.
A development version satisfies a floor which is one (>=2.12.0.dev714
is satisfied by 2.12.0.dev714, by a later build and by the release
2.11.1), which is why the comparison is not a comparison of the texts.
:param installed: the installed version
:param requirement: the requirement, e.g. libroadrunner>=2.12.0.dev714
:return: whether the installed version satisfies the requirement
check_roadrunner
¶
Check the installed libroadrunner against the requirement of the package.
Called by import sbmlsim, where it costs the metadata of two
distributions and imports no roadrunner. The environment variable
SKIP_ROADRUNNER_CHECK skips it, and a checkout which is not installed,
whose requirement is unknown, is not checked.
:raises ImportError: when libroadrunner is missing or does not satisfy the requirement, with the commands which install the build
resolve_engine
¶
Resolve an engine from its name.
:param engine: an engine or its name :return: the engine :raises ValueError: for a name which is no engine
kept_encoding
¶
Set the encoding of the locale back to the one before, after calls of COPASI.
COPASI sets the locale of the process to C when it is imported and when
it compiles some models, e.g. one whose conversion factor has an initial
assignment, which makes the preferred encoding of python ASCII, so every
text file and subprocess of the process which is read without an
explicit encoding fails on a character which is not ASCII. The category
LC_CTYPE of the locale, the encoding, is set back to the one before;
the numbers keep the locale C of COPASI (LC_NUMERIC).
:return: a context manager
import_copasi
¶
Import COPASI, the optional extra copasi.
Importing COPASI sets the locale of the process to C, which makes the
preferred encoding of python ASCII, so every text file and subprocess of
the process which is read without an explicit encoding fails on a
character which is not ASCII. The category LC_CTYPE of the locale, the
encoding, is set back to the one before the import; the numbers keep the
locale C of COPASI (LC_NUMERIC).
:return: the module COPASI
:raises ImportError: when python-copasi is not installed
import_amici
¶
Import AMICI, the optional extra amici.
AMICI is built from source on installation: a C++ compiler, a BLAS
library and the headers of HDF5 come from the system, CMake and SWIG from
PyPI; it needs ninja, which the extra installs, to compile a model.
:return: the module amici
:raises ImportError: when AMICI is not installed
import_core
¶
Import the bindings of sbmlsim-core, the Rust engine core.
sbmlsim-core is a dependency of sbmlsim, so the bindings come with every
install of the package and the engine needs no extra; they are imported
here, and never at the import of sbmlsim, so a run of another engine does
not load them.
:return: the module sbmlsim_core
:raises ImportError: when the bindings are not installed
amici_cache
¶
Get the directory of the compiled models of AMICI the workers of a pool load from.
The directory the first model of AMICI of models was loaded from, else
the one of the process, see sbmlsim.model.model_amici.cache_root, so a
worker does not compile the models again into the directory of its own
environment, see sbmlsim.model.model_amici.using_cache.
:param engine: the engine of the models
:param models: the models of the parent
:return: the directory, None for another engine
using_amici_cache
¶
Load the models of AMICI from the directory of compiled models of a parent.
:param root: the directory, see amici_cache; None changes nothing
:return: the context in which the models are loaded from it