sciml.hybridization¶
Where a network sits in a hybrid problem.
A Hybridization connects a Network to a model: what its inputs are, which
entities of the model its outputs set, and in which of three places it runs.
| pattern | inputs | outputs | executed by |
|---|---|---|---|
PRE_INITIALIZATION |
constants: formulas of parameters, arrays | parameters and initial values, set before the simulation | numpy, once per simulation |
RHS |
formulas of species, parameters and time, arrays | parameters of the rate equations | roadrunner, as assignment rules |
OBSERVABLE |
formulas of species, parameters and time, arrays | symbols of an observable | roadrunner, as assignment rules |
A network before the simulation is evaluated by derived_changes, which a
fit calls for every simulation with the values of its parameters. The
networks of the other two patterns are compiled into the model by
sbmlsim.sciml.compiler; derived_changes sets only their inputs which are
arrays of a condition.
The condition of a simulation is the id of the simulation in its experiment.
NetworkPattern
¶
Bases: StrEnum
The place of a network in a hybrid problem.
is_compiled
property
¶
Check whether a network of the pattern is compiled into the model.
NetworkInput
dataclass
¶
An input of a network or an element of one.
Exactly one of the attributes is given.
Attributes:
| Name | Type | Description |
|---|---|---|
formula |
str | None
|
an L3 formula of SBML which holds for every condition, e.g.
|
formulas |
Mapping[str, str] | None
|
id of the condition -> formula, for an input which differs
between the conditions. |
arrays |
Mapping[str, ArrayLike] | None
|
id of the condition -> values, |
formula_of
¶
Get the formula of a condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
str
|
id of the condition. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The formula, |
str | None
|
without a formula. |
array_of
¶
Get the array of a condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
str
|
id of the condition. |
required |
Returns:
| Type | Description |
|---|---|
ndarray | None
|
The array, |
ndarray | None
|
without an array. |
Hybridization
dataclass
¶
A network with its inputs, its outputs and its place in a problem.
The hybridization is validated when it is created, as far as it can be
without the model: validate checks it against the model. Two
hybridizations are equal when their attributes are; a hybridization is
not hashable, its attributes are dictionaries.
Attributes:
| Name | Type | Description |
|---|---|---|
network |
Network
|
the network. |
pattern |
NetworkPattern
|
where the network sits. |
model |
str
|
id of the model in the experiment. |
inputs |
Mapping[str, NetworkInput]
|
id of the input -> the input. The id is |
outputs |
Mapping[str, str]
|
id of the element of an output -> target, see
|
frozen |
Collection[str]
|
ids of the elements of the arrays which are not estimated. |
constants |
Mapping[str, float]
|
id -> value of the symbols of the formulas which are neither entities of the model nor parameters of the fit. |
error
¶
Get an error which names the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
what is wrong. |
required |
Returns:
| Type | Description |
|---|---|
NetworkHybridizationError
|
The error, to be raised. |
fit_parameters
¶
Get the parameters of a fit of the network and freeze the rest.
The pattern decides whether the elements are entities of the model,
see sbmlsim.sciml.parameters.network_fit_parameters, and every
element which is not estimated is frozen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimate
|
Mapping[str, bool]
|
key of the entry -> whether the elements are estimated, for the network, a layer or an array. |
required |
bounds
|
Mapping[str, tuple[float, float]] | None
|
key of the entry -> lower and upper bound, none by default. |
None
|
Returns:
| Type | Description |
|---|---|
list[FitParameter]
|
The parameters of the fit and the hybridization with the other |
Hybridization
|
elements frozen. |
Raises:
| Type | Description |
|---|---|
NetworkImportError
|
if a key does not name the network, a layer or an array, or if an estimated element has no value. |
summary
¶
Describe the network for the console and the report.
Returns:
| Type | Description |
|---|---|
HookSummary
|
The id of the network, its pattern, its layers with their types |
HookSummary
|
in the order of the forward pass, the targets of its outputs and |
HookSummary
|
one group per array of the layers the forward pass calls, with |
HookSummary
|
the ids of all elements of the array. |
conditions
¶
Get the conditions for which an input has formulas or arrays.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
id of an input -> the conditions its formulas or arrays name, |
dict[str, list[str]]
|
without |
symbols
¶
Get the ids whose values derived_changes reads.
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
The symbols of the formulas of the inputs and the ids of the |
frozenset[str]
|
elements which are not frozen, for a network before the |
frozenset[str]
|
simulation. For a network which is compiled, which the model |
frozenset[str]
|
evaluates, the ids of the frozen elements and of the outputs: |
frozenset[str]
|
the model must have them, and |
frozenset[str]
|
model carries the values of the frozen elements. |
targets
¶
Get the entities of the model derived_changes sets.
The targets are the keys of derived_changes as they are written:
the id of an entity or the selection of the concentration of a
species ([prey]), which sbmlsim.fit.derived compares by their
entity (entity_of).
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
The targets of the outputs for a network before the simulation, |
frozenset[str]
|
and the ids of the elements of the inputs which are arrays of |
frozenset[str]
|
conditions for a network which is compiled. |
check_parameters
¶
Check the targets of the parameters of a fit against the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
Collection[str]
|
the entities the parameters of the fit write, without the prefix of a target which is not an entity of the model. |
required |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if a parameter writes an element which is frozen, an output or its target, or an element of an input. |
input_values
¶
Get the inputs of the network for the values of a simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Mapping[str, float]
|
id -> value of the parameters of the fit, of the changes of the simulation and of the entities of the model, in the units of the model. The constants of the hybridization are the values of the symbols which are not part of it. |
required |
condition
|
str
|
id of the condition of the simulation. |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
The inputs, one array per input of the forward pass. |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if an input has no formula or array for the condition, if a symbol of a formula has no value, or if the value of a formula is not defined or not a finite number. |
derived_changes
¶
Get the changes of a simulation which follow from its values.
A network before the simulation is evaluated: its inputs are resolved
with input_values, its arrays are the nominal values with the
values of the elements which are not frozen, which the fit estimates,
and its outputs are the changes of their targets. For a network which
is compiled the changes are the elements of the inputs which are
arrays of conditions, and the values of its frozen elements are
compared with the network, which is how a model which was compiled
from another network is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Mapping[str, float]
|
id -> value, see |
required |
condition
|
str
|
id of the condition of the simulation. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
target -> value, in the unit of the target in the model. |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if an input cannot be resolved, see
|
validate
¶
Check the hybridization against the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml_path
|
Path
|
the SBML model the network is a part of, without the network. |
required |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if the model cannot be read, if a
target cannot be set by the network, see |
input_shapes
¶
Get the shapes of the inputs of the forward pass of a network.
The shape of an input which is given as an array is the shape of its arrays. The shape of an input which is given element by element follows from the indices of its elements, which have to cover it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network. |
required |
inputs
|
Mapping[str, NetworkInput]
|
id of the input -> the input, see |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, ...]]
|
The shape of every input, in the order of the forward pass. |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if an id is not the id of an input, if an input is given as an array and element by element, if an input of the forward pass is missing, or if the elements of an input do not cover a shape. |
output_shapes
¶
Get the shapes of the outputs of a network for inputs of given shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network, with the values of its arrays. |
required |
shapes
|
list[tuple[int, ...]]
|
the shape of every input, in the order of the forward pass. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, ...]]
|
The shape of every output, in the order of the forward pass. |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if the network cannot be evaluated on inputs of the shapes. |
NetworkImportError
|
if an array of the network has no values. |
entity_of
¶
Get the entity of the model a target names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the entity or the selection of its concentration, e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The id of the entity, e.g. |
read_model
¶
Read the model of an SBML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml_path
|
Path
|
the SBML file. |
required |
network
|
str
|
id of the network, for the message. |
required |
Returns:
| Type | Description |
|---|---|
SBMLDocument
|
The document and its model. The model is a part of the document and |
Model
|
is valid as long as the document is referenced. |
Raises:
| Type | Description |
|---|---|
NetworkHybridizationError
|
if the file does not exist or holds no model. |