Skip to content

Commit

Permalink
Make Model, ModelPtr deepcopyable
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Dec 18, 2023
1 parent 594b07e commit 637f884
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions python/tests/test_swig_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,16 @@ def test_expdata_and_expdataview_are_deepcopyable():
ev2 = copy.deepcopy(ev1)
assert ev2._swigptr.this != ev1._swigptr.this
assert ev1 == ev2


def test_model_is_deepcopyable(pysb_example_presimulation_module):
model_module = pysb_example_presimulation_module
for model1 in (
model_module.getModel(),
amici.ModelPtr(model_module.getModel()),
):
model2 = copy.deepcopy(model1)
assert model1.this != model2.this
assert model1.getT0() == model2.getT0()
model2.setT0(100 * model2.getT0())
assert model1.getT0() != model2.getT0()
14 changes: 13 additions & 1 deletion swig/model.i
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,22 @@ using namespace amici;
%ignore fdx_rdatadx_solver;
%ignore fdsigmaydy;

%newobject amici::Model::clone;

%extend amici::Model {
%pythoncode %{
def __deepcopy__(self, memo):
return self.clone()
%}
};

%extend std::unique_ptr<amici::Model> {
%pythoncode %{
def __deepcopy__(self, memo):
return self.clone()
%}
};

%newobject amici::Model::clone;

// Process symbols in header
%include "amici/model.h"

0 comments on commit 637f884

Please sign in to comment.