PEtab

pyPESTO support for the PEtab data format.

class pypesto.petab.PetabImporter(petab_problem: petab.Problem, output_folder: str = None, model_name: str = None, validate_petab: bool = True)[source]

Bases: pypesto.objective.amici.AmiciObjectBuilder

MODEL_BASE_DIR = 'amici_models'
__init__(petab_problem: petab.Problem, output_folder: str = None, model_name: str = None, validate_petab: bool = True)[source]
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.

check_gradients(*args, rtol: float = 0.01, atol: float = 0.001, mode: Literal = 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

Indicates whether gradients match (True) FDs or not (False)

Return type

bool

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: amici.Model = None, simulation_conditions=None)List[amici.ExpData][source]

Create list of amici.ExpData objects.

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

Import amici model. If necessary or force_compile is True, compile first.

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: amici.Model = None, solver: amici.Solver = None, edatas: Sequence[amici.ExpData] = None, force_compile: bool = False, **kwargs)pypesto.objective.amici.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.

Returns

A pypesto.AmiciObjective for the model and the data.

Return type

objective

create_predictor(objective: Optional[pypesto.objective.amici.AmiciObjective] = None, amici_output_fields: Optional[Sequence[str]] = None, post_processor: Optional[Callable] = None, post_processor_sensi: Optional[Callable] = None, post_processor_time: Optional[Callable] = None, max_chunk_size: Optional[int] = None, output_ids: Optional[Sequence[str]] = None, condition_ids: Optional[Sequence[str]] = None)pypesto.predict.amici_predictor.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()pypesto.objective.priors.NegLogParameterPriors[source]

Creates a prior from the parameter table. Returns None, if no priors are defined.

create_problem(objective: Optional[pypesto.objective.amici.AmiciObjective] = None, x_guesses: Optional[Iterable[float]] = None, **kwargs)pypesto.problem.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.

  • **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: amici.Model = None)amici.Solver[source]

Return model solver.

create_startpoint_method()[source]

Creates a startpoint method, if the PEtab problem specifies an initializationPrior. Returns None, if no initializationPrior is specified.

static from_yaml(yaml_config: Union[dict, str], output_folder: Optional[str] = None, model_name: Optional[str] = None)pypesto.petab.importer.PetabImporter[source]

Simplified constructor using a petab yaml file.

prediction_to_petab_measurement_df(prediction: pypesto.predict.result.PredictionResult, predictor: Optional[pypesto.predict.amici_predictor.AmiciPredictor] = None)pandas.core.frame.DataFrame[source]

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: pypesto.predict.result.PredictionResult, predictor: Optional[pypesto.predict.amici_predictor.AmiciPredictor] = None)pandas.core.frame.DataFrame[source]

Same as 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[amici.ReturnData], model: amici.Model = None)pandas.core.frame.DataFrame[source]

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

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[amici.ReturnData], model: amici.Model = None)pandas.core.frame.DataFrame[source]

Same as rdatas_to_measurement_df, execpt a petab simulation dataframe is created, i.e. the measurement column label is adjusted.

class pypesto.petab.PetabImporterPysb(petab_problem: amici.petab_import_pysb.PysbPetabProblem, output_folder: str = None)[source]

Bases: pypesto.petab.importer.PetabImporter

Import for experimental PySB-based PEtab problems

__init__(petab_problem: amici.petab_import_pysb.PysbPetabProblem, output_folder: str = None)[source]
petab_problem:

Managing access to the model and data.

output_folder:

Folder to contain the amici model.

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