Skip to content

fit.petab_v2.reader

Read a PEtab v2 problem into an sbmlsim optimization problem.

The tables of a PEtab problem are translated into a SimulationExperiment, in the same way a SED-ML parser builds an experiment from a SED-ML document: the models of the problem are the models of the experiment, its experiments are the timecourse simulations, its observables are the fit mappings and the measurements of an observable are its dataset.

A problem which was written by sbmlsim.fit.petab_v2.export carries the sbmlsim extension, which holds what the tables do not: the units, the settings of the fit, the kind of every mapping and the timecourses with their output grid. The reader uses it when it is there, so that a round trip gives the fit which was written, and falls back on the tables when it is not, which is the case for a problem of another tool.

PetabExperiment

PetabExperiment(
    sid=None,
    base_path=None,
    data_path=None,
    ureg=None,
    **kwargs,
)

Bases: SimulationExperiment

Importable implementation of an experiment backed by PEtab data.

models

models()

Get the model definitions of the bound PEtab problem.

datasets

datasets()

Get the measurements of the bound PEtab problem.

simulations

simulations()

Get the simulations of the bound PEtab problem.

tasks

tasks()

Get the tasks of the bound PEtab problem.

fit_mappings

fit_mappings()

Bind measurements and model predictions to this experiment.

PetabReader

PetabReader(
    petab_problem,
    base_path=None,
    name=None,
    derived_dir=None,
    sciml=None,
)

Read a PEtab v2 problem as an sbmlsim simulation experiment and fit.

Attributes:

Name Type Description
sciml SciMLReader | None

the networks of a problem of PEtab SciML, None for a problem without them.

Initialize the reader.

Parameters:

Name Type Description Default
petab_problem Problem

problem to read.

required
base_path Path | None

directory the files of the problem are relative to, the directory of its YAML file by default.

None
name str | None

name of the simulation experiment class which is created, the id of the problem by default.

None
derived_dir Path | None

directory the model the fit simulates is written to, next to the model by default: the model which carries the networks of the problem, <stem>_sciml.xml. It is only written if the problem has networks in the model.

None
sciml SciMLConfig | Mapping[str, Any] | None

the block of the extension of PEtab SciML, a SciMLConfig or the dictionary of the YAML. It is the block of the configuration of the problem by default, which a problem carries that petab has read with its networks. from_yaml reads the tables without the block and hands it over.

None

Raises:

Type Description
ImportError

if the problem has neural networks and the extra sciml is not installed.

ValueError

if the problem has no model or no measurements, if it requires an extension sbmlsim does not know, or if its networks cannot be read, see sbmlsim.fit.petab_v2.sciml.SciMLReader.

settings property

settings

Get the settings of the fit, the defaults without the extension.

Without the extension the settings are the ones of PEtab: a data point at the time of a change is compared with the state after the change (DataAtChangeType.AFTER), and so it is with an extension of a version before 0.4.0, whose settings have no data_at_change, see FitSettings.from_dict, and the fit minimizes the negative log-likelihood of the noise models (ObjectiveType.LIKELIHOOD), so the parameters of the noise are estimated as PEtab defines them.

experiment_ids property

experiment_ids

Get the experiments which are simulated.

A measurement which names no experiment is "use the model as is", i.e. DEFAULT_EXPERIMENT, which a problem of one condition does not have to declare (PEtab v2, measurement table).

from_yaml staticmethod

from_yaml(yaml_file, name=None, *, derived_dir=None)

Read the problem of a PEtab YAML file.

Parameters:

Name Type Description Default
yaml_file Path

path of the YAML file of the problem.

required
name str | None

name of the simulation experiment class which is created.

None
derived_dir Path | None

directory for compiled models, next to the source model by default, see the constructor.

None

Returns:

Type Description
PetabReader

The reader of the problem.

Raises:

Type Description
ImportError

if the problem has neural networks and the extra sciml is not installed.

ValueError

if the problem is a problem of PEtab v1, which is converted first, or requires an extension sbmlsim does not know. The extensions are checked on the YAML, before petab reads the problem: it needs the package of an extension to read its files.

observable_info

observable_info(key)

Get what the extension says about a fit mapping, empty without one.

Parameters:

Name Type Description Default
key str

key of the fit mapping. The block observables of the extension is keyed by the fit mapping since its version 0.2.0, and by the observable before: an observable measured in several experiments is one observable of several fit mappings, each with its own kind and weight.

required

models

models()

Get the models of the experiment, one per model of the problem.

model_source

model_source(model_id=None)

Get the file of the model the fit simulates.

Parameters:

Name Type Description Default
model_id str | None

id of the model, the first model of the problem by default.

None

Returns:

Type Description
Path

The path of the model, see _model_source.

Raises:

Type Description
ValueError

if the problem has no model of the id.

simulations

simulations()

Get the simulations, one per experiment of the problem.

The simulation of the extension is used if the problem carries it, which keeps the output and the units of the fit which was written. Without it a simulation is built from the periods of the experiment.

tasks

tasks()

Get the tasks, one per experiment of the problem.

datasets

datasets()

Get the datasets, one per fit mapping, from its measurements.

fit_mappings

fit_mappings(experiment)

Get the fit mappings, one per observable and experiment.

Parameters:

Name Type Description Default
experiment SimulationExperiment

experiment the mappings belong to.

required

Returns:

Type Description
dict[str, FitMapping]

The mappings by their key, which is the id of their observable,

dict[str, FitMapping]

and <observable>_<experiment> for an observable which is

dict[str, FitMapping]

measured in several experiments.

observable_model

observable_model(key)

Get the observable model of a fit mapping of the problem.

An observable whose formula is the identifier of an entity of the model is the selection of the entity, which keeps its unit. Every other observable is an ObservableModel: its formula in the selections of roadrunner, evaluated on the simulation at the measurements, with the observable parameters of every measurement as the values of its placeholders. The observable model is read once.

Parameters:

Name Type Description Default
key str

key of the fit mapping, see noise_model.

required

Returns:

Type Description
ObservableModel | None

The observable model, None for an observable which is an entity.

Raises:

Type Description
ValueError

if the problem has no fit mapping of the key, or if a measurement does not have a value for every placeholder.

measurement_rows

measurement_rows()

Get the data point of every measurement of the problem.

The measurements of a fit mapping are its data in the order of their time, so the measurement table and the data of the fit differ in their order.

Returns:

Type Description
list[tuple[str, int]]

The key of the fit mapping and the position in its data of every

list[tuple[str, int]]

measurement, in the order of the measurement table.

observable_id

observable_id(key)

Get the observable of a fit mapping of the problem.

Parameters:

Name Type Description Default
key str

key of the fit mapping, which is the id of its observable, and <observable>_<experiment> for an observable which is measured in several experiments.

required

Returns:

Type Description
str

The id of the observable.

Raises:

Type Description
ValueError

if the problem has no fit mapping of the key.

noise_model

noise_model(key)

Get the noise model of a fit mapping of the problem.

The noise model is read once, see _read_noise_model.

Parameters:

Name Type Description Default
key str

key of the fit mapping, which is the id of its observable, and <observable>_<experiment> for an observable which is measured in several experiments.

required

Returns:

Type Description
NoiseModel

The noise model of the fit mapping.

Raises:

Type Description
ValueError

if the problem has no fit mapping of the key, or if a measurement does not have a value for every placeholder.

experiment_class

experiment_class()

Create the simulation experiment class of the problem.

Returns:

Type Description
type[SimulationExperiment]

A SimulationExperiment subclass which holds the models, the

type[SimulationExperiment]

simulations, the tasks, the datasets and the fit mappings of the

type[SimulationExperiment]

PEtab problem.

fit_parameters

fit_parameters()

Get the parameters which are estimated.

A parameter which a condition assigns to an entity of the model, see _versions, is a versioned parameter, built with the target it writes and the mappings selector of its keys. Every other parameter writes itself: an entity of the model, or a parameter which the model the fit simulates gets, e.g. a parameter of the noise, see models.

Returns:

Type Description
list[FitParameter]

The parameters with their bounds, their start value and, if the

list[FitParameter]

problem carries the extension, their unit.

nominal_parameters

nominal_parameters(problem)

Get the nominal values of the parameters of the fit of the problem.

The nominal value of PEtab is the value a problem is evaluated at, e.g. by the test suite, and it may be outside of the bounds of the parameter, while the start value of the FitParameter is in them. A parameter without a nominal value in the parameter table, e.g. an element of a network, has the one of sbmlsim.fit.petab_v2.likelihood.nominal_parameters.

Parameters:

Name Type Description Default
problem OptimizationProblem

initialized optimization problem of the reader.

required

Returns:

Type Description
ParameterSet

The parameter set nominal.

mapping_collections

mapping_collections(experiment_class)

Get the fit mapping collections of the problem, one per experiment.

An experiment of PEtab is a simulation with its conditions, and the observables which are measured in it are the mappings which belong together, i.e. one FitMappingCollection per experiment of the problem. The collection carries the id of the experiment and, with the sbmlsim extension, the kind the mappings had; without it everything is training data, which is what a PEtab problem means.

Parameters:

Name Type Description Default
experiment_class type[SimulationExperiment]

the simulation experiment the mappings belong to.

required

Returns:

Type Description
list[FitMappingCollection]

The collections, in the order of the experiments of the problem.

to_optimization_problem

to_optimization_problem(opid=None)

Build the optimization problem of the PEtab problem.

Parameters:

Name Type Description Default
opid str | None

id of the problem, the id of the PEtab problem by default.

None

Returns:

Type Description
OptimizationProblem

The problem, which is not initialized: initialize(settings) with

OptimizationProblem

the settings of the reader resolves its data.

dataset_id

dataset_id(observable_id)

Get the id of the dataset which holds the measurements of an observable.

from_petab

from_petab(yaml_file, opid=None, *, derived_dir=None)

Read a PEtab v2 problem as an optimization problem.

Parameters:

Name Type Description Default
yaml_file Path

path of the YAML file of the PEtab problem.

required
opid str | None

id of the optimization problem.

None
derived_dir Path | None

directory for compiled models, next to the source model by default.

None

Returns:

Type Description
OptimizationProblem

The problem and the settings of the fit, i.e. what run_optimization

FitSettings

needs. The settings are the defaults if the problem does not carry the

tuple[OptimizationProblem, FitSettings]

sbmlsim extension.