Skip to content

sciml.compiler

The compilation of networks into an SBML model.

A network in the right hand side of a model or in an observable is evaluated by the integrator at every step. compile_network writes it into the model as parameters with assignment rules, which roadrunner simulates like any other rule:

  1. Every element of the arrays is a constant parameter with its nominal value.
  2. Every element of an input is a parameter with an assignment rule of its formula, or a constant parameter for an element of an array.
  3. The forward pass runs on expressions (SympyBackend). After every node the expressions of its units are replaced by symbols, and every unit is a parameter with an assignment rule of its expression. The rules stay one layer deep, so the size of the model grows with the number of units and not with the depth of the network. A maximum of a node, the shift of a log_softmax, is a parameter of its own with an assignment rule.
  4. Every element of an output is a parameter with an assignment rule, and the target of an output has the assignment rule target = output. The target of RHS is a parameter of the model, which becomes variable, the target of OBSERVABLE is a parameter which is added.

The ids of the parameters are the ids of sbmlsim.sciml.network. The expressions are written as the MathML of SBML by sbmlmath.

roadrunner inlines the assignment rules when it compiles a model, so the time it takes to load the model grows with the size of the rules as they are inlined, not with the size of the file. A softmax over n units is written without a maximum and inlines to n**2 terms. A log_softmax needs the maximum in every unit and inlines to n**3 terms, and before L3V2 the maximum is a piecewise with n**2 conditions: a log_softmax over more than a few units loads slowly, before L3V2 in particular.

compiled_path

compiled_path(sbml_path, directory=None)

Get the path of the model which carries the networks of a model.

Parameters:

Name Type Description Default
sbml_path Path

the model without the networks.

required
directory Path | None

the directory the model is written to, the directory of the model by default.

None

Returns:

Type Description
Path

<stem>_sciml.xml in the directory.

compile_network

compile_network(sbml_path, hybridizations, output_path)

Write a model with the networks of its right hand side and observables.

All networks of the patterns RHS and OBSERVABLE are added in one pass and one model is written. The hybridizations of the pattern PRE_INITIALIZATION are not a part of the model and are left out.

Parameters:

Name Type Description Default
sbml_path Path

the SBML model without the networks.

required
hybridizations Sequence[Hybridization]

the hybridizations of the model.

required
output_path Path

the path the model with the networks is written to, see compiled_path.

required

Returns:

Type Description
Path

The path of the model which was written.

Raises:

Type Description
NetworkCompilationError

if no hybridization is compiled, if the hybridizations name different models, if two hybridizations of a network differ, if two networks give a constant different values, if two networks set one target, if an id of a network is an id of the model or of another part of a network, if a formula of an input uses a symbol which is neither a constant of the hybridization nor a value in the math of the model at its level and version (see _Model.is_value), if an initial assignment sets a target, if an expression has no MathML of SBML, or if the model with the networks is not valid SBML. The message names the network.

NetworkHybridizationError

if the model does not exist or a hybridization does not fit it, e.g. a target of RHS which is not a parameter or which a rule or an event sets, see Hybridization.validate. Hybridization also refuses a network with a layer or function which is not evaluated on expressions for the patterns which are compiled.