Result Storage

This notebook will show how to store pypesto result objects to be able to load them later on for visualization and further analysis. This includes sampling, profiling and optimization. Additionally, we will show how to use optimization history to look further into an optimization run and how to store the history.

After this notebook, you will…

  • know how to store and load optimization, profiling and sampling results

  • know how to store and load optimization history

  • know basic plotting functions for optimization history to inspect optimization convergence

[1]:
# install if not done yet
# %pip install pypesto --quiet

Imports

[2]:
import logging
import random
import tempfile

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from IPython.display import Markdown, display

import pypesto.optimize as optimize
import pypesto.petab
import pypesto.profile as profile
import pypesto.sample as sample
import pypesto.visualize as visualize

mpl.rcParams["figure.dpi"] = 100
mpl.rcParams["font.size"] = 18
# set a random seed to get reproducible results
random.seed(3142)

%matplotlib inline

0. Objective function and problem definition

We will use the Boehm model from the benchmark initiative in this notebook as an example. We load the model through PEtab, a data format for specifying parameter estimation problems in systems biology.

[3]:
%%capture
# directory of the PEtab problem
petab_yaml = "./boehm_JProteomeRes2014/boehm_JProteomeRes2014.yaml"

importer = pypesto.petab.PetabImporter.from_yaml(petab_yaml)
problem = importer.create_problem(verbose=False)

1. Filling in the result file

We will now run a standard parameter estimation pipeline with this model. Aside from the part on the history, we shall not go into detail here, as this is covered in other tutorials such as Getting Started and AMICI in pyPESTO.

Optimization

[4]:
%%time

# create optimizers
optimizer = optimize.FidesOptimizer(
    verbose=logging.ERROR, options={"maxiter": 200}
)

# set number of starts
n_starts = 15  # usually a larger number >=100 is used

# Optimization
result = pypesto.optimize.minimize(
    problem=problem, optimizer=optimizer, n_starts=n_starts
)
2024-04-15 14:36:38.153 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.316 and h = 4.50828e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:38.154 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.316: AMICI failed to integrate the forward problem
2024-04-15 14:36:38.489 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.1314 and h = 1.7938e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:38.489 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.1314: AMICI failed to integrate the forward problem
2024-04-15 14:36:38.742 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0994 and h = 3.95389e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:38.743 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0994: AMICI failed to integrate the forward problem
2024-04-15 14:36:38.776 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.553 and h = 3.07611e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:38.777 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.553: AMICI failed to integrate the forward problem
2024-04-15 14:36:39.926 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.21 and h = 4.17226e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:39.927 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.21: AMICI failed to integrate the forward problem
2024-04-15 14:36:40.008 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.215 and h = 3.31678e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:40.009 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.215: AMICI failed to integrate the forward problem
2024-04-15 14:36:40.189 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.058 and h = 4.41912e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:40.190 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.058: AMICI failed to integrate the forward problem
2024-04-15 14:36:40.221 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.592 and h = 2.58614e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:40.221 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.592: AMICI failed to integrate the forward problem
2024-04-15 14:36:43.227 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.2724 and h = 1.22304e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:43.228 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.2724: AMICI failed to integrate the forward problem
2024-04-15 14:36:43.311 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.716 and h = 3.46024e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:43.312 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.716: AMICI failed to integrate the forward problem
2024-04-15 14:36:46.964 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0476 and h = 3.81123e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:46.964 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0476: AMICI failed to integrate the forward problem
2024-04-15 14:36:50.196 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 109.039 and h = 6.78705e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:50.197 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 109.039: AMICI failed to integrate the forward problem
2024-04-15 14:36:50.423 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 87.932 and h = 6.22491e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:50.424 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 87.932: AMICI failed to integrate the forward problem
2024-04-15 14:36:52.414 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 116.416 and h = 9.23603e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:52.415 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 116.416: AMICI failed to integrate the forward problem
2024-04-15 14:36:52.531 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 78.7752 and h = 1.07906e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:52.531 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 78.7752: AMICI failed to integrate the forward problem
2024-04-15 14:36:52.653 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 83.0452 and h = 8.14859e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:52.653 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 83.0452: AMICI failed to integrate the forward problem
CPU times: user 18.4 s, sys: 630 ms, total: 19.1 s
Wall time: 18.1 s
[5]:
display(Markdown(result.summary()))

Optimization Result

  • number of starts: 15

  • best value: 147.54396265366086, id=2

  • worst value: 249.74584993325362, id=13

  • number of non-finite values: 0

  • execution time summary:

    • Mean execution time: 1.208s

    • Maximum execution time: 2.569s, id=7

    • Minimum execution time: 0.157s, id=13

  • summary of optimizer messages:

    Count

    Message

    14

    Converged according to fval difference

    1

    Trust Region Radius too small to proceed

  • best value found (approximately) 7 time(s)

  • number of plateaus found: 3

A summary of the best run:

Optimizer Result

  • optimizer used: <FidesOptimizer hessian_update=default verbose=40 options={‘maxiter’: 200}>

  • message: Trust Region Radius too small to proceed

  • number of evaluations: 83

  • time taken to optimize: 1.398s

  • startpoint: [ 2.43048992 -1.70582011 -0.35232805 3.82011973 3.77318457 -0.3052432 -1.01106052 -4.5584614 -4.95371209]

  • endpoint: [-1.50321189 -3.35809929 4.9265192 -1.77784205 -1.75880841 3.98192698 0.6319766 0.78928571 0.73486701]

  • final objective value: 147.54396265366086

  • final gradient value: [-1.79613291e-02 -8.00644244e-04 -5.87893084e-06 1.94817363e-03 -7.76672751e-03 -1.59175821e-02 -1.66677433e-03 -7.91856683e-04 1.66072449e-03]

  • final hessian value: [[ 2.42028399e+03 2.18624313e+01 -1.40512648e-04 1.80808916e+03 6.88260542e+02 -9.06267540e+02 1.80937999e+01 -9.17862226e+00 -8.87382018e+00] [ 2.18624313e+01 1.00972094e+00 -2.49009075e-06 1.35913922e+01 8.94471054e-01 -9.01038972e+00 -4.48654137e-02 -2.96967206e-01 3.43676171e-01] [-1.40512648e-04 -2.49009075e-06 1.48568089e-11 -9.80908004e-05 -2.95847718e-05 7.59646676e-05 3.28397664e-06 -6.77021773e-08 1.03204641e-05] [ 1.80808916e+03 1.35913922e+01 -9.80908004e-05 1.37844802e+03 5.22124376e+02 -6.38382132e+02 2.39692837e+01 -8.16184316e+00 -1.58119264e+01] [ 6.88260542e+02 8.94471054e-01 -2.95847718e-05 5.22124376e+02 2.98627339e+02 -2.95673590e+02 -1.05217827e+01 -4.04702513e+00 1.45866914e+01] [-9.06267540e+02 -9.01038972e+00 7.59646676e-05 -6.38382132e+02 -2.95673590e+02 8.97440862e+02 1.04858057e+01 -3.74408882e+01 2.69917341e+01] [ 1.80937999e+01 -4.48654137e-02 3.28397664e-06 2.39692837e+01 -1.05217827e+01 1.04858057e+01 8.48342077e+01 0.00000000e+00 0.00000000e+00] [-9.17862226e+00 -2.96967206e-01 -6.77021773e-08 -8.16184316e+00 -4.04702513e+00 -3.74408882e+01 0.00000000e+00 8.48321931e+01 0.00000000e+00] [-8.87382018e+00 3.43676171e-01 1.03204641e-05 -1.58119264e+01 1.45866914e+01 2.69917341e+01 0.00000000e+00 0.00000000e+00 8.48265458e+01]]

Profiling

[6]:
%%time

# Profiling
result = profile.parameter_profile(
    problem=problem,
    result=result,
    optimizer=optimizer,
    profile_index=np.array([1, 1, 1, 0, 0, 0, 0, 0, 1]),
)
2024-04-15 14:36:54.483 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 91.7234 and h = 1.76076e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:54.484 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 91.7234: AMICI failed to integrate the forward problem
2024-04-15 14:36:54.608 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 91.7809 and h = 1.71294e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:54.608 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 91.7809: AMICI failed to integrate the forward problem
2024-04-15 14:36:54.749 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.768 and h = 2.34636e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:54.750 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.768: AMICI failed to integrate the forward problem
2024-04-15 14:36:55.094 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 95.8078 and h = 3.57267e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:55.095 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 95.8078: AMICI failed to integrate the forward problem
2024-04-15 14:36:55.602 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.1084 and h = 4.58154e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:55.603 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.1084: AMICI failed to integrate the forward problem
2024-04-15 14:36:55.781 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 144.937 and h = 2.36762e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:55.782 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 144.937: AMICI failed to integrate the forward problem
2024-04-15 14:36:56.549 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 226.416 and h = 4.86033e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:56.549 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 226.416: AMICI failed to integrate the forward problem
2024-04-15 14:36:56.655 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 81.4645 and h = 4.01947e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:56.655 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 81.4645: AMICI failed to integrate the forward problem
2024-04-15 14:36:56.918 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.144 and h = 5.19836e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:56.918 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.144: AMICI failed to integrate the forward problem
2024-04-15 14:36:56.985 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.116 and h = 2.37242e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:56.986 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.116: AMICI failed to integrate the forward problem
2024-04-15 14:36:57.035 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.029 and h = 1.66556e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:57.036 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.029: AMICI failed to integrate the forward problem
2024-04-15 14:36:57.069 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.056 and h = 3.78949e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:57.070 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.056: AMICI failed to integrate the forward problem
2024-04-15 14:36:57.085 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 79.0782 and h = 2.12412e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:57.086 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 79.0782: AMICI failed to integrate the forward problem
2024-04-15 14:36:57.498 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 74.8804 and h = 3.95773e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:57.499 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 74.8804: AMICI failed to integrate the forward problem
2024-04-15 14:36:57.672 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 141.996 and h = 4.10822e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:57.672 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 141.996: AMICI failed to integrate the forward problem
2024-04-15 14:36:57.866 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 140.189 and h = 5.48725e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:57.867 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 140.189: AMICI failed to integrate the forward problem
2024-04-15 14:36:58.056 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 139.588 and h = 2.3272e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:58.056 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 139.588: AMICI failed to integrate the forward problem
2024-04-15 14:36:58.171 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 69.5251 and h = 3.05118e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:58.171 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 69.5251: AMICI failed to integrate the forward problem
2024-04-15 14:36:58.222 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 139.537 and h = 2.16563e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:58.223 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 139.537: AMICI failed to integrate the forward problem
2024-04-15 14:36:59.289 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 133.132 and h = 2.51316e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:59.289 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 133.132: AMICI failed to integrate the forward problem
2024-04-15 14:36:59.440 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 132.318 and h = 4.48473e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:36:59.441 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 132.318: AMICI failed to integrate the forward problem
2024-04-15 14:37:00.591 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 85.6747 and h = 5.9093e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:00.592 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 85.6747: AMICI failed to integrate the forward problem
2024-04-15 14:37:00.627 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 149.86 and h = 1.94516e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:00.627 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 149.86: AMICI failed to integrate the forward problem
2024-04-15 14:37:01.328 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 155.164 and h = 3.52796e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:01.329 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 155.164: AMICI failed to integrate the forward problem
2024-04-15 14:37:01.459 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 81.0745 and h = 8.64471e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:01.459 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 81.0745: AMICI failed to integrate the forward problem
2024-04-15 14:37:01.719 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 155.237 and h = 2.62234e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:01.719 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 155.237: AMICI failed to integrate the forward problem
2024-04-15 14:37:03.919 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 136.146 and h = 2.27733e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:03.920 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 136.146: AMICI failed to integrate the forward problem
2024-04-15 14:37:04.287 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 97.2435 and h = 1.57414e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:04.288 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 97.2435: AMICI failed to integrate the forward problem
2024-04-15 14:37:04.611 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 99.186 and h = 6.21343e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:04.611 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 99.186: AMICI failed to integrate the forward problem
2024-04-15 14:37:05.075 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 132.823 and h = 4.25397e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:05.076 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 132.823: AMICI failed to integrate the forward problem
2024-04-15 14:37:05.108 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 102.23 and h = 3.4761e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:05.108 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 102.23: AMICI failed to integrate the forward problem
2024-04-15 14:37:05.209 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 102.32 and h = 4.35519e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:05.209 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 102.32: AMICI failed to integrate the forward problem
2024-04-15 14:37:05.446 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 132.784 and h = 3.88674e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:05.446 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 132.784: AMICI failed to integrate the forward problem
2024-04-15 14:37:05.762 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 102.16 and h = 5.29468e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:05.762 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 102.16: AMICI failed to integrate the forward problem
2024-04-15 14:37:05.796 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 132.768 and h = 1.76787e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:05.797 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 132.768: AMICI failed to integrate the forward problem
CPU times: user 11.9 s, sys: 471 ms, total: 12.4 s
Wall time: 11.7 s

Sampling

[7]:
%%time

# Sampling
sampler = sample.AdaptiveMetropolisSampler()
result = sample.sample(
    problem=problem,
    sampler=sampler,
    n_samples=5000,  # rather low
    result=result,
    filename=None,
)
Elapsed time: 16.969201720999997
CPU times: user 14.4 s, sys: 2.55 s, total: 17 s
Wall time: 13.2 s

2. Storing the result file

We filled all our analyses into one result file. We can now store this result object into HDF5 format to reload this later on.

[8]:
# create temporary file
fn = tempfile.NamedTemporaryFile(suffix=".hdf5", delete=False)
# write the result with the write_result function.
# Choose which parts of the result object to save with
# corresponding booleans.
pypesto.store.write_result(
    result=result,
    filename=fn.name,
    problem=True,
    optimize=True,
    profile=True,
    sample=True,
)

As easy as we can save the result object, we can also load it again:

[9]:
# load result with read_result function
result_loaded = pypesto.store.read_result(fn.name)
/home/docs/checkouts/readthedocs.org/user_builds/pypesto/envs/v0.5.1/lib/python3.11/site-packages/pypesto/store/read_from_hdf5.py:304: UserWarning: You are loading a problem. This problem is not to be used without a separately created objective.
  result.problem = pypesto_problem_reader.read()

As you can see, when loading the result object, we get a warning regarding the problem. This is the case, as the problem is not fully saved into hdf5, as a big part of the problem is the objective function. Therefore, after loading the result object, we cannot evaluate the objective function anymore. We can, however, still use the result object for plotting and further analysis.

The best practice would be to still create the problem through petab and insert it into the result object after loading it.

[10]:
# dummy call to non-existent objective function would fail
test_parameter = result.optimize_result[0].x[problem.x_free_indices]
# result_loaded.problem.objective(test_parameter)
[11]:
result_loaded.problem = problem
print(
    f"Objective function call: {result_loaded.problem.objective(test_parameter)}"
)
print(f"Corresponding saved value: {result_loaded.optimize_result[0].fval}")
Objective function call: 147.54396985748588
Corresponding saved value: 147.54396265366086

To show that for visualizations however, the storage and loading of the result object is accurate, we will plot some result visualizations.

3. Visualization Comparison

Optimization

[12]:
# waterfall plot original
ax = visualize.waterfall(result)
ax.title.set_text("Original Result")
../_images/example_store_24_0.png
[13]:
# waterfall plot loaded
ax = visualize.waterfall(result_loaded)
ax.title.set_text("Loaded Result")
../_images/example_store_25_0.png

Profiling

[14]:
# profile plot original
ax = visualize.profiles(result)
../_images/example_store_27_0.png
[15]:
# profile plot loaded
ax = visualize.profiles(result_loaded)
../_images/example_store_28_0.png

Sampling

[16]:
# sampling plot original
ax = visualize.sampling_fval_traces(result)
/home/docs/checkouts/readthedocs.org/user_builds/pypesto/envs/v0.5.1/lib/python3.11/site-packages/pypesto/visualize/sampling.py:79: UserWarning: Burn in index not found in the results, the full chain will be shown.
You may want to use, e.g., `pypesto.sample.geweke_test`.
  _, params_fval, _, _, _ = get_data_to_plot(
../_images/example_store_30_1.png
[17]:
# sampling plot loaded
ax = visualize.sampling_fval_traces(result_loaded)
/home/docs/checkouts/readthedocs.org/user_builds/pypesto/envs/v0.5.1/lib/python3.11/site-packages/pypesto/visualize/sampling.py:79: UserWarning: Burn in index not found in the results, the full chain will be shown.
You may want to use, e.g., `pypesto.sample.geweke_test`.
  _, params_fval, _, _, _ = get_data_to_plot(
../_images/example_store_31_1.png

We can see that we are perfectly able to reproduce the plots from the loaded result object. With this, we can reuse the result object for further analysis and visualization again and again without spending time and resources on rerunning the analyses.

4. Optimization History

During optimization, it is possible to regularly write the objective function trace to file. This is useful, e.g., when runs fail, or for various diagnostics. Currently, pyPESTO can save histories to 3 backends: in-memory, as CSV files, or to HDF5 files.

Memory History

To record the history in-memory, just set trace_record=True in the pypesto.HistoryOptions. Then, the optimization result contains those histories:

[18]:
# record the history
history_options = pypesto.HistoryOptions(trace_record=True)

# Run optimizations
result = optimize.minimize(
    problem=problem,
    optimizer=optimizer,
    n_starts=n_starts,
    history_options=history_options,
    filename=None,
)
2024-04-15 14:37:22.123 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 148.033 and h = 3.97012e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:22.123 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 148.033: AMICI failed to integrate the forward problem
2024-04-15 14:37:22.467 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0195 and h = 2.23534e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:22.467 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0195: AMICI failed to integrate the forward problem
2024-04-15 14:37:22.515 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.797 and h = 3.39677e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:22.516 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.797: AMICI failed to integrate the forward problem
2024-04-15 14:37:23.291 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 184.342 and h = 3.88554e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:23.291 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 184.342: AMICI failed to integrate the forward problem
2024-04-15 14:37:25.855 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0633 and h = 1.65522e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:25.856 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0633: AMICI failed to integrate the forward problem
2024-04-15 14:37:26.715 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 75.402 and h = 1.9825e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:26.716 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 75.402: AMICI failed to integrate the forward problem
2024-04-15 14:37:26.969 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.2658 and h = 1.3084e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:26.969 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.2658: AMICI failed to integrate the forward problem
2024-04-15 14:37:27.348 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.596 and h = 3.11657e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:27.349 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.596: AMICI failed to integrate the forward problem
2024-04-15 14:37:28.941 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 230.941 and h = 3.2538e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:28.941 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 230.941: AMICI failed to integrate the forward problem
2024-04-15 14:37:30.489 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 173.287 and h = 1.96644e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:30.490 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 173.287: AMICI failed to integrate the forward problem
2024-04-15 14:37:32.372 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 147.782 and h = 3.82159e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:32.373 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 147.782: AMICI failed to integrate the forward problem
2024-04-15 14:37:32.407 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 91.1688 and h = 2.27468e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:32.407 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 91.1688: AMICI failed to integrate the forward problem
2024-04-15 14:37:32.840 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.838 and h = 5.00335e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:32.840 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.838: AMICI failed to integrate the forward problem
2024-04-15 14:37:33.122 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0247 and h = 9.72132e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:33.123 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0247: AMICI failed to integrate the forward problem
2024-04-15 14:37:33.613 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.1351 and h = 4.35791e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:33.614 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.1351: AMICI failed to integrate the forward problem
2024-04-15 14:37:34.383 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0619 and h = 7.60729e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:34.384 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0619: AMICI failed to integrate the forward problem
2024-04-15 14:37:36.815 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 214.03 and h = 1.28169e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:36.815 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 214.03: AMICI failed to integrate the forward problem
2024-04-15 14:37:39.551 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.6108 and h = 8.99172e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:39.552 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.6108: AMICI failed to integrate the forward problem
2024-04-15 14:37:41.134 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 19.7618 and h = 2.12464e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:41.135 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 19.7618: AMICI failed to integrate the forward problem
2024-04-15 14:37:41.616 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 53.3095 and h = 4.74276e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:41.616 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 53.3095: AMICI failed to integrate the forward problem
2024-04-15 14:37:41.961 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 87.3834 and h = 1.32928e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:41.962 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 87.3834: AMICI failed to integrate the forward problem
2024-04-15 14:37:44.171 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.617 and h = 4.78354e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:44.172 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.617: AMICI failed to integrate the forward problem
2024-04-15 14:37:44.501 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.493 and h = 4.06916e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:44.501 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.493: AMICI failed to integrate the forward problem
2024-04-15 14:37:44.553 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.422 and h = 3.26691e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:44.554 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.422: AMICI failed to integrate the forward problem

Now, in addition to queries on the result, we can also access the history.

[19]:
print("History type: ", type(result.optimize_result.list[0].history))
# print("Function value trace of best run: ", result.optimize_result.list[0].history.get_fval_trace())

fig, ax = plt.subplots(1, 2)
visualize.waterfall(result, ax=ax[0])
visualize.optimizer_history(result, ax=ax[1])
fig.set_size_inches((15, 5))
History type:  <class 'pypesto.history.memory.MemoryHistory'>
../_images/example_store_39_1.png

CSV History

The in-memory storage is, however, not stored anywhere. To do that, it is possible to store either to CSV or HDF5. This is specified via the storage_file option. If it ends in .csv, a pypesto.objective.history.CsvHistory will be employed; if it ends in .hdf5 a pypesto.objective.history.Hdf5History. Occurrences of the substring {id} in the filename are replaced by the multistart id, allowing to maintain a separate file per run (this is necessary for CSV as otherwise runs are overwritten).

[20]:
# create temporary file
with tempfile.NamedTemporaryFile(suffix="_{id}.csv") as fn_csv:
    # record the history and store to CSV
    history_options = pypesto.HistoryOptions(
        trace_record=True, storage_file=fn_csv.name
    )

    # Run optimizations
    result = optimize.minimize(
        problem=problem,
        optimizer=optimizer,
        n_starts=n_starts,
        history_options=history_options,
        filename=None,
    )
2024-04-15 14:37:46.351 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 238.582 and h = 3.67308e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:46.351 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 238.582: AMICI failed to integrate the forward problem
2024-04-15 14:37:47.012 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.6593 and h = 1.19181e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:47.013 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.6593: AMICI failed to integrate the forward problem
2024-04-15 14:37:47.257 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 90.888 and h = 1.51384e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:47.257 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 90.888: AMICI failed to integrate the forward problem
2024-04-15 14:37:47.444 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.8547 and h = 2.64966e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:47.445 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.8547: AMICI failed to integrate the forward problem
2024-04-15 14:37:49.474 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 9.74005 and h = 2.4647e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:49.475 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 9.74005: AMICI failed to integrate the forward problem
2024-04-15 14:37:49.601 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 9.85398 and h = 2.61976e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:49.602 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 9.85398: AMICI failed to integrate the forward problem
2024-04-15 14:37:49.705 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 9.8579 and h = 1.51657e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:49.706 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 9.8579: AMICI failed to integrate the forward problem
2024-04-15 14:37:55.051 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 142.982 and h = 2.76054e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:55.052 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 142.982: AMICI failed to integrate the forward problem
2024-04-15 14:37:55.091 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.029 and h = 2.8378e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:55.092 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.029: AMICI failed to integrate the forward problem
2024-04-15 14:37:59.296 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0179 and h = 1.14666e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:59.296 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0179: AMICI failed to integrate the forward problem
2024-04-15 14:37:59.669 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.504 and h = 4.04183e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:59.669 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.504: AMICI failed to integrate the forward problem
2024-04-15 14:37:59.914 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.9644 and h = 1.58197e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:37:59.914 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.9644: AMICI failed to integrate the forward problem
2024-04-15 14:38:00.004 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.1379 and h = 2.02888e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:00.005 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.1379: AMICI failed to integrate the forward problem
2024-04-15 14:38:00.798 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 148.803 and h = 4.17673e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:00.799 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 148.803: AMICI failed to integrate the forward problem
2024-04-15 14:38:00.850 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 91.5623 and h = 2.17839e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:00.851 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 91.5623: AMICI failed to integrate the forward problem
2024-04-15 14:38:00.908 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 91.9085 and h = 2.09607e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:00.909 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 91.9085: AMICI failed to integrate the forward problem
2024-04-15 14:38:02.714 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.4756 and h = 1.42839e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:02.715 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.4756: AMICI failed to integrate the forward problem
2024-04-15 14:38:04.340 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 153.349 and h = 2.67618e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:04.340 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 153.349: AMICI failed to integrate the forward problem
2024-04-15 14:38:04.646 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 169.591 and h = 4.59801e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:04.647 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 169.591: AMICI failed to integrate the forward problem
2024-04-15 14:38:05.100 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.246 and h = 2.93669e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:05.101 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.246: AMICI failed to integrate the forward problem

Note that for this simple cost function, saving to CSV takes a considerable amount of time. This overhead decreases for more costly simulators, e.g., using ODE simulations via AMICI.

[21]:
print("History type: ", type(result.optimize_result.list[0].history))
# print("Function value trace of best run: ", result.optimize_result.list[0].history.get_fval_trace())

fig, ax = plt.subplots(1, 2)
visualize.waterfall(result, ax=ax[0])
visualize.optimizer_history(result, ax=ax[1])
fig.set_size_inches((15, 5))
History type:  <class 'pypesto.history.amici.CsvAmiciHistory'>
../_images/example_store_44_1.png

HDF5 History

Just as in CSV, writing the history to HDF5 takes a considerable amount of time. If a user specifies a HDF5 output file named my_results.hdf5 and uses a parallelization engine, then: * a folder is created to contain partial results, named my_results/ (the stem of the output filename) * files are created to store the results of each start, named my_results/my_results_{START_INDEX}.hdf5 * a file is created to store the combined result from all starts, named my_results.hdf5. Note that this file depends on the files in the my_results/ directory, so cease to function if my_results/ is deleted.

[22]:
# create temporary file
f_hdf5 = tempfile.NamedTemporaryFile(suffix=".hdf5", delete=False)
fn_hdf5 = f_hdf5.name

# record the history and store to CSV
history_options = pypesto.HistoryOptions(
    trace_record=True, storage_file=fn_hdf5
)

# Run optimizations
result = optimize.minimize(
    problem=problem,
    optimizer=optimizer,
    n_starts=n_starts,
    history_options=history_options,
    filename=fn_hdf5,
)
2024-04-15 14:38:10.502 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 117.97 and h = 9.16638e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:10.503 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 117.97: AMICI failed to integrate the forward problem
2024-04-15 14:38:12.743 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 70.0924 and h = 4.58915e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:12.744 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 70.0924: AMICI failed to integrate the forward problem
2024-04-15 14:38:13.757 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 108.409 and h = 2.73792e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:13.758 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 108.409: AMICI failed to integrate the forward problem
2024-04-15 14:38:14.016 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 120 and h = 4.14091e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:14.017 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 120: AMICI failed to integrate the forward problem
2024-04-15 14:38:14.681 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 85.6113 and h = 2.17468e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:14.681 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 85.6113: AMICI failed to integrate the forward problem
2024-04-15 14:38:14.959 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 149.673 and h = 1.131e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:14.959 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 149.673: AMICI failed to integrate the forward problem
2024-04-15 14:38:15.139 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.569 and h = 2.5548e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:15.140 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.569: AMICI failed to integrate the forward problem
2024-04-15 14:38:15.200 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.447 and h = 1.16517e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:15.201 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.447: AMICI failed to integrate the forward problem
2024-04-15 14:38:15.357 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 87.544 and h = 1.95364e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:15.357 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 87.544: AMICI failed to integrate the forward problem
2024-04-15 14:38:16.927 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 87.9104 and h = 6.1141e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:16.928 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 87.9104: AMICI failed to integrate the forward problem
2024-04-15 14:38:17.184 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0502 and h = 1.28097e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:17.184 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0502: AMICI failed to integrate the forward problem
2024-04-15 14:38:24.868 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 168.759 and h = 2.82345e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:24.869 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 168.759: AMICI failed to integrate the forward problem
2024-04-15 14:38:27.789 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 144.943 and h = 3.91346e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:27.789 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 144.943: AMICI failed to integrate the forward problem
2024-04-15 14:38:29.012 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 65.4126 and h = 5.50693e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-15 14:38:29.013 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 65.4126: AMICI failed to integrate the forward problem
[23]:
print("History type: ", type(result.optimize_result.list[0].history))
# print("Function value trace of best run: ", result.optimize_result.list[0].history.get_fval_trace())

fig, ax = plt.subplots(1, 2)
visualize.waterfall(result, ax=ax[0])
visualize.optimizer_history(result, ax=ax[1])
fig.set_size_inches((15, 5))
History type:  <class 'pypesto.history.amici.Hdf5AmiciHistory'>
../_images/example_store_48_1.png

For the HDF5 history, it is possible to load the history from file, and to plot it, together with the optimization result.

[24]:
# load the history
result_loaded_w_history = pypesto.store.read_result(fn_hdf5)

fig, ax = plt.subplots(1, 2)
visualize.waterfall(result_loaded_w_history, ax=ax[0])
visualize.optimizer_history(result_loaded_w_history, ax=ax[1])
fig.set_size_inches((15, 5))
/home/docs/checkouts/readthedocs.org/user_builds/pypesto/envs/v0.5.1/lib/python3.11/site-packages/pypesto/store/read_from_hdf5.py:304: UserWarning: You are loading a problem. This problem is not to be used without a separately created objective.
  result.problem = pypesto_problem_reader.read()
Loading the profiling result failed. It is highly likely that no profiling result exists within /tmp/tmpal2e7a2g.hdf5.
Loading the sampling result failed. It is highly likely that no sampling result exists within /tmp/tmpal2e7a2g.hdf5.
../_images/example_store_50_3.png
[25]:
# close the temporary file
f_hdf5.close()