amici.petab.petab_importer
PEtab v2 handling.
Functionality for importing and simulating PEtab v2 problems.
The relevant classes are:
PetabImporter: Import a PEtab problem as an AMICI model.PetabSimulator: Simulate PEtab problems with AMICI.ExperimentManager: Createamici.ExpDataobjects for PEtab experiments.
See PEtab 2.0 import for example usage.
Functions
Flatten timepoint-specific output parameter overrides. |
|
|
Check if the measurements have timepoint-specific observable or noise parameter overrides. |
|
Create a measurement dataframe in the PEtab format from the passed |
|
Create a simulation dataframe in the PEtab format from the passed |
|
Unflatten simulations from a flattened PEtab problem. |
Classes
|
Handles the creation of |
|
Convert PEtab experiments to amici events and PySB initials. |
|
Importer for PEtab2 problems. |
|
Simulator for PEtab2 problems. |
- class amici.petab.petab_importer.ExperimentManager(model, petab_problem)[source]
Handles the creation of
ExpDataobjects for a given model and PEtab problem.The assumption is that we have a set of
amici.ExpDataobjects, one for each PEtab experiment. Those are updated based on a set of global parameters (PEtab problem parameters, as opposed to model parameters for a single experiment period).- __init__(model, petab_problem)[source]
Initialize the ExperimentManager.
- Parameters:
model (
amici.amici.Model) – The AMICI model to use.petab_problem (
petab.v2.core.Problem) – The PEtab problem to use. This is expected to be the output ofpetab.v2.ExperimentsToSbmlConverteror an equivalent problem. This object must not be modified after the creation of thisExperimentManagerinstance.
- apply_parameters(edata, problem_parameters)[source]
Apply problem parameters.
Update the parameter-dependent values of the given ExpData instance according to the provided problem parameters (i.e., values of the parameters in the PEtab parameter table).
This assumes that:
the ExpData instance was created by
create_edata(),no other changes except for calls to
apply_parameters()were made,and the PEtab problem was not modified since the creation of this
ExperimentManagerinstance.
- Parameters:
edata (
amici.amici.ExpData) – TheExpDatainstance to be updated. In case of errors, the state of edata is undefined.problem_parameters (
dict[str,float]) – Problem parameters to be applied.
- Return type:
- create_edata(experiment, problem_parameters=None)[source]
Create an ExpData object for a single experiment.
Sets timepoints, measurements, initial conditions, … based on the given experiment and the nominal parameters of the PEtab problem.
- Parameters:
- Return type:
- Returns:
The created ExpData object for the given experiment.
- class amici.petab.petab_importer.PetabImporter(petab_problem, *, compile_=None, validate=True, module_name=None, outdir=None, jax=False, output_parameter_defaults=None, verbose=20, non_estimated_parameters_as_constants=True)[source]
Importer for PEtab2 problems.
This class is used to create an AMICI model from a PEtab problem.
The underlying SBML or PySB model will be modified to encode the experiments defined in the PEtab problem as events or initial conditions.
Be careful when using the imported model for anything other than the PEtab-encoded experiments.
All PEtab experiments will be encoded in the model, independent of whether they have measurements. This is to make it easier to simulate the respective experiments with the resulting AMICI model. This may make the resulting model more bloated. If this is not desired, the problem should be simplified before import.
- Parameters:
petab_problem (
petab.v2.core.Problem|petab.v1.problem.Problem) – The PEtab problem to import. The problem must not be changed after construction of the importer.
- __init__(petab_problem, *, compile_=None, validate=True, module_name=None, outdir=None, jax=False, output_parameter_defaults=None, verbose=20, non_estimated_parameters_as_constants=True)[source]
Create a new PetabImporter instance.
- Parameters:
petab_problem (
petab.v2.core.Problem|petab.v1.problem.Problem) – The PEtab problem to import.compile – Whether to compile the model extension after import.
validate (
bool) – Whether to validate the PEtab problem before import.module_name (
str) – The name of model module to generate.outdir (
str|pathlib._local.Path) – The output directory where the model files are written to.jax (
bool) – Whether to generate a JAX model instead of a SUNDIALS model. Currently, onlyFalseis supported.output_parameter_defaults (
dict[str,float] |None) – Optional default parameter values for output parameters introduced in the PEtab observables table, in particular for placeholder parameters. A dictionary mapping parameter IDs to default values.verbose (
int|bool) – The verbosity level. IfTrue, set tologging.INFO. IfFalse, set tologging.WARNING. Otherwise, use the given logging level.non_estimated_parameters_as_constants (
bool) – Whether parameters marked as non-estimated in PEtab should be considered constant in AMICI. Setting this toTruewill reduce model size and simulation times. If sensitivities with respect to those parameters are required, this should be set toFalse.
- create_simulator(force_import=False)[source]
Create a PEtab simulator for the imported model.
- Parameters:
force_import (
bool) – Whether to force re-import even if the model module already exists.- Return type:
- Returns:
The created PEtab simulator.
- import_module(force_import=False)[source]
Import the generated model module.
- Parameters:
force_import (
bool) – Whether to force re-import even if the model module already exists.- Return type:
- Returns:
The imported model module.
- property outdir: Path
The output directory where the model files are written to.
- class amici.petab.petab_importer.PetabSimulator(em, solver=None, num_threads=1)[source]
Simulator for PEtab2 problems.
This class is used to simulate all experiments of a given PEtab problem using a given AMICI model and solver, and to aggregate the results.
- __init__(em, solver=None, num_threads=1)[source]
Initialize the simulator.
- Parameters:
em (
amici.petab.petab_importer.ExperimentManager) – TheExperimentManagerto generate theamici.ExpDataobjects.solver (
amici.amici.Solver|None) – The AMICI solver to use for the simulations. If not provided, a new solver with default settings will be used.num_threads (
int) – The number of threads to use for parallel simulation of experiments. Only relevant if multiple experiments are present in the PEtab problem, and if AMICI was compiled with OpenMP support.
- property exp_man: ExperimentManager
The ExperimentManager used by this simulator.
- simulate(problem_parameters=None)[source]
Simulate all experiments of the given PEtab problem.
- Return type:
- Returns:
Dictionary of
the summed cost function value (
LLH),list of
amici.amici.ReturnData(RDATAS) for each experiment,list of
amici.amici.ExpData(EDATAS) for each experiment
Note that the returned
amici.amici.ExpDatainstances may be changed by subsequent calls to this function. Create a copy if needed.
- amici.petab.petab_importer.flatten_timepoint_specific_output_overrides(petab_problem)[source]
Flatten timepoint-specific output parameter overrides.
If the PEtab problem definition has timepoint-specific observableParameters or noiseParameters for the same observable, replace those by replicating the respective observable.
This is a helper function for some tools which may not support such timepoint-specific mappings. The observable table and measurement table are modified in place.
- Parameters:
petab_problem (
petab.v2.core.Problem) – PEtab problem to work on. Modified in place.- Return type:
- amici.petab.petab_importer.has_timepoint_specific_overrides(petab_problem, ignore_scalar_numeric_noise_parameters=False, ignore_scalar_numeric_observable_parameters=False)[source]
Check if the measurements have timepoint-specific observable or noise parameter overrides.
- Parameters:
petab_problem (
petab.v2.core.Problem) – PEtab problem to check.ignore_scalar_numeric_noise_parameters (
bool) – ignore scalar numeric assignments to noiseParameter placeholdersignore_scalar_numeric_observable_parameters (
bool) – ignore scalar numeric assignments to observableParameter placeholders
- Return type:
- Returns:
True if the problem has timepoint-specific overrides, False otherwise.
- amici.petab.petab_importer.rdatas_to_measurement_df(rdatas, model, petab_problem)[source]
Create a measurement dataframe in the PEtab format from the passed
rdatasand own information.- Parameters:
rdatas (
collections.abc.Sequence[amici.amici.ReturnData]) – A sequence ofamici.ReturnData.model (
amici.amici.Model|amici.amici.ModelPtr) – AMICI model used to generaterdatas.petab_problem (
petab.v2.core.Problem) – The PEtab problem used to generaterdatas.
- Return type:
- Returns:
A dataframe built from simulation results in rdatas in the format of the PEtab measurement table.
- amici.petab.petab_importer.rdatas_to_simulation_df(rdatas, model, petab_problem)[source]
Create a simulation dataframe in the PEtab format from the passed
rdatasand own information.- Parameters:
rdatas (
collections.abc.Sequence[amici.amici.ReturnData]) – A sequence ofamici.ReturnData.model (
amici.amici.Model|amici.amici.ModelPtr) – AMICI model used to generaterdatas.petab_problem (
petab.v2.core.Problem) – The PEtab problem used to generaterdatas.
- Return type:
- Returns:
A dataframe built from simulation results in rdatas in the format of the PEtab simulation table.
- amici.petab.petab_importer.unflatten_simulation_df(simulation_df, petab_problem)[source]
Unflatten simulations from a flattened PEtab problem.
A flattened PEtab problem is the output of applying
flatten_timepoint_specific_output_overrides()to a PEtab problem.- Parameters:
simulation_df (
pandas.core.frame.DataFrame) – The simulation dataframe. A dataframe in the same format as a PEtab measurements table, but with themeasurementcolumn switched with asimulationcolumn.petab_problem (
petab.v2.core.Problem) – The unflattened PEtab problem.
- Return type:
- Returns:
The simulation dataframe for the unflattened PEtab problem.