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.

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 models the fit simulates are written to, next to the model by default: the model which carries the networks of the problem, <stem>_sciml.xml, and the model which carries its observables, <stem>_observables.xml. A model is only written if the problem has networks in the model or an observable which is a formula.

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.

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)

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

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

An observable which is a formula over the entities of the model is not something roadrunner selects, so the model the fit simulates carries it as an entity, see sbmlsim.fit.petab_v2.observables.

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 timecourses of the extension are used if the problem carries it, which keeps the output grid and the pre-simulations of the fit which was written. Without it a timecourse is built from the periods of the experiment and the times of the measurements it holds.

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_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: it is not itself an entity of a model, so it is exempt from the check which otherwise drops a parameter PEtab estimates that sbmlsim cannot fit, and it is built with the target it writes and the mappings selector of its keys.

Returns:

Type Description
list[FitParameter]

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

list[FitParameter]

problem carries the extension, their unit.

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)

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

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.