Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Model, ModelPtr deepcopyable #2247

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"