fit.petab_v2.sciml¶
The neural networks of a PEtab SciML problem.
PEtab SciML is the extension
sciml of PEtab v2 for hybrid problems, in which a model is combined with
neural networks. This module translates the extension into the objects of
sbmlsim.sciml, which know nothing of PEtab:
| PEtab SciML | sbmlsim |
|---|---|
a network of the block neural_networks with its array files |
Network |
pre_initialization, the hybridization table and the observables |
Hybridization and its NetworkPattern |
| the rows of the mapping table | the ids of the inputs, outputs and arrays |
| the rows of the parameter table of a network | FitParameter per element |
| an array of a condition | an array of the simulation of an experiment |
The module imports sbmlsim.sciml and with it petab_sciml, which is the
extra sciml. sbmlsim.fit.petab_v2.reader imports it only for a problem
with the extension.
petab.v2.Problem.from_yaml of petab 0.9.0 reads the networks of a problem
through PyTorch. torch is no dependency of sbmlsim, so the tables of a
problem are read by petab without the block of the extension, and the
networks, the hybridization tables and the array files are read here.
SciMLProblemError
¶
Bases: ValueError
A PEtab SciML problem which cannot be read.
Attributes:
| Name | Type | Description |
|---|---|---|
gap |
id of the gap the problem runs into, see
|
Initialize the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
what cannot be read. |
required |
gap
|
str | None
|
id of the gap the problem runs into. |
None
|
NetworkEntity
dataclass
¶
A part of a network a row of the mapping table names.
Attributes:
| Name | Type | Description |
|---|---|---|
petab_id |
str
|
the |
network |
str
|
id of the network. |
kind |
str
|
|
k |
int | None
|
position of the input or output, |
index |
tuple[int, ...] | None
|
index of the element, |
key |
str | None
|
the key of the parameters, e.g. |
SciMLReader
¶
Read the networks of a PEtab SciML problem.
Attributes:
| Name | Type | Description |
|---|---|---|
networks |
dict[str, Network]
|
the networks by their id, with the nominal values of the problem. |
entities |
dict[str, NetworkEntity]
|
the parts of the networks the mapping table names, by their
|
Read the networks, the hybridization tables and the array files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
petab_problem
|
Problem
|
the problem, read without the block of the extension. |
required |
config
|
SciMLConfig
|
the block of the extension. |
required |
base_path
|
Path
|
directory the files of the problem are relative to. |
required |
simulations
|
Mapping[str, list[str]]
|
id of the simulation of every experiment -> the ids of the conditions the simulation starts with, which set the inputs of the networks. |
required |
later_periods
|
Mapping[str, list[tuple[float, list[str]]]] | None
|
id of the simulation of every experiment -> the time and the ids of the conditions of every period after the first, which must not set an input of a network. |
None
|
fallbacks
|
Mapping[str, str] | None
|
id of an input -> its formula for the simulations
without a formula of their own, in the math of PEtab, which
the conditions repeat: the block |
None
|
Raises:
| Type | Description |
|---|---|
SciMLProblemError
|
if the problem has not one model, if a network
is not in the format |
NetworkImportError
|
if a network or its arrays cannot be read. |
parameter_ids
property
¶
Get the ids of the parameter table which are arrays of networks.
is_pre_initialization
¶
Check whether a network runs before the simulation.
is_compiled_symbol
¶
Check whether a symbol is used by a network which is compiled.
Such a symbol is a parameter of the model with the networks, so a parameter of the fit of its id is an entity of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
id of a parameter of the parameter table. |
required |
hybridizations
¶
Get the hybridizations of the networks of the problem.
The pattern of a network is PRE_INITIALIZATION when the problem
says so. Otherwise an output which an observable uses is
OBSERVABLE and an output which the hybridization table assigns to
an entity of the model is RHS, and a network with outputs of both
kinds has two hybridizations.
The hybridizations are built once, so the model the networks are compiled into and the problem are built from the same objects.
Returns:
| Type | Description |
|---|---|
list[Hybridization]
|
The hybridizations, in the order of the networks of the problem. |
Raises:
| Type | Description |
|---|---|
SciMLProblemError
|
if an output of the mapping table is not an
element of the outputs of its network, if an output is
assigned to a target and used by an observable, if a network
has no output which is used, or if a network in the model has
a layer without MathML of SBML (gap |
NetworkHybridizationError
|
if the inputs and outputs do not fit a network. |
network_parameters
¶
Get the parameters of the fit which are elements of a network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sid
|
str
|
id of the network. |
required |
Returns:
| Type | Description |
|---|---|
list[FitParameter]
|
One parameter per estimated element, see |
list[FitParameter]
|
|
list[FitParameter]
|
a network which runs before the simulation are not entities of |
list[FitParameter]
|
the model. The parameters are resolved once, every call gets |
list[FitParameter]
|
copies of them. |
fit_parameters
¶
Get the parameters of the fit which the networks add.
These are the estimated elements of the networks and the estimated parameters of the parameter table which are inputs of networks and not entities of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_of
|
Callable[[str], str | None]
|
gets the unit of an entity of the model. |
required |
Returns:
| Type | Description |
|---|---|
list[FitParameter]
|
The parameters, the inputs first and the elements in the order of |
list[FitParameter]
|
the networks. |
parse_entity
¶
Read a row of the mapping table which names a part of a network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
petab_id
|
str
|
the |
required |
model_entity_id
|
str
|
the |
required |
Returns:
| Type | Description |
|---|---|
NetworkEntity | None
|
The part of the network, |
NetworkEntity | None
|
model. |
Raises:
| Type | Description |
|---|---|
SciMLProblemError
|
if the row names a part of a network and is not one of the forms. |
read_sciml_config
¶
Get the block of the extension sciml of a problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extensions
|
Mapping[str, Any] | None
|
the blocks of the extensions of the YAML of the problem. |
required |
Returns:
| Type | Description |
|---|---|
SciMLConfig | None
|
The configuration, |
Raises:
| Type | Description |
|---|---|
SciMLProblemError
|
if the block is not a block of the extension. |
parameter_scale
¶
Get the scale of a parameter of the parameter table.
PEtab v2 has no scale of a parameter, it is a property of the
optimization. The problems of PEtab SciML carry the column
parameterScale of PEtab v1, which is read when it is there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
Any
|
parameter of the parameter table. |
required |
Returns:
| Type | Description |
|---|---|
ParameterScaleType | None
|
The scale, |
Raises:
| Type | Description |
|---|---|
SciMLProblemError
|
if the scale is not |