Skip to content

Commit

Permalink
Make Model, ModelPtr deepcopyable (#2247)
Browse files Browse the repository at this point in the history
* Make Model, ModelPtr deepcopyable
  • Loading branch information
dweindl authored Jan 2, 2024
1 parent 0cc43f9 commit e5cf148
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions python/tests/test_swig_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,16 @@ def test_solvers_are_deepcopyable():
solver1.getRelativeTolerance()
!= solver2.getRelativeTolerance()
)


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.t0() == model2.t0()
model2.setT0(100 + model2.t0())
assert model1.t0() != model2.t0()
1 change: 1 addition & 0 deletions swig/amici.i
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ nonstandard type conversions.

// typemaps for docstrings
%typemap(doctype) std::unique_ptr< amici::ExpData >::pointer "ExpData";
%typemap(doctype) std::unique_ptr< amici::Model > "ModelPtr";
%typemap(doctype) std::unique_ptr< amici::Solver > "SolverPtr";
%typemap(doctype) std::vector< amici::realtype,std::allocator< amici::realtype > > "DoubleVector";
%typemap(doctype) std::vector< double,std::allocator< double > > "DoubleVector";
Expand Down
15 changes: 13 additions & 2 deletions swig/model.i
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,21 @@ using namespace amici;
%ignore fdx_rdatadx_solver;
%ignore fdsigmaydy;

%newobject amici::Model::clone;

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


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

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

0 comments on commit e5cf148

Please sign in to comment.