From caeb9f0c2ece232a3113e9cc768cbbf7c277c91f Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Sun, 17 Dec 2023 19:30:39 +0100 Subject: [PATCH] Make solvers deepcopyable --- python/tests/test_swig_interface.py | 10 ++++++++++ swig/solver.i | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/python/tests/test_swig_interface.py b/python/tests/test_swig_interface.py index 6a7cfec855..189c836506 100644 --- a/python/tests/test_swig_interface.py +++ b/python/tests/test_swig_interface.py @@ -471,3 +471,13 @@ def test_expdata_and_expdataview_are_deepcopyable(): ev2 = copy.deepcopy(ev1) assert ev2._swigptr.this != ev1._swigptr.this assert ev1 == ev2 + + +def test_solvers_are_deepcopyable(): + for solver_type in (amici.CVodeSolver, amici.IDASolver): + solver1 = solver_type() + solver2 = copy.deepcopy(solver1) + assert solver1.this != solver2.this + assert solver1.getRelativeTolerance() == solver2.getRelativeTolerance() + solver2.setRelativeTolerance(100 * solver2.getRelativeTolerance()) + assert solver1.getRelativeTolerance() != solver2.getRelativeTolerance() diff --git a/swig/solver.i b/swig/solver.i index 992842c409..f48f3ff71d 100644 --- a/swig/solver.i +++ b/swig/solver.i @@ -116,6 +116,12 @@ def __repr__(self): %} }; +%extend amici::Solver { +%pythoncode %{ +def __deepcopy__(self, memo): + return self.clone() +%} +}; %newobject amici::Solver::clone; // Process symbols in header