Skip to content

Commit c4a395b

Browse files
authored
Fix regeneration of expected results hdf5 (#3073)
* Restore deleted data file * Update to changed locations and names
1 parent af76f17 commit c4a395b

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

tests/cpp/generate_expected_results.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
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

410
import subprocess
511
from pathlib import Path
612

713
import amici
814
import 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
)
1622
from amici.testing.models import (
1723
import_model_calvetti,
@@ -28,7 +34,7 @@
2834
outfile = 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

6672
def 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

tests/generateTestConfig/example_jakstat_adjoint.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

3-
import os
43
import sys
4+
from pathlib import Path
55

66
import numpy as np
77
import pandas as pd
@@ -16,10 +16,9 @@ def __init__(self):
1616
self.numP = 17
1717
self.numK = 2
1818

19-
curPath = os.path.dirname(os.path.realpath(__file__))
2019
dataPath = (
21-
curPath
22-
+ "/../../matlab/examples/example_jakstat_adjoint/pnas_data_original.xls"
20+
Path(__file__).parent
21+
/ "example_jakstat_adjoint_pnas_data_original.xls"
2322
)
2423
xls = pd.ExcelFile(dataPath).parse()
2524
self.modelOptions["ts"] = xls.time
Binary file not shown.

tests/generateTestConfig/example_steadystate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
import numpy as np
5-
from amici import (
5+
from amici.sim.sundials import (
66
SensitivityOrder,
77
SteadyStateComputationMode,
88
SteadyStateSensitivityMode,

0 commit comments

Comments
 (0)