pypesto.petab

PEtab

pyPESTO support for the PEtab data format.

class pypesto.petab.PetabImporter[source]

Bases: AmiciObjectBuilder

Importer for PEtab files.

Create an amici.amici.Model, an pypesto.objective.AmiciObjective or a pypesto.problem.Problem from PEtab files. The created objective function is a negative log-likelihood function and can thus be negative. The actual form of the likelihood depends on the noise model specified in the provided PEtab problem. For more information, see the PEtab documentation.

MODEL_BASE_DIR = 'amici_models/0.23.1'
__init__(petab_problem, output_folder=None, model_name=None, validate_petab=True, validate_petab_hierarchical=True, hierarchical=False, inner_options=None)[source]

Initialize importer.

Parameters:
  • petab_problem (Problem) – Managing access to the model and data.

  • output_folder (str) – Folder to contain the amici model. Defaults to ‘./amici_models/{model_name}’.

  • model_name (str) – Name of the model, which will in particular be the name of the compiled model python module.

  • validate_petab (bool) – Flag indicating if the PEtab problem shall be validated.

  • validate_petab_hierarchical (bool) – Flag indicating if the PEtab problem shall be validated in terms of pyPESTO’s hierarchical optimization implementation.

  • hierarchical (bool) – Whether to use hierarchical optimization or not, in case the underlying PEtab problem has parameters marked for hierarchical optimization (non-empty parameterType column in the PEtab parameter table). Required for ordinal, censored and semiquantitative data.

  • inner_options (dict) – Options for the inner problems and solvers. If not provided, default options will be used.

check_gradients(*args, rtol=0.01, atol=0.001, mode=None, multi_eps=None, **kwargs)[source]

Check if gradients match finite differences (FDs).

Parameters:
  • rtol (relative error tolerance) –

  • atol (absolute error tolerance) –

  • mode (function values or residuals) –

  • objAbsoluteTolerance (absolute tolerance in sensitivity calculation) –

  • objRelativeTolerance (relative tolerance in sensitivity calculation) –

  • multi_eps (multiple test step width for FDs) –

Return type:

bool

Returns:

match (Whether gradients match FDs (True) or not (False))

compile_model(**kwargs)[source]

Compile the model.

If the output folder exists already, it is first deleted.

Parameters:

kwargs – Extra arguments passed to amici.sbml_import.SbmlImporter.sbml2amici() or amici.pysb_import.pysb2amici().

create_edatas(model=None, simulation_conditions=None, verbose=True)[source]

Create list of amici.amici.ExpData objects.

Return type:

list[ExpData]

Parameters:
create_model(force_compile=False, verbose=True, **kwargs)[source]

Import amici model.

Parameters:
  • force_compile (bool) –

    If False, the model is compiled only if the output folder does not exist yet. If True, the output folder is deleted and the model (re-)compiled in either case.

    Warning

    If force_compile, then an existing folder of that name will be deleted.

  • verbose (bool) – Passed to AMICI’s model compilation. If True, the compilation progress is printed.

  • kwargs – Extra arguments passed to amici.SbmlImporter.sbml2amici

Return type:

Model

create_objective(model=None, solver=None, edatas=None, force_compile=False, verbose=True, **kwargs)[source]

Create a pypesto.objective.AmiciObjective.

Parameters:
  • model (Model) – The AMICI model.

  • solver (Solver) – The AMICI solver.

  • edatas (Sequence[ExpData]) – The experimental data in AMICI format.

  • force_compile (bool) – Whether to force-compile the model if not passed.

  • verbose (bool) – Passed to AMICI’s model compilation. If True, the compilation progress is printed.

  • **kwargs – Additional arguments passed on to the objective. In case of ordinal or semiquantitative measurements, inner_options can optionally be passed here. If none are given, inner_options given to the importer constructor (or inner defaults) will be chosen.

Return type:

AmiciObjective

Returns:

A pypesto.objective.AmiciObjective for the model and the data.

create_predictor(objective=None, amici_output_fields=None, post_processor=None, post_processor_sensi=None, post_processor_time=None, max_chunk_size=None, output_ids=None, condition_ids=None)[source]

Create a pypesto.predict.AmiciPredictor.

The AmiciPredictor facilitates generation of predictions from parameter vectors.

Parameters:
  • objective (AmiciObjective) – An objective object, which will be used to get model simulations

  • amici_output_fields (Sequence[str]) – keys that exist in the return data object from AMICI, which should be available for the post-processors

  • post_processor (Optional[Callable]) – A callable function which applies postprocessing to the simulation results. Default are the observables of the AMICI model. This method takes a list of ndarrays (as returned in the field [‘y’] of amici ReturnData objects) as input.

  • post_processor_sensi (Optional[Callable]) – A callable function which applies postprocessing to the sensitivities of the simulation results. Default are the observable sensitivities of the AMICI model. This method takes two lists of ndarrays (as returned in the fields [‘y’] and [‘sy’] of amici ReturnData objects) as input.

  • post_processor_time (Optional[Callable]) – A callable function which applies postprocessing to the timepoints of the simulations. Default are the timepoints of the amici model. This method takes a list of ndarrays (as returned in the field [‘t’] of amici ReturnData objects) as input.

  • max_chunk_size (int | None) – In some cases, we don’t want to compute all predictions at once when calling the prediction function, as this might not fit into the memory for large datasets and models. Here, the user can specify a maximum number of conditions, which should be simulated at a time. Default is 0 meaning that all conditions will be simulated. Other values are only applicable, if an output file is specified.

  • output_ids (Sequence[str]) – IDs of outputs, if post-processing is used

  • condition_ids (Sequence[str]) – IDs of conditions, if post-processing is used

Return type:

AmiciPredictor

Returns:

create_prior()[source]

Create a prior from the parameter table.

Returns None, if no priors are defined.

Return type:

NegLogParameterPriors | None

create_problem(objective=None, x_guesses=None, problem_kwargs=None, startpoint_kwargs=None, **kwargs)[source]

Create a pypesto.problem.Problem.

Parameters:
Return type:

Problem

Returns:

A pypesto.problem.Problem for the objective.

create_solver(model=None, verbose=True)[source]

Return model solver.

Return type:

Solver

Parameters:
create_startpoint_method(**kwargs)[source]

Create a startpoint method.

Parameters:

**kwargs – Additional keyword arguments passed on to pypesto.startpoint.FunctionStartpoints.__init__().

Return type:

StartpointMethod

static from_yaml(yaml_config, output_folder=None, model_name=None)[source]

Simplified constructor using a petab yaml file.

Return type:

PetabImporter

Parameters:
  • yaml_config (dict | str) –

  • output_folder (str) –

  • model_name (str) –

prediction_to_petab_measurement_df(prediction, predictor=None)[source]

Cast prediction into a dataframe.

If a PEtab problem is simulated without post-processing, then the result can be cast into a PEtab measurement or simulation dataframe

Parameters:
Return type:

DataFrame

Returns:

  • A dataframe built from the rdatas in the format as in

  • self.petab_problem.measurement_df.

prediction_to_petab_simulation_df(prediction, predictor=None)[source]

See prediction_to_petab_measurement_df().

Except a PEtab simulation dataframe is created, i.e. the measurement column label is adjusted.

Return type:

DataFrame

Parameters:
rdatas_to_measurement_df(rdatas, model=None, verbose=True)[source]

Create a measurement dataframe in the petab format.

Parameters:
  • rdatas (Sequence[ReturnData]) – A list of rdatas as produced by pypesto.AmiciObjective.__call__(x, return_dict=True)['rdatas'].

  • model (Model) – The amici model.

  • verbose (bool) – Passed to AMICI’s model compilation. If True, the compilation progress is printed.

Return type:

DataFrame

Returns:

  • A dataframe built from the rdatas in the format as in

  • self.petab_problem.measurement_df.

rdatas_to_simulation_df(rdatas, model=None)[source]

See rdatas_to_measurement_df().

Except a petab simulation dataframe is created, i.e. the measurement column label is adjusted.

Return type:

DataFrame

Parameters:
validate_inner_options()[source]

Validate the inner options.