amici.sim.sundials.petab.v1
Functions
|
Simulate PEtab model. |
|
Create a PEtab simulation dataframe from |
|
Create a measurement dataframe in the PEtab format from the passed |
|
Create list of |
|
Create list of |
|
Fill fixed and dynamic parameters into the edatas (in-place). |
Classes
|
Manage experimental conditions based on a PEtab problem definition. |
|
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
ExpDataobjects 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=Truewas 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=Truewas 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.
- 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:
- 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) – IfTrue, the working directory is removed regardless of whether it is a temporary directory.**kwargs – Additional keyword arguments are passed to
shutil.rmtree().
- Return type:
- 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 namedpetab.C.MEASUREMENT(True) orpetab.C.SIMULATION(False).**kwargs – Additional keyword arguments are passed to
petab.simulate.Simulator.simulate_without_noise().
- Return type:
- 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:
- amici.sim.sundials.petab.v1.create_edatas(amici_model, petab_problem, simulation_conditions=None)[source]
Create list of
ExpDataobjects for PEtab problem.- Parameters:
amici_model (
amici._installation.amici.Model|amici._installation.amici.ModelPtr) – AMICI model.petab_problem (
petab.v1.problem.Problem) – Underlying PEtab problem.simulation_conditions (
pandas.DataFrame|dict) – Result ofpetab.get_simulation_conditions(). Can be provided to save time if this has be obtained before.
- Return type:
- Returns:
List with one
ExpDataper simulation condition, with filled in timepoints and data, but without parameter values (seecreate_parameterized_edatas()orfill_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
ExpDataobjects with parameters filled in.- Parameters:
amici_model (
amici._installation.amici.Model|amici._installation.amici.ModelPtr) – AMICI Model assumed to be compatible withpetab_problem.petab_problem (
petab.v1.problem.Problem) – PEtab problem to work on.problem_parameters (
dict[str,numbers.Number]) – Run simulation with these parameters. IfNone, PEtabnominalValueswill be used. To be provided as dict, mapping PEtab problem parameters to SBML IDs.scaled_parameters (
bool) – IfTrue,problem_parametersare assumed to be on the scale provided in the PEtab parameter table and will be unscaled. IfFalse, they are assumed to be in linear scale.parameter_mapping (
amici.sim._parameter_mapping.ParameterMapping) – Optional precomputed PEtab parameter mapping for efficiency, as generated byamici.sim.sundials.petab.v1.create_parameter_mapping().simulation_conditions (
pandas.DataFrame|dict) – Result ofpetab.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:
- Returns:
List with one
ExpDataper 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 datasExpDatawith 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:
- 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
rdatasand own information.- Parameters:
rdatas (
collections.abc.Sequence[amici._installation.amici.ReturnData]) – A sequence of rdatas with the ordering ofpetab.v1.get_simulation_conditions().model (
amici._installation.amici.Model|amici._installation.amici.ModelPtr) – AMICI model used to generaterdatas.measurement_df (
pandas.DataFrame) – PEtab measurement table used to generaterdatas.
- Return type:
- 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
ReturnDatas.See
rdatas_to_measurement_df()for details, only that model outputs will appear in columnsimulationinstead ofmeasurement.- Return type:
- 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 withpetab_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. IfNone, PEtabnominalValueswill be used. To be provided as dict, mapping PEtab problem parameters to SBML IDs.simulation_conditions (
pandas.DataFrame|dict) – Result ofpetab.v1.get_simulation_conditions(). Can be provided to save time if this has be obtained before. Not required ifedatasandparameter_mappingare 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 bycreate_parameter_mapping()withscaled_parameters=True.scaled_parameters (
bool|None) – IfTrue,problem_parametersare assumed to be on the scale provided in the PEtab parameter table and will be unscaled. IfFalse, 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.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:
- 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().