petab.v2.converters

Conversion of PEtab problems.

Classes

ExperimentsToSbmlConverter(problem[, ...])

Convert PEtab experiments to SBML.

class petab.v2.converters.ExperimentsToSbmlConverter(problem: Problem, default_priority: float | None = None)[source]

Bases: object

Convert PEtab experiments to SBML.

For an SBML-model-based PEtab problem, this class converts the PEtab experiments to initial assignments and events as far as possible.

If the model already contains events, the events implementing the PEtab condition changes are added with a higher priority than the pre-existing events, so that these changes are applied before any pre-existing assignments. This requires that all event priorities in the original model are numeric constants. If exactly one pre-existing event has no priority, it is assigned a priority lower than all other priorities in the model. If multiple events have no priority, their order relative to the condition-change events is undefined, unless default_priority is provided.

The PEtab problem must not contain any identifiers starting with _petab.

All periods and condition changes that are represented by initial assignments or events will be removed from the condition table. Each experiment will have at most one period with a start time of -inf and one period with a finite start time. The associated changes with these periods are only the pre-equilibration indicator (if necessary), and the experiment indicator parameter.

CONDITION_ID_PREEQ_OFF = '_petab_preequilibration_off'

The condition ID of the condition that sets the pre-equilibration indicator to 0.

CONDITION_ID_PREEQ_ON = '_petab_preequilibration_on'

The condition ID of the condition that sets the pre-equilibration indicator to 1.

PREEQ_INDICATOR = '_petab_preequilibration_indicator'
convert() → Problem[source]

Convert the PEtab experiments to SBML events.

Returns:

The converted PEtab problem.

static get_experiment_indicator(experiment_id: str) → str[source]

The ID of the experiment indicator parameter.

The experiment indicator parameter is used to identify the experiment in the SBML model. It is a parameter that is set to 1 for the current experiment and 0 for all other experiments. The parameter is used in the event trigger to determine whether the event should be triggered.

Parameters:

experiment_id – The ID of the experiment for which to create the experiment indicator parameter ID.

petab.v2.converters.assignments_to_experiments(problem: Problem) → Problem[source]

Replace time-dependent piecewise assignments by experiment periods.

Fixed parameters may change over the course of a single simulation, e.g., as described by a v2 experiment with multiple periods. As v1 did not have experiments, then these changes were sometimes directly encoded in an SBML model as assignment rules with piecewise functions. This method takes a v2 problem (possibly converted from a v1 problem) and replaces those SBML assignment rules with v2 experiments.

Note

Measurements without an experiment ID are assigned to a new experiment DEFAULT_EXPERIMENT_ID, if needed, which starts at time 0. Every experiment keeps the period that starts it, without conditions if all of them were replaced, since a period’s time overrides the model’s initial time.

Scope: conversion is supported for SBML assignment rules to parameters that depend on time through the conditions of piecewise functions, and at most linearly through their values, where

  • every such condition is an inequality that can be re-arranged explicitly into t </<=/>/>= …,

  • every piecewise function that depends on time has an explicit “otherwise” piece,

  • every switching time evaluates to a real number in every experiment (it may depend on parameters that are fixed or set by the condition table, but not on estimated ones),

  • and all other symbols are truly constant model parameters.

Within that, the piecewise functions may be combined: a sum of doses given at different times (d1 * piecewise(0, t < t1, 1) + d2 * piecewise(0, t < t2, 1)), phases one after another as several pieces or nested piecewise functions (piecewise(b0, t < t1, piecewise(b1, t < t2, b2))). Each switch that changes the value becomes a period. A value may also change linearly with time within a period (a ramp: piecewise(r * t + a, t <= t_end, 0)). A condition change is applied once at the start of its period, so the target of such an assignment becomes a differential entity instead, with the rate rule d target/dt = <target>_slope, and each period sets both the target and its slope; an assignment that only switches between constant values stays a constant parameter. Anything else raises a NotImplementedError. Initial assignments stay in the model, since they are evaluated once, at the start of the simulation.

Condition changes of the replaced assignments’ symbols are dropped, unless the model, an observable or another change still refers to them.

Warning

As SBML assignment rules, the changes would occur during pre-equilibration. As v2 experiments, the changes do not occur during pre-equilibration. Hence, using this converter may affect the correctness of your model’s pre-equilibration. In this case, you could e.g. keep the SBML assignment rules and/or add indicator variables to trigger them correctly in the model for some/all pre-equilibration conditions.

Parameters:

problem – The PEtab problem to convert. This will not be modified.

Returns:

The converted PEtab problem.

Raises:
  • NotImplementedError – If a time-dependent assignment is outside the scope described above.

  • ValueError – If the converted problem does not pass linting.