Skip to content

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. an algebraic rule 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.

resolve_engine

resolve_engine(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

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()

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()

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

amici_cache

amici_cache(engine, models)

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

using_amici_cache(root)

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