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
¶
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, |
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, |
None
|
sciml
|
SciMLConfig | Mapping[str, Any] | None
|
the block of the extension of PEtab SciML, a |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
if the problem has neural networks and the extra
|
ValueError
|
if the problem has no model or no measurements, if
it requires an extension |
experiment_ids
property
¶
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
¶
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
|
ValueError
|
if the problem requires an extension |
observable_info
¶
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 |
required |
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
¶
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 |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the problem has no model of the id. |
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.
fit_mappings
¶
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 |
dict[str, FitMapping]
|
measured in several experiments. |
observable_id
¶
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 |
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
¶
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 |
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
¶
Create the simulation experiment class of the problem.
Returns:
| Type | Description |
|---|---|
type[SimulationExperiment]
|
A |
type[SimulationExperiment]
|
simulations, the tasks, the datasets and the fit mappings of the |
type[SimulationExperiment]
|
PEtab problem. |
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
¶
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
¶
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: |
OptimizationProblem
|
the |
dataset_id
¶
Get the id of the dataset which holds the measurements of an observable.
from_petab
¶
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 |
FitSettings
|
needs. The settings are the defaults if the problem does not carry the |
tuple[OptimizationProblem, FitSettings]
|
|