pypesto.objective.roadrunner

RoadRunner objective

class pypesto.objective.roadrunner.ExpData[source]

Bases: object

Class for managing experimental data for a single condition.

__init__(condition_id, measurements, observable_ids, noise_distributions, noise_formulae)[source]

Initialize the ExpData object.

Parameters:
  • condition_id (str) – Identifier of the condition.

  • measurements (ndarray) – Numpy Array containing the measurement data. It is a 2D array of dimension (n_timepoints, n_observables + 1). The first column is the timepoints, the remaining columns are the observable values. Observables not measured at a given timepoint should be NaN.

  • timepoints – Timepoints of the measurement data.

  • observable_ids (Sequence[str]) – Observable ids of the measurement data. Order must match the columns of the measurements array (-time).

  • noise_distributions (ndarray) – Numpy Array describing noise distributions of the measurement data. Dimension: (n_timepoints, n_observables). Each entry is a string describing scale and type of noise distribution, the name is “scale_type”. E.g. “lin_normal”, “log_normal”, “log10_normal”.

  • noise_formulae (ndarray) – Numpy Array describing noise formulae of the measurement data. Dimension: (n_timepoints, n_observables). Each entry is a string describing the noise formula, either a parameter name or a constant.

static from_petab_problem(petab_problem)[source]

Create a list of ExpData object from a petab problem.

Parameters:

petab_problem (Problem) – PEtab problem.

Return type:

list[ExpData]

static from_petab_single_condition(condition_id, petab_problem)[source]

Create an ExpData object from a single condition of a petab problem.

Parameters:
  • condition_id (str) – Identifier of the condition.

  • petab_problem (Problem) – PEtab problem.

Return type:

ExpData

get_observable_ids()[source]

Get the observable ids of the measurement data.

Returns:

observable_ids – Observable ids of the measurement data.

sanity_check()[source]

Perform a sanity check of the data.

property timepoints

Timepoints of the measurement data.

class pypesto.objective.roadrunner.PetabImporterRR[source]

Bases: object

Importer for PEtab problems using RoadRunner.

Create a roadrunner.RoadRunner instance, a pypesto.objective.RoadRunnerObjective or a pypesto.problem.Problem from PEtab files. The actual form of the likelihood depends on the noise model specified in the provided PEtab problem. For more information, see the PEtab documentation.

__init__(petab_problem, validate_petab=True)[source]

Initialize importer.

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

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

create_edatas()[source]

Create a List of ExpData objects from the PEtab problem.

Return type:

list[ExpData]

create_objective(rr=None, edatas=None)[source]

Create a pypesto.objective.RoadRunnerObjective.

Parameters:
  • rr (RoadRunner | None) – RoadRunner instance.

  • edatas (ExpData | None) – ExpData object.

Return type:

RoadRunnerObjective

create_parameter_mapping()[source]

Create a parameter mapping from the PEtab problem.

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 instance.

create_startpoint_method(**kwargs)[source]

Create a startpoint method.

Parameters:

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

Return type:

StartpointMethod

fill_model()[source]

Fill the RoadRunner model inplace from the PEtab problem.

Parameters:

return_model – Flag indicating if the model should be returned.

static from_yaml(yaml_config)[source]

Simplified constructor using a petab yaml file.

Return type:

PetabImporterRR

Parameters:

yaml_config (Path | str) –

class pypesto.objective.roadrunner.RoadRunnerCalculator[source]

Bases: object

Class to handle RoadRunner simulation and obtain objective value.

__call__(x_dct, mode, roadrunner_instance, edatas, x_ids, parameter_mapping, petab_problem, solver_options)[source]

Perform the RoadRunner call and obtain objective function values.

Parameters:
Returns:

Tuple of objective function values.

fill_in_parameters(problem_parameters, roadrunner_instance=None, parameter_mapping=None, preeq=False, filling_mode=None)[source]

Fill in parameters into the roadrunner instance.

Parameters:
  • roadrunner_instance (Optional[RoadRunner]) – RoadRunner instance to fill in parameters

  • problem_parameters (dict) – Problem parameters as parameterId=>value dict. Only parameters included here will be set. Remaining parameters will be used as already set in amici_model and edata.

  • parameter_mapping (Optional[Tuple[Dict[str, Union[str, Number]], Dict[str, Union[str, Number]], Dict[str, str], Dict[str, str]]]) – Parameter mapping for current condition. Quadruple of dicts, where the first dict contains the parameter mapping for pre- equilibration, the second dict contains the parameter mapping for the simulation, the third and fourth dict contain the scaling factors for the pre-equilibration and simulation, respectively.

  • preeq (bool) – Whether to fill in parameters for pre-equilibration.

  • filling_mode (Optional[str]) – Which parameters to fill in. If None or “all”, all parameters are filled in. Other options are “only_parameters” and “only_species”.

Return type:

dict

Returns:

dict – Mapping of parameter IDs to values.

simulate_per_condition(x_dct, roadrunner_instance, edata, parameter_mapping_per_condition)[source]

Simulate the model for a single condition.

Parameters:
Return type:

tuple[ndarray, float]

Returns:

  • Tuple of simulation results in form of a numpy array and the

  • negative log-likelihood.

class pypesto.objective.roadrunner.RoadRunnerObjective[source]

Bases: ObjectiveBase

Objective function for RoadRunner models.

Currently does not support sensitivities.

__call__(x, sensi_orders=(0,), mode='mode_fun', return_dict=False, **kwargs)[source]

See ObjectiveBase documentation.

Return type:

Union[float, ndarray, dict]

Parameters:
__init__(rr, edatas, parameter_mapping, petab_problem, calculator=None, x_names=None, solver_options=None)[source]

Initialize the RoadRunner objective function.

Parameters:
  • rr (RoadRunner) – RoadRunner instance for simulation.

  • edatas (Union[Sequence[ExpData], ExpData]) – The experimental data. If a list is passed, its entries correspond to multiple experimental conditions.

  • parameter_mapping (list[Tuple[Dict[str, Union[str, Number]], Dict[str, Union[str, Number]], Dict[str, str], Dict[str, str]]]) – Mapping of optimization parameters to model parameters. Format as created by petab.get_optimization_to_simulation_parameter_mapping. The default is just to assume that optimization and simulation parameters coincide.

  • petab_problem (Problem) – The corresponding PEtab problem. Needed to calculate NLLH. Might be removed later.

  • calculator (Optional[RoadRunnerCalculator]) – The calculator to use. If None, a new instance is created.

  • x_names (Optional[Sequence[str]]) – Names of optimization parameters.

  • solver_options (SolverOptions | None) –

call_unprocessed(x, sensi_orders, mode, edatas=None, parameter_mapping=None)[source]

Call objective function without pre- or post-processing and formatting.

Return type:

dict

Returns:

result – A dict containing the results.

Parameters:
check_mode(mode)[source]

See ObjectiveBase documentation.

Return type:

bool

Parameters:

mode (Literal['mode_fun', 'mode_res']) –

check_sensi_orders(sensi_orders, mode)[source]

See ObjectiveBase documentation.

Return type:

bool

Parameters:
  • sensi_orders (tuple[int, ...]) –

  • mode (Literal['mode_fun', 'mode_res']) –

get_config()[source]

Return basic information of the objective configuration.

Return type:

dict

class pypesto.objective.roadrunner.SolverOptions[source]

Bases: dict

Class for managing solver options of roadrunner.

__init__(integrator=None, relative_tolerance=None, absolute_tolerance=None, maximum_num_steps=None, **kwargs)[source]

Initialize the SolverOptions object. Can be used as a dictionary.

Parameters:
  • integrator (str | None) – Integrator to use.

  • relative_tolerance (float | None) – Relative tolerance of the integrator.

  • absolute_tolerance (float | None) – Absolute tolerance of the integrator.

  • maximum_num_steps (int | None) – Maximum number of steps to take.

  • kwargs – Additional solver options.

apply_to_roadrunner(roadrunner_instance)[source]

Apply the solver options to a roadrunner object inplace.

Parameters:

roadrunner_instance (RoadRunner) – Roadrunner object to apply the solver options to.

pypesto.objective.roadrunner.simulation_to_measurement_df(simulations, measurement_df)[source]

Convert simulation results to a measurement DataFrame.

Parameters:
  • simulations (dict) – Dictionary containing the simulation results of a roadrunner simulator. The keys are the condition ids and the values are the simulation results.

  • measurement_df (DataFrame) – DataFrame containing the measurement data of the PEtab problem.

Return type:

DataFrame