pypesto.petab

PEtab

pyPESTO support for the PEtab data format.

class pypesto.petab.PetabImporter(petab_problem: Problem, output_folder: str | None = None, model_name: str | None = None, validate_petab: bool = True, validate_petab_hierarchical: bool = True, hierarchical: bool = False, inner_options: Dict | None = None)[source]

Bases: AmiciObjectBuilder

Importer for Petab files.

Create an amici.Model, an objective.AmiciObjective or a pypesto.Problem from Petab files.

MODEL_BASE_DIR = 'amici_models'
__init__(petab_problem: Problem, output_folder: str | None = None, model_name: str | None = None, validate_petab: bool = True, validate_petab_hierarchical: bool = True, hierarchical: bool = False, inner_options: Dict | None = None)[source]

Initialize importer.

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

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

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

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

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

  • hierarchical – 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 nonlinear-monotone data.

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

check_gradients(*args, rtol: float = 0.01, atol: float = 0.001, mode: str | List[str] | None = None, multi_eps=None, **kwargs) bool[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) –

Returns:

match

Return type:

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.SbmlImporter.sbml2amici.) –

create_edatas(model: Model | None = None, simulation_conditions=None) List[ExpData][source]

Create list of amici.ExpData objects.

create_model(force_compile: bool = False, **kwargs) Model[source]

Import amici model.

Parameters:
  • force_compile

    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.

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

create_objective(model: Model | None = None, solver: Solver | None = None, edatas: Sequence[ExpData] | None = None, force_compile: bool = False, **kwargs) AmiciObjective[source]

Create a pypesto.AmiciObjective.

Parameters:
  • model – The AMICI model.

  • solver – The AMICI solver.

  • edatas – The experimental data in AMICI format.

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

  • **kwargs – Additional arguments passed on to the objective. In case of ordinal or nonlinear-monotone 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.

Returns:

A pypesto.AmiciObjective for the model and the data.

Return type:

objective

create_predictor(objective: AmiciObjective | None = None, amici_output_fields: Sequence[str] | None = None, post_processor: Callable | None = None, post_processor_sensi: Callable | None = None, post_processor_time: Callable | None = None, max_chunk_size: int | None = None, output_ids: Sequence[str] | None = None, condition_ids: Sequence[str] | None = None) AmiciPredictor[source]

Create a pypesto.predict.AmiciPredictor.

The AmiciPredictor facilitates generation of predictions from parameter vectors.

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

  • amici_output_fields – keys that exist in the return data object from AMICI, which should be available for the post-processors

  • post_processor – 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 – 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 – 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 – 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 – IDs of outputs, if post-processing is used

  • condition_ids – IDs of conditions, if post-processing is used

Returns:

A pypesto.predict.AmiciPredictor for the model, using the outputs of the AMICI model and the timepoints from the PEtab data

Return type:

predictor

create_prior() NegLogParameterPriors | None[source]

Create a prior from the parameter table.

Returns None, if no priors are defined.

create_problem(objective: AmiciObjective | None = None, x_guesses: Iterable[float] | None = None, problem_kwargs: Dict[str, Any] | None = None, **kwargs) Problem[source]

Create a pypesto.Problem.

Parameters:
  • objective – Objective as created by create_objective.

  • x_guesses – Guesses for the parameter values, shape (g, dim), where g denotes the number of guesses. These are used as start points in the optimization.

  • problem_kwargs – Passed to the pypesto.Problem constructor.

  • **kwargs – Additional key word arguments passed on to the objective, if not provided.

Returns:

A pypesto.Problem for the objective.

Return type:

problem

create_solver(model: Model | None = None) Solver[source]

Return model solver.

create_startpoint_method(**kwargs) StartpointMethod[source]

Create a startpoint method.

Parameters:

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

static from_yaml(yaml_config: dict | str, output_folder: str | None = None, model_name: str | None = None) PetabImporter[source]

Simplified constructor using a petab yaml file.

prediction_to_petab_measurement_df(prediction: PredictionResult, predictor: AmiciPredictor | None = None) DataFrame[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:
  • prediction – A prediction result as produced by an AmiciPredictor

  • predictor – The AmiciPredictor function

Returns:

A dataframe built from the rdatas in the format as in self.petab_problem.measurement_df.

Return type:

measurement_df

prediction_to_petab_simulation_df(prediction: PredictionResult, predictor: AmiciPredictor | None = None) DataFrame[source]

See prediction_to_petab_measurement_df.

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

rdatas_to_measurement_df(rdatas: Sequence[ReturnData], model: Model | None = None) DataFrame[source]

Create a measurement dataframe in the petab format.

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

  • model – The amici model.

Returns:

A dataframe built from the rdatas in the format as in self.petab_problem.measurement_df.

Return type:

measurement_df

rdatas_to_simulation_df(rdatas: Sequence[ReturnData], model: Model | None = None) DataFrame[source]

See rdatas_to_measurement_df.

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

validate_inner_options()[source]

Validate the inner options.

class pypesto.petab.PetabImporterPysb(petab_problem: amici.petab_import_pysb.PysbPetabProblem, validate_petab: bool = False, **kwargs)[source]

Bases: PetabImporter

Import for experimental PySB-based PEtab problems.

__init__(petab_problem: amici.petab_import_pysb.PysbPetabProblem, validate_petab: bool = False, **kwargs)[source]

Initialize importer.

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

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

  • kwargs – Passed to PetabImporter.__init__.

compile_model(**kwargs)[source]

Compile the model.

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

Parameters:

kwargs (Extra arguments passed to amici.SbmlImporter.sbml2amici.) –