Skip to content

Commit

Permalink
Make solvers deepcopyable
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Dec 17, 2023
1 parent 594b07e commit caeb9f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/tests/test_swig_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions swig/solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit caeb9f0

Please sign in to comment.