Skip to content

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

SciMLProblemError(message, gap=None)

Bases: ValueError

A PEtab SciML problem which cannot be read.

Attributes:

Name Type Description
gap

id of the gap the problem runs into, see sbmlsim.fit.petab_v2.gaps, None for a problem which is not valid.

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

NetworkEntity(
    petab_id, network, kind, k=None, index=None, key=None
)

A part of a network a row of the mapping table names.

Attributes:

Name Type Description
petab_id str

the petabEntityId of the row.

network str

id of the network.

kind str

inputs, outputs or parameters.

k int | None

position of the input or output, None for parameters.

index tuple[int, ...] | None

index of the element, None for an input which is an array and for parameters.

key str | None

the key of the parameters, e.g. net1.layer1.weight, see sbmlsim.sciml.parameters, None for an input or output.

SciMLReader

SciMLReader(
    petab_problem,
    config,
    base_path,
    simulations,
    later_periods=None,
    fallbacks=None,
)

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 petabEntityId.

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 sbmlsim of a problem which sbmlsim wrote, see sbmlsim.fit.petab_v2.sciml_export.

None

Raises:

Type Description
SciMLProblemError

if the problem has not one model, if a network is not in the format YAML, if a row of the mapping table names a network the problem does not have, if a row of the hybridization table cannot be read or assigns something else than an input of a network or an output of a network to an entity of the model, if a period after the first of an experiment sets an input of a network, if an input has no value, or if a parameter of a network has a prior.

NetworkImportError

if a network or its arrays cannot be read.

parameter_ids property

parameter_ids

Get the ids of the parameter table which are arrays of networks.

input_ids property

input_ids

Get the ids which are inputs of networks.

condition_ids property

condition_ids

Get the conditions the array files have arrays for.

is_pre_initialization

is_pre_initialization(sid)

Check whether a network runs before the simulation.

is_compiled_symbol

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

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 sciml-layer-sbml).

NetworkHybridizationError

if the inputs and outputs do not fit a network.

network_parameters

network_parameters(sid)

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]

sbmlsim.sciml.parameters.network_fit_parameters. The elements of

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

fit_parameters(unit_of)

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

parse_entity(petab_id, model_entity_id)

Read a row of the mapping table which names a part of a network.

Parameters:

Name Type Description Default
petab_id str

the petabEntityId of the row.

required
model_entity_id str

the modelEntityId, e.g. net1.inputs[0][1], net1.inputs[0], net1.outputs[0][0], net1.parameters, net1.parameters[layer1] or net1.parameters[layer1].weight.

required

Returns:

Type Description
NetworkEntity | None

The part of the network, None for a row which names an entity of a

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

read_sciml_config(extensions)

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, None for a problem without the extension.

Raises:

Type Description
SciMLProblemError

if the block is not a block of the extension.

parameter_scale

parameter_scale(parameter)

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, None for a parameter without one.

Raises:

Type Description
SciMLProblemError

if the scale is not lin, log or log10.