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-16 14:28:38.289 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.2705 and h = 1.1982e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:38.290 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.2705: AMICI failed to integrate the forward problem
2024-04-16 14:28:38.915 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 90.1538 and h = 3.59967e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:38.915 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 90.1538: AMICI failed to integrate the forward problem
2024-04-16 14:28:39.381 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 87.456 and h = 3.53998e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:39.381 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 87.456: AMICI failed to integrate the forward problem
2024-04-16 14:28:39.398 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.9475 and h = 5.50879e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:39.398 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.9475: AMICI failed to integrate the forward problem
2024-04-16 14:28:39.885 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 125.015 and h = 3.19472e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:39.886 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 125.015: AMICI failed to integrate the forward problem
2024-04-16 14:28:39.973 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 166.785 and h = 3.51903e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:39.973 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 166.785: AMICI failed to integrate the forward problem
2024-04-16 14:28:40.471 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.589 and h = 2.24538e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:40.472 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.589: AMICI failed to integrate the forward problem
2024-04-16 14:28:44.888 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 180.034 and h = 7.53027e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:44.889 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 180.034: AMICI failed to integrate the forward problem
2024-04-16 14:28:45.724 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 12.3764 and h = 3.10638e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:45.725 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 12.3764: AMICI failed to integrate the forward problem
2024-04-16 14:28:46.099 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 128.398 and h = 1.2614e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:46.100 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 128.398: AMICI failed to integrate the forward problem
2024-04-16 14:28:50.239 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.435 and h = 2.69593e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:50.240 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.435: AMICI failed to integrate the forward problem
2024-04-16 14:28:50.256 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 90.2767 and h = 1.01755e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:50.257 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 90.2767: AMICI failed to integrate the forward problem
2024-04-16 14:28:50.413 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.138 and h = 1.37137e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:50.414 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.138: AMICI failed to integrate the forward problem
2024-04-16 14:28:52.031 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 147.492 and h = 2.21407e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:52.032 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 147.492: AMICI failed to integrate the forward problem
2024-04-16 14:28:52.200 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.076 and h = 3.78892e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:52.200 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.076: AMICI failed to integrate the forward problem
2024-04-16 14:28:57.568 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 151.788 and h = 2.58437e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:57.568 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 151.788: AMICI failed to integrate the forward problem
2024-04-16 14:28:57.670 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.1285 and h = 1.42453e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:28:57.671 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.1285: AMICI failed to integrate the forward problem
2024-04-16 14:29:00.560 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 205.886 and h = 2.10498e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:00.560 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 205.886: AMICI failed to integrate the forward problem
2024-04-16 14:29:00.624 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 222.542 and h = 2.3082e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:00.624 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 222.542: AMICI failed to integrate the forward problem
2024-04-16 14:29:00.990 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 237.994 and h = 1.93003e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:00.991 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 237.994: AMICI failed to integrate the forward problem
2024-04-16 14:29:01.429 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 239.834 and h = 2.04954e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:01.429 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 239.834: AMICI failed to integrate the forward problem
2024-04-16 14:29:01.863 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.676 and h = 3.71238e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:01.863 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.676: AMICI failed to integrate the forward problem
CPU times: user 25 s, sys: 707 ms, total: 25.7 s
Wall time: 24.7 s
[5]:
display(Markdown(result.summary()))

Optimization Result

  • number of starts: 15

  • best value: 147.54396202566505, id=12

  • worst value: 249.74599744421172, id=0

  • number of non-finite values: 0

  • execution time summary:

    • Mean execution time: 1.643s

    • Maximum execution time: 4.558s, id=6

    • Minimum execution time: 0.301s, id=8

  • 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: 4

A summary of the best run:

Optimizer Result

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

  • message: Converged according to fval difference

  • number of evaluations: 76

  • time taken to optimize: 1.151s

  • startpoint: [-2.05584779 -0.84140818 -1.72675561 2.59380116 -2.51121525 -4.06115388 -3.25423421 -1.30318564 1.3225711 ]

  • endpoint: [-1.50319945 -3.35478493 4.99999999 -1.77791884 -1.75862648 3.98200221 0.63203464 0.78933999 0.73475694]

  • final objective value: 147.54396202566505

  • final gradient value: [ 3.73922985e-03 1.32469520e-03 -4.96960547e-06 3.62512139e-03 -6.56973699e-03 -7.60410024e-04 2.38982938e-03 3.53393745e-04 -3.15564417e-03]

  • final hessian value: [[ 2.42010590e+03 2.20032471e+01 -1.18631521e-04 1.80817502e+03 6.87522194e+02 -9.06099146e+02 1.81537962e+01 -9.26216780e+00 -8.90023830e+00] [ 2.20032471e+01 1.02323351e+00 -2.11647273e-06 1.36828289e+01 8.92340949e-01 -9.06819594e+00 -4.54000157e-02 -3.00681272e-01 3.43031064e-01] [-1.18631521e-04 -2.11647273e-06 1.05950219e-11 -8.28256916e-05 -2.49446817e-05 6.41414375e-05 2.77255396e-06 -5.27139252e-08 8.72309943e-06] [ 1.80817502e+03 1.36828289e+01 -8.28256916e-05 1.37868211e+03 5.21594717e+02 -6.38323355e+02 2.40343780e+01 -8.22504934e+00 -1.58176758e+01] [ 6.87522194e+02 8.92340949e-01 -2.49446817e-05 5.21594717e+02 2.98201353e+02 -2.95400479e+02 -1.05196344e+01 -4.07112091e+00 1.46058827e+01] [-9.06099146e+02 -9.06819594e+00 6.41414375e-05 -6.38323355e+02 -2.95400479e+02 8.97130825e+02 1.04323473e+01 -3.74387475e+01 2.70081511e+01] [ 1.81537962e+01 -4.54000157e-02 2.77255396e-06 2.40343780e+01 -1.05196344e+01 1.04323473e+01 8.48248670e+01 0.00000000e+00 0.00000000e+00] [-9.26216780e+00 -3.00681272e-01 -5.27139252e-08 -8.22504934e+00 -4.07112091e+00 -3.74387475e+01 0.00000000e+00 8.48295560e+01 0.00000000e+00] [-8.90023830e+00 3.43031064e-01 8.72309943e-06 -1.58176758e+01 1.46058827e+01 2.70081511e+01 0.00000000e+00 0.00000000e+00 8.48376359e+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-16 14:29:02.767 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 94.4939 and h = 6.65751e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:02.767 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 94.4939: AMICI failed to integrate the forward problem
2024-04-16 14:29:02.804 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 94.3618 and h = 1.29022e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:02.804 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 94.3618: AMICI failed to integrate the forward problem
2024-04-16 14:29:03.282 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.722 and h = 3.31501e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:03.283 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.722: AMICI failed to integrate the forward problem
2024-04-16 14:29:03.401 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 86.0343 and h = 1.47198e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:03.402 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 86.0343: AMICI failed to integrate the forward problem
2024-04-16 14:29:03.613 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 85.4012 and h = 4.53672e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:03.614 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 85.4012: AMICI failed to integrate the forward problem
2024-04-16 14:29:03.757 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 85.2749 and h = 3.52731e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:03.757 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 85.2749: AMICI failed to integrate the forward problem
2024-04-16 14:29:03.851 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 67.7316 and h = 2.78976e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:03.852 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 67.7316: AMICI failed to integrate the forward problem
2024-04-16 14:29:03.920 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.418 and h = 3.30747e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:03.921 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.418: AMICI failed to integrate the forward problem
2024-04-16 14:29:04.463 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 234.215 and h = 2.16142e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:04.464 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 234.215: AMICI failed to integrate the forward problem
2024-04-16 14:29:04.811 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 142.871 and h = 2.0625e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:04.812 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 142.871: AMICI failed to integrate the forward problem
2024-04-16 14:29:04.847 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.042 and h = 2.94471e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:04.848 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.042: AMICI failed to integrate the forward problem
2024-04-16 14:29:04.935 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 143.004 and h = 3.82215e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:04.936 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 143.004: AMICI failed to integrate the forward problem
2024-04-16 14:29:05.329 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 74.8658 and h = 2.04311e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:05.330 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 74.8658: AMICI failed to integrate the forward problem
2024-04-16 14:29:05.486 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 74.6468 and h = 1.06192e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:05.487 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 74.6468: AMICI failed to integrate the forward problem
2024-04-16 14:29:05.557 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 140.997 and h = 3.65571e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:05.558 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 140.997: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.147 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 139.401 and h = 3.49079e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.148 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 139.401: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.198 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 69.9961 and h = 3.20875e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.198 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 69.9961: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.215 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 70.1677 and h = 2.4208e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.216 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 70.1677: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.301 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 69.7747 and h = 1.48384e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.301 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 69.7747: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.393 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 69.5184 and h = 2.93938e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.393 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 69.5184: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.482 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 139.51 and h = 4.19393e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.483 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 139.51: AMICI failed to integrate the forward problem
2024-04-16 14:29:06.644 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 139.149 and h = 3.69782e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:06.645 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 139.149: AMICI failed to integrate the forward problem
2024-04-16 14:29:07.357 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 131.636 and h = 3.63644e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:07.358 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 131.636: AMICI failed to integrate the forward problem
2024-04-16 14:29:07.470 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 54.164 and h = 3.10709e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:07.471 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 54.164: AMICI failed to integrate the forward problem
2024-04-16 14:29:07.547 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 132.471 and h = 3.72742e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:07.547 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 132.471: AMICI failed to integrate the forward problem
2024-04-16 14:29:08.337 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.677 and h = 4.81356e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:08.338 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.677: AMICI failed to integrate the forward problem
2024-04-16 14:29:08.571 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 150.041 and h = 4.62259e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:08.571 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 150.041: AMICI failed to integrate the forward problem
2024-04-16 14:29:08.656 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 149.855 and h = 1.8495e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:08.656 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 149.855: AMICI failed to integrate the forward problem
2024-04-16 14:29:08.963 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 152.418 and h = 4.64147e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:08.964 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 152.418: AMICI failed to integrate the forward problem
2024-04-16 14:29:09.522 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 158.387 and h = 2.40207e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:09.523 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 158.387: AMICI failed to integrate the forward problem
2024-04-16 14:29:09.558 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 158.427 and h = 3.43332e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:09.559 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 158.427: AMICI failed to integrate the forward problem
2024-04-16 14:29:09.664 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 158.344 and h = 3.37208e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:09.665 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 158.344: AMICI failed to integrate the forward problem
2024-04-16 14:29:09.991 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 158.517 and h = 2.09499e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:09.992 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 158.517: AMICI failed to integrate the forward problem
2024-04-16 14:29:10.027 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 158.528 and h = 1.87931e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:10.028 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 158.528: AMICI failed to integrate the forward problem
2024-04-16 14:29:10.302 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 75.2266 and h = 1.27866e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:10.303 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 75.2266: AMICI failed to integrate the forward problem
2024-04-16 14:29:10.608 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 168.053 and h = 4.54691e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:10.609 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 168.053: AMICI failed to integrate the forward problem
2024-04-16 14:29:10.753 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 168.195 and h = 1.62844e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:10.754 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 168.195: AMICI failed to integrate the forward problem
2024-04-16 14:29:11.440 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 93.9066 and h = 1.27791e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:11.441 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 93.9066: AMICI failed to integrate the forward problem
2024-04-16 14:29:11.492 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 93.9478 and h = 1.64037e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:11.492 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 93.9478: AMICI failed to integrate the forward problem
2024-04-16 14:29:11.605 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 138.469 and h = 9.27435e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:11.606 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 138.469: AMICI failed to integrate the forward problem
2024-04-16 14:29:11.851 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 95.541 and h = 2.45158e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:11.851 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 95.541: AMICI failed to integrate the forward problem
2024-04-16 14:29:12.247 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 136.232 and h = 1.4079e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:12.248 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 136.232: AMICI failed to integrate the forward problem
2024-04-16 14:29:12.989 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 134.783 and h = 3.57913e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:12.989 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 134.783: AMICI failed to integrate the forward problem
2024-04-16 14:29:13.358 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 133.042 and h = 1.10978e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:13.358 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 133.042: AMICI failed to integrate the forward problem
CPU times: user 11.4 s, sys: 474 ms, total: 11.9 s
Wall time: 11.2 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.547055913
CPU times: user 14.2 s, sys: 2.34 s, total: 16.6 s
Wall time: 13 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/latest/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.54396825638023
Corresponding saved value: 147.54396202566505

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/latest/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/latest/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-16 14:29:29.717 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 91.3645 and h = 1.60689e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:29.717 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 91.3645: AMICI failed to integrate the forward problem
2024-04-16 14:29:30.137 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.68 and h = 2.09603e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:30.137 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.68: AMICI failed to integrate the forward problem
2024-04-16 14:29:30.895 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.542 and h = 4.17007e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:30.896 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.542: AMICI failed to integrate the forward problem
2024-04-16 14:29:32.152 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 168.285 and h = 1.64852e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:32.153 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 168.285: AMICI failed to integrate the forward problem
2024-04-16 14:29:33.400 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.1571 and h = 1.33168e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:33.401 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.1571: AMICI failed to integrate the forward problem
2024-04-16 14:29:35.521 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 98.0785 and h = 2.22821e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:35.522 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 98.0785: AMICI failed to integrate the forward problem
2024-04-16 14:29:36.432 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.659 and h = 4.04152e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:36.433 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.659: AMICI failed to integrate the forward problem
2024-04-16 14:29:38.840 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 139.267 and h = 1.79563e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:38.841 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 139.267: AMICI failed to integrate the forward problem
2024-04-16 14:29:38.979 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 144.772 and h = 2.91083e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:38.980 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 144.772: AMICI failed to integrate the forward problem
2024-04-16 14:29:39.382 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0816 and h = 1.24475e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:39.383 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0816: AMICI failed to integrate the forward problem
2024-04-16 14:29:41.224 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 87.8428 and h = 2.28637e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:41.225 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 87.8428: AMICI failed to integrate the forward problem
2024-04-16 14:29:41.678 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0376 and h = 1.67616e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:41.678 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0376: AMICI failed to integrate the forward problem
2024-04-16 14:29:41.712 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.8864 and h = 7.47234e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:41.713 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.8864: AMICI failed to integrate the forward problem
2024-04-16 14:29:41.819 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.599 and h = 2.69091e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:41.820 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.599: AMICI failed to integrate the forward problem
2024-04-16 14:29:42.219 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0439 and h = 4.61946e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:42.219 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0439: AMICI failed to integrate the forward problem
2024-04-16 14:29:43.257 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.723 and h = 1.29669e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:43.258 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.723: AMICI failed to integrate the forward problem
2024-04-16 14:29:43.480 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.049 and h = 3.40049e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:29:43.481 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.049: 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-16 14:30:06.936 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 178.814 and h = 7.29928e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:06.936 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 178.814: AMICI failed to integrate the forward problem
2024-04-16 14:30:07.013 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 165.068 and h = 1.10673e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:07.013 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 165.068: AMICI failed to integrate the forward problem
2024-04-16 14:30:07.095 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 178.679 and h = 1.68828e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:07.095 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 178.679: AMICI failed to integrate the forward problem
2024-04-16 14:30:07.325 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:TOO_MUCH_WORK] AMICI ERROR: in module CVODES in function CVode : At t = 142.843, mxstep steps taken before reaching tout.
2024-04-16 14:30:07.326 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 142.843: AMICI failed to integrate the forward problem
2024-04-16 14:30:09.459 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.464 and h = 4.21942e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:09.459 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.464: AMICI failed to integrate the forward problem
2024-04-16 14:30:12.721 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.0449 and h = 9.82732e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:12.721 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.0449: AMICI failed to integrate the forward problem
2024-04-16 14:30:14.112 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.354 and h = 1.88486e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:14.113 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.354: AMICI failed to integrate the forward problem
2024-04-16 14:30:14.692 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.742 and h = 3.92573e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:14.693 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.742: AMICI failed to integrate the forward problem
2024-04-16 14:30:15.066 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.592 and h = 1.58305e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:15.067 - 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-16 14:30:15.107 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.578 and h = 2.52918e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:15.107 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.578: AMICI failed to integrate the forward problem
2024-04-16 14:30:15.845 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 146.408 and h = 2.1874e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:15.846 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 146.408: AMICI failed to integrate the forward problem
2024-04-16 14:30:16.209 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.654 and h = 1.99447e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:16.210 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.654: AMICI failed to integrate the forward problem
2024-04-16 14:30:16.229 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.1875 and h = 1.179e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:16.229 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.1875: AMICI failed to integrate the forward problem
2024-04-16 14:30:17.039 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.586 and h = 3.11192e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:17.040 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.586: 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-16 14:30:18.723 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.614 and h = 3.94093e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:18.724 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.614: AMICI failed to integrate the forward problem
2024-04-16 14:30:18.910 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.535 and h = 5.26265e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:18.911 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.535: AMICI failed to integrate the forward problem
2024-04-16 14:30:20.432 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 90.3314 and h = 2.38778e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:20.432 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 90.3314: AMICI failed to integrate the forward problem
2024-04-16 14:30:20.638 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.3192 and h = 1.50854e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:20.639 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.3192: AMICI failed to integrate the forward problem
2024-04-16 14:30:23.210 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.51 and h = 3.2192e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:23.211 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.51: AMICI failed to integrate the forward problem
2024-04-16 14:30:24.628 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.9284 and h = 1.45456e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:24.629 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.9284: AMICI failed to integrate the forward problem
2024-04-16 14:30:24.837 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 88.9762 and h = 1.08078e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:24.838 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 88.9762: AMICI failed to integrate the forward problem
2024-04-16 14:30:26.606 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.632 and h = 2.95705e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:26.606 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.632: AMICI failed to integrate the forward problem
2024-04-16 14:30:32.190 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 89.2327 and h = 1.49021e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:32.191 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 89.2327: AMICI failed to integrate the forward problem
2024-04-16 14:30:32.618 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.483 and h = 3.52509e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:32.619 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.483: AMICI failed to integrate the forward problem
2024-04-16 14:30:35.538 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 98.2395 and h = 3.35315e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:35.539 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 98.2395: AMICI failed to integrate the forward problem
2024-04-16 14:30:37.641 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 217.707 and h = 1.16183e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:37.642 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 217.707: AMICI failed to integrate the forward problem
2024-04-16 14:30:38.105 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 142.967 and h = 9.60039e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:38.105 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 142.967: AMICI failed to integrate the forward problem
2024-04-16 14:30:38.265 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 132.662 and h = 8.67466e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:38.265 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 132.662: AMICI failed to integrate the forward problem
2024-04-16 14:30:38.527 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 161.219 and h = 7.82938e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:38.528 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 161.219: AMICI failed to integrate the forward problem
2024-04-16 14:30:38.700 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 124.02 and h = 7.70433e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:38.701 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 124.02: AMICI failed to integrate the forward problem
2024-04-16 14:30:38.802 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 103.228 and h = 6.76267e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:38.803 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 103.228: AMICI failed to integrate the forward problem
2024-04-16 14:30:38.976 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 150.302 and h = 6.9339e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:38.977 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 150.302: AMICI failed to integrate the forward problem
2024-04-16 14:30:39.022 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 115.543 and h = 6.23208e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:39.023 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 115.543: AMICI failed to integrate the forward problem
2024-04-16 14:30:39.299 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 110.121 and h = 9.35787e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:39.300 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 110.121: AMICI failed to integrate the forward problem
2024-04-16 14:30:39.399 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 153.554 and h = 7.51389e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:39.399 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 153.554: AMICI failed to integrate the forward problem
2024-04-16 14:30:39.447 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 189.001 and h = 6.66793e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:39.448 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 189.001: AMICI failed to integrate the forward problem
2024-04-16 14:30:39.491 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 127.472 and h = 7.53945e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:39.492 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 127.472: AMICI failed to integrate the forward problem
2024-04-16 14:30:40.155 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 181.088 and h = 2.32297e-05, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:40.156 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 181.088: AMICI failed to integrate the forward problem
2024-04-16 14:30:40.699 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 122.108 and h = 8.08675e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:40.700 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 122.108: AMICI failed to integrate the forward problem
2024-04-16 14:30:40.928 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 118.476 and h = 8.24006e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:40.929 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 118.476: AMICI failed to integrate the forward problem
2024-04-16 14:30:41.091 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 124.315 and h = 7.72626e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:41.092 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 124.315: AMICI failed to integrate the forward problem
2024-04-16 14:30:41.481 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 118.3 and h = 8.68733e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:41.482 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 118.3: AMICI failed to integrate the forward problem
2024-04-16 14:30:48.169 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 137.159 and h = 5.8645e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:48.170 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 137.159: AMICI failed to integrate the forward problem
2024-04-16 14:30:49.076 - amici.swig_wrappers - DEBUG - [model1_data1][CVODES:CVode:ERR_FAILURE] AMICI ERROR: in module CVODES in function CVode : At t = 145.602 and h = 8.28022e-06, the error test failed repeatedly or with |h| = hmin.
2024-04-16 14:30:49.076 - amici.swig_wrappers - ERROR - [model1_data1][FORWARD_FAILURE] AMICI forward simulation failed at t = 145.602: 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/latest/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/tmpgp_z0x35.hdf5.
Loading the sampling result failed. It is highly likely that no sampling result exists within /tmp/tmpgp_z0x35.hdf5.
../_images/example_store_50_3.png
[25]:
# close the temporary file
f_hdf5.close()