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,
)

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

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 which carries the observables of the problem is written to, next to the model by default. It is only written if an observable of the problem is a formula.

None

Raises:

Type Description
ValueError

if the problem has no model or no measurements.

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.

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.

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 observable, from its measurements.

fit_mappings

fit_mappings(experiment)

Get the fit mappings, one per observable of the problem.

Parameters:

Name Type Description Default
experiment SimulationExperiment

experiment the mappings belong to.

required

Returns:

Type Description
dict[str, FitMapping]

The mappings by the id of their observable.

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.