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:
- Every element of the arrays is a constant parameter with its nominal value.
- 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.
- 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 alog_softmax, is a parameter of its own with an assignment rule. - 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 ofRHSis a parameter of the model, which becomes variable, the target ofOBSERVABLEis 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
¶
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
|
|
compile_network
¶
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
|
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 |
NetworkHybridizationError
|
if the model does not exist or a
hybridization does not fit it, e.g. a target of |