petab.v2.core
Types around the PEtab object model.
Classes
|
Base class for PEtab tables. |
|
Base class for PEtab tables. |
|
Base class for PEtab tables. |
|
Base class for PEtab tables. |
|
Base class for PEtab tables. |
|
Base class for PEtab tables. |
|
Base class for PEtab tables. |
|
A change to the model or model state. |
|
A set of changes to the model or model state. |
|
PEtab condition table. |
|
An experiment or a timecourse defined by an ID and a set of different periods. |
|
A period of a timecourse or experiment defined by a start time and a list of condition IDs. |
|
PEtab experiment table. |
|
The configuration of a PEtab extension. |
|
Mapping PEtab entities to model entities. |
|
PEtab mapping table. |
|
A measurement. |
|
PEtab measurement table. |
|
A file in the PEtab problem configuration. |
|
Noise distribution types. |
|
Observable definition. |
|
PEtab observable table. |
|
Parameter definition. |
|
Parameter scales. |
|
PEtab parameter table. |
|
Prior types. |
|
PEtab parameter estimation problem |
|
The PEtab problem configuration. |
- class petab.v2.core.Change(*, targetId: Annotated[str, AfterValidator(func=_valid_petab_id)], targetValue: Basic, **extra_data: Any)[source]
Bases:
BaseModelA change to the model or model state.
A change to the model or model state, corresponding to an individual row of the PEtab condition table.
>>> Change( ... target_id="k1", ... target_value="10", ... ) Change(target_id='k1', target_value=10.0000000000000)
- target_value: sp.Basic
The value to set the target entity to.
- class petab.v2.core.Condition(*, conditionId: Annotated[str, AfterValidator(func=_valid_petab_id)], changes: list[Change], **extra_data: Any)[source]
Bases:
BaseModelA set of changes to the model or model state.
A set of simultaneously occurring changes to the model or model state, corresponding to a perturbation of the underlying system. This corresponds to all rows of the PEtab condition table with the same condition ID.
>>> Condition( ... id="condition1", ... changes=[ ... Change( ... target_id="k1", ... target_value="10", ... ) ... ], ... ) Condition(id='condition1', changes=[Change(target_id='k1', target_value=10.0000000000000)])
- class petab.v2.core.ConditionTable(elements: list[T] = None, *, rel_path: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None)[source]
Bases:
BaseTable[Condition]PEtab condition table.
- property free_symbols: set[Symbol]
Get all free symbols in the condition table.
This includes all free symbols in the target values of the changes, independently of whether it is referenced by any experiment, or (indirectly) by any measurement.
- classmethod from_df(df: DataFrame, **kwargs) ConditionTable[source]
Create a ConditionTable from a DataFrame.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class petab.v2.core.Experiment(*, experimentId: Annotated[str, AfterValidator(func=_valid_petab_id)], periods: list[ExperimentPeriod] = [], **extra_data: Any)[source]
Bases:
BaseModelAn experiment or a timecourse defined by an ID and a set of different periods.
Corresponds to a group of rows of the PEtab experiment table with the same experiment ID.
- periods: list[ExperimentPeriod]
The periods of the experiment.
- property sorted_periods: list[ExperimentPeriod]
Get the periods of the experiment sorted by time.
- class petab.v2.core.ExperimentPeriod(*, time: ~typing.Annotated[float, ~pydantic.functional_validators.AfterValidator(func=~petab.v2.core._is_finite_or_neg_inf)], condition_ids: list[str] = <factory>, **extra_data: ~typing.Any)[source]
Bases:
BaseModelA period of a timecourse or experiment defined by a start time and a list of condition IDs.
This corresponds to a row of the PEtab experiment table.
- class petab.v2.core.ExperimentTable(elements: list[T] = None, *, rel_path: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None)[source]
Bases:
BaseTable[Experiment]PEtab experiment table.
- property experiments: list[Experiment]
List of experiments.
- classmethod from_df(df: DataFrame, **kwargs) ExperimentTable[source]
Create an ExperimentTable from a DataFrame.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class petab.v2.core.Mapping(*, petabEntityId: Annotated[str, AfterValidator(func=_valid_petab_id)], modelEntityId: Annotated[str | None, BeforeValidator(func=_convert_nan_to_none, json_schema_input_type=PydanticUndefined)] = None, name: Annotated[str | None, BeforeValidator(func=_convert_nan_to_none, json_schema_input_type=PydanticUndefined)] = None, **extra_data: Any)[source]
Bases:
BaseModelMapping PEtab entities to model entities.
- class petab.v2.core.MappingTable(elements: list[T] = None, *, rel_path: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None)[source]
Bases:
BaseTable[Mapping]PEtab mapping table.
- classmethod from_df(df: DataFrame, **kwargs) MappingTable[source]
Create a MappingTable from a DataFrame.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class petab.v2.core.Measurement(*, modelId: ~typing.Annotated[str | None, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._valid_petab_id_or_none, json_schema_input_type=PydanticUndefined)] = None, observableId: ~typing.Annotated[str, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._valid_petab_id, json_schema_input_type=PydanticUndefined)], experimentId: ~typing.Annotated[str | None, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._valid_petab_id_or_none, json_schema_input_type=PydanticUndefined)] = None, time: ~typing.Annotated[float, ~pydantic.functional_validators.AfterValidator(func=~petab.v2.core._is_finite_or_pos_inf)], measurement: ~typing.Annotated[float, ~pydantic.functional_validators.AfterValidator(func=~petab.v2.core._not_nan)], observableParameters: list[~sympy.core.basic.Basic] = <factory>, noiseParameters: list[~sympy.core.basic.Basic] = <factory>, **extra_data: ~typing.Any)[source]
Bases:
BaseModelA measurement.
A measurement of an observable at a specific time point in a specific experiment.
- classmethod convert_nan_to_none(v, info: ValidationInfo)[source]
- class petab.v2.core.MeasurementTable(elements: list[T] = None, *, rel_path: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None)[source]
Bases:
BaseTable[Measurement]PEtab measurement table.
- classmethod from_df(df: DataFrame, **kwargs) MeasurementTable[source]
Create a MeasurementTable from a DataFrame.
- property measurements: list[Measurement]
List of measurements.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class petab.v2.core.NoiseDistribution(*values)[source]
-
Noise distribution types.
Noise distributions as used in the PEtab observable table.
- LAPLACE = 'laplace'
Laplace distribution
- LOG_LAPLACE = 'log-laplace'
Log-Laplace distribution
- LOG_NORMAL = 'log-normal'
Log-normal distribution
- NORMAL = 'normal'
Normal distribution
- class petab.v2.core.Observable(*, observableId: Annotated[str, AfterValidator(func=_valid_petab_id)], observableName: str | None = None, observableFormula: Basic | None = None, noiseFormula: Basic | None = None, noiseDistribution: NoiseDistribution = NoiseDistribution.NORMAL, observablePlaceholders: list[Symbol] = [], noisePlaceholders: list[Symbol] = [], **extra_data: Any)[source]
Bases:
BaseModelObservable definition.
- noise_distribution: NoiseDistribution
Noise distribution.
- class petab.v2.core.ObservableTable(elements: list[T] = None, *, rel_path: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None)[source]
Bases:
BaseTable[Observable]PEtab observable table.
- classmethod from_df(df: DataFrame, **kwargs) ObservableTable[source]
Create an ObservableTable from a DataFrame.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property observables: list[Observable]
List of observables.
- class petab.v2.core.Parameter(*, parameterId: ~typing.Annotated[str, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._valid_petab_id, json_schema_input_type=PydanticUndefined)], lowerBound: ~typing.Annotated[float | None, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._convert_nan_to_none, json_schema_input_type=PydanticUndefined)] = None, upperBound: ~typing.Annotated[float | None, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._convert_nan_to_none, json_schema_input_type=PydanticUndefined)] = None, nominalValue: ~typing.Annotated[float | None, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._convert_nan_to_none, json_schema_input_type=PydanticUndefined)] = None, estimate: bool = True, priorDistribution: ~typing.Annotated[~petab.v2.core.PriorDistribution | None, ~pydantic.functional_validators.BeforeValidator(func=~petab.v2.core._convert_nan_to_none, json_schema_input_type=PydanticUndefined)] = None, priorParameters: list[float] = <factory>, **extra_data: ~typing.Any)[source]
Bases:
BaseModelParameter definition.
- property prior_dist: Distribution | None
Get the prior distribution of the parameter.
- Returns:
The prior distribution of the parameter, or None if no prior distribution is set.
- prior_distribution: Annotated[PriorDistribution | None, BeforeValidator(_convert_nan_to_none)]
Type of parameter prior distribution.
- class petab.v2.core.ParameterScale(*values)[source]
-
Parameter scales.
Parameter scales as used in the PEtab parameter table.
- LIN = 'lin'
- LOG = 'log'
- LOG10 = 'log10'
- class petab.v2.core.ParameterTable(elements: list[T] = None, *, rel_path: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None)[source]
Bases:
BaseTable[Parameter]PEtab parameter table.
- classmethod from_df(df: DataFrame, **kwargs) ParameterTable[source]
Create a ParameterTable from a DataFrame.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class petab.v2.core.PriorDistribution(*values)[source]
-
Prior types.
Prior types as used in the PEtab parameter table.
- CAUCHY = 'cauchy'
Cauchy distribution.
- CHI_SQUARED = 'chisquare'
Chi-squared distribution.
- EXPONENTIAL = 'exponential'
Exponential distribution.
- GAMMA = 'gamma'
Gamma distribution.
- LAPLACE = 'laplace'
Laplace distribution.
- LOG_LAPLACE = 'log-laplace'
Log-Laplace distribution
- LOG_NORMAL = 'log-normal'
Log-normal distribution.
- LOG_UNIFORM = 'log-uniform'
Log-uniform distribution.
- NORMAL = 'normal'
Normal distribution.
- RAYLEIGH = 'rayleigh'
Rayleigh distribution.
- UNIFORM = 'uniform'
Uniform distribution.
- class petab.v2.core.Problem(models: list[Model] = None, condition_tables: list[ConditionTable] = None, experiment_tables: list[ExperimentTable] = None, observable_tables: list[ObservableTable] = None, measurement_tables: list[MeasurementTable] = None, parameter_tables: list[ParameterTable] = None, mapping_tables: list[MappingTable] = None, config: ProblemConfig = None)[source]
Bases:
objectPEtab parameter estimation problem
A PEtab parameter estimation problem as defined by
models
condition tables
experiment tables
measurement tables
parameter tables
observable tables
mapping tables
See also PEtab data format specification 2.0.
- add_condition(id_: str, name: str = None, **kwargs: Number | str | Expr)[source]
Add a simulation condition to the problem.
If there are more than one condition tables, the condition is added to the last one.
- Parameters:
id – The condition id
name – The condition name. If given, this will be added to the last mapping table. If no mapping table exists, a new mapping table will be created.
kwargs – Entities to be added to the condition table in the form target_id=target_value.
- add_experiment(id_: str, *args)[source]
Add an experiment to the problem.
If there are more than one experiment tables, the experiment is added to the last one.
- Parameters:
id – The experiment ID.
args – Timepoints and associated conditions (single condition ID as string or multiple condition IDs as lists of strings).
- Example:
>>> p = Problem() >>> p.add_experiment( ... "experiment1", ... 1, ... "condition1", ... 2, ... ["condition2a", "condition2b"], ... ) >>> p.experiments[0] Experiment(id='experiment1', periods=[ExperimentPeriod(time=1.0, condition_ids=['condition1']), ExperimentPeriod(time=2.0, condition_ids=['condition2a', 'condition2b'])])
- add_mapping(petab_id: str, model_id: str = None, name: str = None)[source]
Add a mapping table entry to the problem.
If there are more than one mapping tables, the mapping is added to the last one.
- Parameters:
petab_id – The new PEtab-compatible ID mapping to model_id
model_id – The ID of some entity in the model
name – A name (any string) for the entity referenced by petab_id.
- add_measurement(obs_id: str, *, time: float, measurement: float, experiment_id: str | None = None, observable_parameters: Sequence[str | float] | str | float = None, noise_parameters: Sequence[str | float] | str | float = None)[source]
Add a measurement to the problem.
If there are more than one measurement tables, the measurement is added to the last one.
- Parameters:
obs_id – The observable ID
experiment_id – The experiment ID
time – The measurement time
measurement – The measurement value
observable_parameters – The observable parameters
noise_parameters – The noise parameters
- add_observable(id_: str, formula: str, noise_formula: str | float | int = None, noise_distribution: str = None, observable_placeholders: list[str] = None, noise_placeholders: list[str] = None, name: str = None, **kwargs)[source]
Add an observable to the problem.
If there are more than one observable tables, the observable is added to the last one.
- Parameters:
id – The observable id
formula – The observable formula
noise_formula – The noise formula
noise_distribution – The noise distribution
observable_placeholders – Placeholders for the observable formula
noise_placeholders – Placeholders for the noise formula
name – The observable name
kwargs – additional columns/values to add to the observable table
- add_parameter(id_: str, estimate: bool | str = True, nominal_value: Number | None = None, lb: Number = None, ub: Number = None, prior_dist: str = None, prior_pars: str | Sequence = None, **kwargs)[source]
Add a parameter to the problem.
If there are more than one parameter tables, the parameter is added to the last one.
- Parameters:
id – The parameter id
estimate – Whether the parameter is estimated
nominal_value – The nominal value of the parameter
lb – The lower bound of the parameter
ub – The upper bound of the parameter
prior_dist – The type of the prior distribution
prior_pars – The parameters of the prior distribution
kwargs – additional columns/values to add to the parameter table
- assert_valid(**kwargs) None[source]
Assert that the PEtab problem is valid.
- Parameters:
kwargs – Additional arguments passed to
Problem.validate().- Raises:
AssertionError – If the PEtab problem is not valid.
- property experiments: list[Experiment]
List of experiments in the experiment table(s).
- static from_combine(filename: Path | str) Problem[source]
Read PEtab COMBINE archive (http://co.mbine.org/documents/archive).
See also
petab.v2.create_combine_archive().- Parameters:
filename – Path to the PEtab-COMBINE archive
- Returns:
A
petab.v2.Probleminstance.
- static from_yaml(yaml_config: dict | Path | str, base_path: str | Path = None) Problem[source]
Factory method to load model and tables as specified by YAML file.
- Parameters:
yaml_config – PEtab configuration as dictionary or YAML file name
base_path – Base directory or URL to resolve relative paths
- get_changes_for_period(period: ExperimentPeriod) list[Change][source]
Get the changes for a given experiment period.
- Parameters:
period – The experiment period to get the changes for.
- Returns:
A list of changes for the given period.
- get_lb(free: bool = True, fixed: bool = True)[source]
Generic function to get lower parameter bounds.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Return type:
The lower parameter bounds.
- get_measurements_for_experiment(experiment: Experiment) list[Measurement][source]
Get the measurements for a given experiment.
- Parameters:
experiment – The experiment to get the measurements for.
- Returns:
A list of measurements for the given experiment.
- get_optimization_parameters() list[str][source]
Get the list of optimization parameter IDs from parameter table.
- Returns:
A list of IDs of parameters selected for optimization (i.e., those with estimate = True).
- get_output_parameters(observable: bool = True, noise: bool = True) list[str][source]
Get output parameters.
Returns IDs of symbols used in observable and noise formulas that are not observables and that are not defined in the model.
- Parameters:
observable – Include parameters from observableFormulas
noise – Include parameters from noiseFormulas
- Returns:
List of output parameter IDs, including any placeholder parameters.
- get_priors() dict[str, Distribution][source]
Get prior distributions.
Note that this will default to uniform distributions over the parameter bounds for parameters without an explicit prior.
- Returns:
The prior distributions for the estimated parameters in case the problem has a MAP objective, an empty dictionary otherwise.
- static get_problem(problem: str | Path | Problem) Problem[source]
Get a PEtab problem from a file or a problem object.
- Parameters:
problem – Path to a PEtab problem file or a PEtab problem object.
- Returns:
A PEtab problem object.
- get_startpoint_distributions() dict[str, Distribution][source]
Get distributions for sampling startpoints.
The distributions are the prior distributions for estimated parameters that have a prior distribution defined, and uniform distributions over the parameter bounds for estimated parameters without an explicit prior.
- Returns:
Mapping of parameter IDs to distributions for sampling startpoints.
- get_ub(free: bool = True, fixed: bool = True)[source]
Generic function to get upper parameter bounds.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Return type:
The upper parameter bounds.
- get_x_ids(free: bool = True, fixed: bool = True)[source]
Generic function to get parameter ids.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Return type:
The parameter IDs.
- get_x_nominal(free: bool = True, fixed: bool = True) list[source]
Generic function to get parameter nominal values.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Return type:
The parameter nominal values.
- get_x_nominal_dict(free: bool = True, fixed: bool = True) dict[str, float][source]
Get parameter nominal values as dict.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Returns:
A dictionary mapping parameter IDs to their nominal values.
- property has_map_objective: bool
Whether this problem encodes a maximum a posteriori (MAP) objective.
A PEtab problem is considered to have a MAP objective if there is a prior distribution specified for at least one estimated parameter.
- Returns:
Trueif MAP objective,Falseotherwise.
- property has_ml_objective: bool
Whether this problem encodes a maximum likelihood (ML) objective.
A PEtab problem is considered to have an ML objective if there are no prior distributions specified for any estimated parameters.
- Returns:
Trueif ML objective,Falseotherwise.
- property measurements: list[Measurement]
List of measurements in the measurement table(s).
- property model: Model | None
The model of the problem.
This is a convenience property for `Problem`s with only one single model.
- Returns:
The model of the problem, or None if no model is defined.
- Raises:
ValueError: If the problem has more than one model defined.
- model_dump(**kwargs) dict[str, Any][source]
Convert this Problem to a dictionary.
This function is intended for debugging purposes and should not be used for serialization. The output of this function may change without notice.
The output includes all PEtab tables, but not the models.
See pydantic.BaseModel.model_dump for details.
- Example:
>>> from pprint import pprint >>> p = Problem() >>> p += Parameter(id="par", lb=0, ub=1) >>> pprint(p.model_dump()) {'conditions': [], 'config': {'condition_files': [], 'experiment_files': [], 'extensions': {}, 'format_version': '2.0.0', 'id': None, 'mapping_files': [], 'measurement_files': [], 'model_files': {}, 'observable_files': [], 'parameter_files': []}, 'experiments': [], 'mappings': [], 'measurements': [], 'observables': [], 'parameters': [{'estimate': 'true', 'id': 'par', 'lb': 0.0, 'nominal_value': None, 'prior_distribution': '', 'prior_parameters': '', 'ub': 1.0}]}
- property observables: list[Observable]
List of observables in the observable table(s).
- sample_parameter_startpoints(n_starts: int = 100, **kwargs)[source]
Create 2D array with starting points for optimization
- sample_parameter_startpoints_dict(n_starts: int = 100) list[dict[str, float]][source]
Create dictionaries with starting points for optimization
- Returns:
A list of dictionaries with parameter IDs mapping to sampled parameter values.
- to_files(base_path: str | Path | None) None[source]
Write the PEtab problem to files.
Writes the model, condition, experiment, measurement, parameter, observable, and mapping tables to their respective files as specified by the rel_path and base_path of their respective objects.
This expects that all objects have their rel_path and base_path set correctly, which is usually done by
Problem.from_yaml().- Parameters:
base_path – The base path the yaml file and tables will be written to. If
None, the base_path of the individual tables andProblem.config.base_pathwill be used.
- validate(validation_tasks: list[ValidationTask] = None) ValidationResultList[source]
Validate the PEtab problem.
- Parameters:
validation_tasks – List of validation tasks to run. If
Noneor empty,Problem.validation_tasksare used.- Returns:
A list of validation results.
- validation_tasks: list[ValidationTask]
- class petab.v2.core.ProblemConfig(*, filepath: AnyUrl | Path | None = None, base_path: AnyUrl | Path | None = None, format_version: str = '2.0.0', id: str | None = None, parameter_files: list[AnyUrl | Path] = [], model_files: dict[str, ModelFile] | None = {}, measurement_files: list[AnyUrl | Path] = [], condition_files: list[AnyUrl | Path] = [], experiment_files: list[AnyUrl | Path] = [], observable_files: list[AnyUrl | Path] = [], mapping_files: list[AnyUrl | Path] = [], extensions: list[ExtensionConfig] | dict = {})[source]
Bases:
BaseModelThe PEtab problem configuration.
- property format_version_tuple: tuple[int, int, int, str]
The format version as a tuple of major/minor/patch `int`s and a suffix.
- model_config = {'validate_assignment': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].