amici.sim.sundials.petab.v1

Functions

simulate_petab(petab_problem, *, amici_model)

Simulate PEtab model.

rdatas_to_simulation_df(rdatas, model, ...)

Create a PEtab simulation dataframe from ReturnData s.

rdatas_to_measurement_df(rdatas, model, ...)

Create a measurement dataframe in the PEtab format from the passed rdatas and own information.

create_edatas(amici_model, petab_problem[, ...])

Create list of ExpData objects for PEtab problem.

create_parameterized_edatas(amici_model, ...)

Create list of ExpData objects with parameters filled in.

fill_in_parameters(edatas, ...[, warn_unused])

Fill fixed and dynamic parameters into the edatas (in-place).

Classes

PetabProblem(petab_problem[, amici_model, ...])

Manage experimental conditions based on a PEtab problem definition.

PetabSimulator(*args[, amici_model])

Implementation of the PEtab Simulator class that uses AMICI.

class amici.sim.sundials.petab.v1.PetabProblem(petab_problem, amici_model=None, problem_parameters=None, scaled_parameters=False, simulation_conditions=None, store_edatas=True)[source]

Manage experimental conditions based on a PEtab problem definition.

Create ExpData objects from a PEtab problem definition, and handle parameter scales and parameter mapping.

Parameters:
  • petab_problem – PEtab problem definition.

  • amici_model – AMICI model

  • problem_parameters – Problem parameters to use for simulation (default: PEtab nominal values and model values).

  • scaled_parameters – Whether the provided parameters are on PEtab parameterScale or not.

  • simulation_conditions – Simulation conditions to use for simulation. It can be used to subset the conditions in the PEtab problem. All subsequent operations will only be performed on that subset. By default, all conditions are used.

  • store_edatas – Whether to create and store all ExpData objects for all conditions upfront. If set to False, ExpData objects will be created and disposed of on the fly during simulation. The latter saves memory if the given PEtab problem comprises many simulation conditions.

__init__(petab_problem, amici_model=None, problem_parameters=None, scaled_parameters=False, simulation_conditions=None, store_edatas=True)[source]
get_edata(condition_id, preequilibration_condition_id=None)[source]

Get ExpData object for a given condition.

NOTE: If store_edatas=True was passed to the constructor and the returned object is modified, the changes will be reflected in the internal ExpData objects. Also, if parameter values of PetabProblem are changed, all ExpData objects will be updated. Create a deep copy if you want to avoid this.

Parameters:
  • condition_id – PEtab condition ID

  • preequilibration_condition_id – PEtab preequilibration condition ID

Returns:

ExpData object

get_edatas()[source]

Get all ExpData objects.

NOTE: If store_edatas=True was passed to the constructor and the returned objects are modified, the changes will be reflected in the internal ExpData objects. Also, if parameter values of PetabProblem are changed, all ExpData objects will be updated. Create a deep copy if you want to avoid this.

Returns:

List of ExpData objects

property model: amici.Model

AMICI model.

set_parameters(problem_parameters, scaled_parameters=False)[source]

Set problem parameters.

Parameters:
  • problem_parameters (dict[str, float]) – Problem parameters to use for simulation. This may be a subset of all parameters.

  • scaled_parameters (bool) – Whether the provided parameters are on PEtab parameterScale or not.

class amici.sim.sundials.petab.v1.PetabSimulator(*args, amici_model=None, **kwargs)[source]

Implementation of the PEtab Simulator class that uses AMICI.

__init__(*args, amici_model=None, **kwargs)[source]

Initialize the simulator.

Initialize the simulator with sufficient information to perform a simulation. If no working directory is specified, a temporary one is created.

Parameters:
  • petab_problem – A PEtab problem.

  • working_dir – All simulator-specific output files will be saved here. This directory and its contents may be modified and deleted, and should be considered ephemeral.

add_noise(simulation_df, noise_scaling_factor=1, **kwargs)

Add noise to simulated data.

Parameters:
  • simulation_df (pandas.DataFrame) – A PEtab measurements table that contains simulated data.

  • noise_scaling_factor (float) – A multiplier of the scale of the noise distribution.

  • **kwargs – Additional keyword arguments are passed to sample_noise().

Return type:

pandas.DataFrame

Returns:

Simulated data with noise, as a PEtab measurements table.

remove_working_dir(force=False, **kwargs)

Remove the simulator working directory, and all files within.

See the petab.simulate.Simulator.__init__() method arguments.

Parameters:
  • force (bool) – If True, the working directory is removed regardless of whether it is a temporary directory.

  • **kwargs – Additional keyword arguments are passed to shutil.rmtree().

Return type:

None

simulate(noise=False, noise_scaling_factor=1, as_measurement=False, **kwargs)

Simulate a PEtab problem, optionally with noise.

Parameters:
  • noise (bool) – If True, noise is added to simulated data.

  • noise_scaling_factor (float) – A multiplier of the scale of the noise distribution.

  • as_measurement (bool) – Whether the data column is named petab.C.MEASUREMENT (True) or petab.C.SIMULATION (False).

  • **kwargs – Additional keyword arguments are passed to petab.simulate.Simulator.simulate_without_noise().

Return type:

pandas.DataFrame

Returns:

Simulated data, as a PEtab measurements table.

simulate_without_noise(**kwargs)[source]

See petab.simulate.Simulator.simulate() docstring.

Additional keyword arguments can be supplied to specify arguments for the AMICI PEtab import, simulate, and export methods. See the docstrings for the respective methods for argument options: - import_petab_problem(), and - simulate_petab().

Note that some arguments are expected to have already been specified in the Simulator constructor (including the PEtab problem).

Return type:

pandas.DataFrame

amici.sim.sundials.petab.v1.create_edatas(amici_model, petab_problem, simulation_conditions=None)[source]

Create list of ExpData objects for PEtab problem.

Parameters:
Return type:

list[amici._installation.amici.ExpData]

Returns:

List with one ExpData per simulation condition, with filled in timepoints and data, but without parameter values (see create_parameterized_edatas() or fill_in_parameters() for that).

amici.sim.sundials.petab.v1.create_parameterized_edatas(amici_model, petab_problem, problem_parameters, scaled_parameters=False, parameter_mapping=None, simulation_conditions=None, warn_unused=True)[source]

Create list of ExpData objects with parameters filled in.

Parameters:
  • amici_model (amici._installation.amici.Model | amici._installation.amici.ModelPtr) – AMICI Model assumed to be compatible with petab_problem.

  • petab_problem (petab.v1.problem.Problem) – PEtab problem to work on.

  • problem_parameters (dict[str, numbers.Number]) – Run simulation with these parameters. If None, PEtab nominalValues will be used. To be provided as dict, mapping PEtab problem parameters to SBML IDs.

  • scaled_parameters (bool) – If True, problem_parameters are assumed to be on the scale provided in the PEtab parameter table and will be unscaled. If False, they are assumed to be in linear scale.

  • parameter_mapping (amici.sim._parameter_mapping.ParameterMapping) – Optional precomputed PEtab parameter mapping for efficiency, as generated by amici.sim.sundials.petab.v1.create_parameter_mapping().

  • simulation_conditions (pandas.DataFrame | dict) – Result of petab.v1.get_simulation_conditions(). Can be provided to save time if this has been obtained before.

  • warn_unused (bool) – Whether a warning should be emitted if not all problem parameters were used. I.e., if there are parameters in problem_parameters that are not in parameter_mapping or in the generated parameter mapping.

Return type:

list[amici._installation.amici.ExpData]

Returns:

List with one ExpData per simulation condition, with filled in timepoints, data and parameters.

amici.sim.sundials.petab.v1.fill_in_parameters(edatas, problem_parameters, scaled_parameters, parameter_mapping, amici_model, warn_unused=True)[source]

Fill fixed and dynamic parameters into the edatas (in-place).

Parameters:
  • edatas (list[amici._installation.amici.ExpData]) – List of experimental datas ExpData with everything except parameters filled.

  • problem_parameters (dict[str, numbers.Number]) – Problem parameters as parameterId=>value dict. Only parameters included here will be set. Remaining parameters will be used as currently set in amici_model.

  • scaled_parameters (bool) – If True, problem_parameters are assumed to be on the scale provided in the parameter mapping. If False, they are assumed to be in linear scale.

  • parameter_mapping (amici.sim._parameter_mapping.ParameterMapping) – Parameter mapping for all conditions.

  • amici_model (amici._installation.amici.Model | amici._installation.amici.ModelPtr) – AMICI model.

  • warn_unused (bool) – Whether a warning should be emitted if not all problem parameters were used. I.e., if there are parameters in problem_parameters that are not in parameter_mapping.

Return type:

None

amici.sim.sundials.petab.v1.rdatas_to_measurement_df(rdatas, model, measurement_df)[source]

Create a measurement dataframe in the PEtab format from the passed rdatas and own information.

Parameters:
Return type:

pandas.DataFrame

Returns:

A dataframe built from the rdatas in the format of measurement_df.

amici.sim.sundials.petab.v1.rdatas_to_simulation_df(rdatas, model, measurement_df)[source]

Create a PEtab simulation dataframe from ReturnData s.

See rdatas_to_measurement_df() for details, only that model outputs will appear in column simulation instead of measurement.

Return type:

pandas.DataFrame

amici.sim.sundials.petab.v1.simulate_petab(petab_problem, *, amici_model, solver=None, problem_parameters=None, simulation_conditions=None, edatas=None, parameter_mapping=None, scaled_parameters=False, log_level=30, num_threads=1, failfast=True, scaled_gradients=False)[source]

Simulate PEtab model.

Note

Regardless of scaled_parameters, unscaled sensitivities are returned, unless scaled_gradients=True.

Parameters:
  • petab_problem (petab.v1.problem.Problem) – PEtab problem to work on.

  • amici_model (amici._installation.amici.Model | amici._installation.amici.ModelPtr) – AMICI Model assumed to be compatible with petab_problem.

  • solver (amici._installation.amici.Solver | None) – An AMICI solver. Will use default options if None.

  • problem_parameters (dict[str, float] | None) – Run simulation with these parameters. If None, PEtab nominalValues will be used. To be provided as dict, mapping PEtab problem parameters to SBML IDs.

  • simulation_conditions (pandas.DataFrame | dict) – Result of petab.v1.get_simulation_conditions(). Can be provided to save time if this has be obtained before. Not required if edatas and parameter_mapping are provided.

  • edatas (list[typing.Union[amici._installation.amici.ExpData, amici._installation.amici.ExpDataPtr]]) – Experimental data. Parameters are inserted in-place for simulation.

  • parameter_mapping (amici.sim._parameter_mapping.ParameterMapping) – Optional precomputed PEtab parameter mapping for efficiency, as generated by create_parameter_mapping() with scaled_parameters=True.

  • scaled_parameters (bool | None) – If True, problem_parameters are assumed to be on the scale provided in the PEtab parameter table and will be unscaled. If False, they are assumed to be in linear scale. If parameter_mapping is provided, this must match the value of scaled_parameters used to generate the mapping.

  • log_level (int) – Log level, see logging module.

  • num_threads (int) – Number of threads to use for simulating multiple conditions (only used if compiled with OpenMP).

  • failfast (bool) – Returns as soon as an integration failure is encountered, skipping any remaining simulations.

  • scaled_gradients (bool) – Whether to compute gradients on parameter scale (True) or not (False).

Return type:

dict[str, typing.Any]

Returns:

Dictionary of

  • cost function value (LLH),

  • list of ReturnData (RDATAS),

  • list of ExpData (EDATAS),

corresponding to the different simulation conditions. For ordering of simulation conditions, see petab.v1.Problem.get_simulation_conditions_from_measurement_df().