11#!/usr/bin/env python3
2- """Generate HDF5 file with expected results for the C++ tests."""
2+ """
3+ Generate HDF5 file with expected results for the C++ tests.
4+
5+ Delete `tests/cpp/expected_results_py.h5` and re-run this script to
6+ regenerate the expected results.
7+ Check the diff carefully before committing!
8+ """
39
410import subprocess
511from pathlib import Path
612
713import amici
814import h5py
9- from amici import (
10- readModelDataFromHDF5 ,
11- readSimulationExpData ,
12- readSolverSettingsFromHDF5 ,
13- runAmiciSimulation ,
14- writeReturnData ,
15+ from amici . sim . sundials import (
16+ read_exp_data_from_hdf5 ,
17+ read_model_data_from_hdf5 ,
18+ read_solver_settings_from_hdf5 ,
19+ run_simulation ,
20+ write_return_data_to_hdf5 ,
1521)
1622from amici .testing .models import (
1723 import_model_calvetti ,
2834outfile = Path (__file__ ).parent / "expected_results_py.h5"
2935
3036
31- def handle_model (id_ : str , model : amici .Model ):
37+ def handle_model (id_ : str , model : amici .sim . sundials . Model ):
3238 # write model settings to h5
3339 script = repo_root / "tests" / "generateTestConfig" / f"example_{ id_ } .py"
3440 subprocess .run ([script , str (outfile )])
@@ -42,36 +48,36 @@ def handle_model(id_: str, model: amici.Model):
4248 for case in cases :
4349 # create a new model instance for each case, to ensure no interference
4450 model = model .module .get_model ()
45- readModelDataFromHDF5 (
46- str ( outfile ), model . get (), f"/model_{ id_ } /{ case } /options "
47- )
48- solver = model . getSolver ()
49- readSolverSettingsFromHDF5 (
50- str ( outfile ), solver , f"/model_ { id_ } / { case } /options"
51- )
51+ options_path = f"/model_ { id_ } / { case } /options"
52+ data_path = f"/model_{ id_ } /{ case } /data "
53+ result_path = f"/model_ { id_ } / { case } /results"
54+
55+ read_model_data_from_hdf5 ( str ( outfile ), model . get (), options_path )
56+ solver = model . create_solver ()
57+ read_solver_settings_from_hdf5 ( str ( outfile ), solver , options_path )
5258 # read ExpData if data/ exists
5359 try :
54- edata = readSimulationExpData (
55- str (outfile ), f"/model_ { id_ } / { case } /data" , model .get ()
60+ edata = read_exp_data_from_hdf5 (
61+ str (outfile ), data_path , model .get ()
5662 )
5763 except RuntimeError :
5864 edata = None
5965
60- rdata = runAmiciSimulation (model , solver , edata )
61- writeReturnData (
62- rdata ._swigptr .get (), str (outfile ), f"/model_ { id_ } / { case } /results"
66+ rdata = run_simulation (model , solver , edata )
67+ write_return_data_to_hdf5 (
68+ rdata ._swigptr .get (), str (outfile ), result_path
6369 )
6470
6571
6672def main ():
6773 """Generate expected results for the C++ tests."""
74+ handle_model ("calvetti" , import_model_calvetti ())
6875 handle_model ("dirac" , import_model_dirac ())
6976 handle_model ("events" , import_model_events ())
70- handle_model ("neuron" , import_model_neuron ())
71- handle_model ("calvetti" , import_model_calvetti ())
72- handle_model ("robertson" , import_model_robertson ())
7377 handle_model ("jakstat_adjoint" , import_model_jakstat ())
7478 handle_model ("nested_events" , import_model_nested_events ())
79+ handle_model ("neuron" , import_model_neuron ())
80+ handle_model ("robertson" , import_model_robertson ())
7581 handle_model ("steadystate" , import_model_steadystate ())
7682
7783
0 commit comments