Skip to content

Commit 94c407f

Browse files
authored
Merge branch 'main' into jax_sciml
2 parents 0b3bb26 + 67f3ed6 commit 94c407f

15 files changed

+199
-9
lines changed

.github/workflows/deploy_branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
scripts/buildSdist.sh
3232
3333
- name: "Upload artifact: sdist"
34-
uses: actions/upload-artifact@v4
34+
uses: actions/upload-artifact@v5
3535
with:
3636
name: sdist
3737
path: python/sdist/dist/amici-*.gz

.github/workflows/test_benchmark_collection_models.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
run: |
8585
python3 tests/benchmark_models/evaluate_benchmark.py
8686
87-
- uses: actions/upload-artifact@v4
87+
- uses: actions/upload-artifact@v5
8888
with:
8989
name: computation-times-${{ matrix.python-version }}-${{ matrix.extract_subexpressions }}
9090
path: |

.github/workflows/test_performance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
AMICI_IMPORT_NPROCS=2 check_time.sh petab_import python tests/performance/test.py import
5656
5757
- name: "Upload artifact: CS_Signalling_ERBB_RAS_AKT_petab"
58-
uses: actions/upload-artifact@v4
58+
uses: actions/upload-artifact@v5
5959
with:
6060
name: model_performance_test
6161
path: model_performance_test

.github/workflows/test_sbml_semantic_test_suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- run: AMICI_PARALLEL_COMPILE="" ./scripts/run-SBMLTestsuite.sh ${{ matrix.cases }}
4848

4949
- name: "Upload artifact: SBML semantic test suite results"
50-
uses: actions/upload-artifact@v4
50+
uses: actions/upload-artifact@v5
5151
with:
5252
name: amici-semantic-results-${{ matrix.cases }}
5353
path: tests/sbml/amici-semantic-results

.github/workflows/test_sbml_semantic_test_suite_jax.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- run: ./scripts/run-SBMLTestsuite.sh --jax ${{ matrix.cases }}
4545

4646
- name: "Upload artifact: SBML semantic test suite results"
47-
uses: actions/upload-artifact@v4
47+
uses: actions/upload-artifact@v5
4848
with:
4949
name: amici-semantic-results-jax-${{ matrix.cases }}
5050
path: tests/sbml/amici-semantic-results-jax

CHANGELOG.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ See also our [versioning policy](https://amici.readthedocs.io/en/latest/versioni
6161
This is a wrapper for both `amici.run_simulation` and
6262
`amici.run_simulations`, depending on the type of the `edata` argument.
6363
It also supports passing some `Solver` options as keyword arguments.
64-
* `amici.ModelPtr` now supports sufficient pickling for use in
65-
multi-processing contexts. This works only if the amici-generated model
66-
package exists in the same file system location and does not change until
67-
unpickling.
64+
* Improved `pickle` support for `amici.{ModelPtr,Solver,ExpData`.
65+
Note that AMICI's pickling support is only intended for short-term storage
66+
or inter-process communication.
67+
Reading pickled objects after updating AMICI or the model code will almost
68+
certainly fail.
69+
* `amici.ModelPtr` now supports sufficient pickling for use in
70+
multi-processing contexts. This works only if the amici-generated model
71+
package exists in the same file system location and does not change until
72+
unpickling.
73+
* `amici.Solver` is now picklable if amici was built with HDF5 support.
74+
This only works on shared file systems, as the solver state is stored in a
75+
temporary HDF5 file.
76+
* `amici.ExpData` is now picklable.
6877

6978
## v0.X Series
7079

include/amici/solver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class Solver {
7575
*/
7676
SUNContext get_sun_context() const;
7777

78+
/**
79+
* @brief Get the name of this class.
80+
* @return Class name.
81+
*/
82+
virtual std::string get_class_name() const = 0;
83+
7884
/**
7985
* @brief runs a forward simulation until the specified timepoint
8086
*

include/amici/solver_cvodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class CVodeSolver : public Solver {
3838
*/
3939
Solver* clone() const override;
4040

41+
std::string get_class_name() const override {return "CVodeSolver"; };
42+
4143
void reinit(
4244
realtype t0, AmiVector const& yy0, AmiVector const& yp0
4345
) const override;

include/amici/solver_idas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class IDASolver : public Solver {
3535
*/
3636
Solver* clone() const override;
3737

38+
std::string get_class_name() const override {return "IDASolver"; };
39+
3840
void reinit_post_process_f(realtype tnext) const override;
3941

4042
void reinit_post_process_b(realtype tnext) const override;

python/sdist/amici/swig_wrappers.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,52 @@ def file_checksum(
397397
for chunk in iter(lambda: f.read(chunk_size), b""):
398398
h.update(chunk)
399399
return h.hexdigest()
400+
401+
402+
def restore_edata(
403+
init_args: Sequence,
404+
simulation_parameter_dict: dict[str, Any],
405+
) -> amici_swig.ExpData:
406+
"""
407+
Recreate an ExpData instance.
408+
409+
For use in ExpData.__reduce__.
410+
"""
411+
edata = amici_swig.ExpData(*init_args)
412+
413+
edata.pscale = amici.parameter_scaling_from_int_vector(
414+
simulation_parameter_dict.pop("pscale")
415+
)
416+
for key, value in simulation_parameter_dict.items():
417+
if key == "timepoints":
418+
# timepoints are set during ExpData construction
419+
continue
420+
assert hasattr(edata, key)
421+
setattr(edata, key, value)
422+
return edata
423+
424+
425+
def restore_solver(cls: type, cls_name: str, hdf5_file: str) -> Solver:
426+
"""
427+
Recreate a Solver or SolverPtr instance from an HDF5 file.
428+
429+
For use in Solver.__reduce__.
430+
431+
:param cls:
432+
Class of the original object ({CVode,IDA}Solver or SolverPtr).
433+
:param cls_name:
434+
Name of the (pointed to) solver class ("CVodeSolver" or "IDASolver").
435+
:param hdf5_file:
436+
HDF5 file from which to read the solver settings.
437+
"""
438+
if cls_name == "CVodeSolver":
439+
solver = amici.CVodeSolver()
440+
elif cls_name == "IDASolver":
441+
solver = amici.IDASolver()
442+
else:
443+
raise ValueError(f"Unknown solver class name: {cls_name}")
444+
445+
if not issubclass(cls, Solver):
446+
solver = cls(solver)
447+
read_solver_settings_from_hdf5(hdf5_file, solver)
448+
return solver

0 commit comments

Comments
 (0)