Skip to content

Commit

Permalink
Merge branch 'develop' into swigptr_props
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Dec 18, 2023
2 parents cd18a22 + ba4f856 commit 4bd8c80
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-22.04, macos-latest]

runs-on: ${{ matrix.os }}
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/test_python_ver_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
experimental: [false]

steps:
Expand All @@ -44,15 +44,27 @@ jobs:
- name: Install apt dependencies
uses: ./.github/actions/install-apt-dependencies

# install AMICI
- name: Build BNGL
run: scripts/buildBNGL.sh

- name: Install python package
run: scripts/installAmiciSource.sh

# until https://github.com/dateutil/dateutil >2.8.2 is released https://github.com/dateutil/dateutil/issues/1314
- run: source build/venv/bin/activate && pip3 install git+https://github.com/dateutil/dateutil.git@296d419fe6bf3b22897f8f210735ac9c4e1cb796
if: matrix.python-version == '3.12'

# install pysb before sympy to allow for sympy>=1.12 (https://github.com/pysb/pysb/commit/e83937cb8c74afc9b2fa96595b68464946745f33)
- run: source build/venv/bin/activate && pip3 install git+https://github.com/pysb/pysb

# until sympy>1.12 is released
- run: source build/venv/bin/activate && pip3 install git+https://github.com/sympy/sympy.git@master
if: matrix.python-version == '3.12'

- name: Python tests
run: |
source build/venv/bin/activate \
&& pip3 install git+https://github.com/pysb/pysb \
&& python3 -m pytest --ignore-glob=*petab* \
&& python3 -m pytest \
--durations=10 \
--ignore-glob=*petab* \
--ignore-glob=*test_splines.py ${AMICI_DIR}/python/tests
24 changes: 16 additions & 8 deletions python/sdist/amici/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ def _setup_logger(
level: Optional[int] = logging.WARNING,
console_output: Optional[bool] = True,
file_output: Optional[bool] = False,
capture_warnings: Optional[bool] = True,
capture_warnings: Optional[bool] = False,
) -> logging.Logger:
"""
Set up a new logging.Logger for AMICI logging
Set up a new :class:`logging.Logger` for AMICI logging.
:param level:
Logging level, typically using a constant like logging.INFO or
logging.DEBUG
Logging level, typically using a constant like :obj:`logging.INFO` or
:obj:`logging.DEBUG`
:param console_output:
Set up a default console log handler if True (default)
Set up a default console log handler if ``True`` (default)
:param file_output:
Supply a filename to copy all log output to that file, or
set to False to disable (default)
set to ``False`` to disable (default)
:param capture_warnings:
Capture warnings from Python's warnings module if True (default)
Capture warnings from Python's warnings module if ``True``
:return:
A :class:`logging.Logger` object for AMICI logging. Note that other
Expand Down Expand Up @@ -81,7 +81,12 @@ def _setup_logger(

log.setLevel(level)

py_warn_logger = logging.getLogger("py.warnings")

# Remove default logging handler
for handler in log.handlers:
if handler in py_warn_logger.handlers:
py_warn_logger.removeHandler(handler)
log.handlers = []

log_fmt = logging.Formatter(
Expand All @@ -105,7 +110,10 @@ def _setup_logger(
log.debug("Python version: %s", platform.python_version())
log.debug("Hostname: %s", socket.getfqdn())

logging.captureWarnings(capture_warnings)
if capture_warnings:
logging.captureWarnings(capture_warnings)
for handler in log.handlers:
py_warn_logger.addHandler(handler)

return log

Expand Down
8 changes: 5 additions & 3 deletions python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,15 +2776,17 @@ def replace_logx(math_str: Union[str, float, None]) -> Union[str, float, None]:
return re.sub(r"(^|\W)log(\d+)\(", r"\g<1>1/ln(\2)*ln(", math_str)


def _collect_event_assignment_parameter_targets(sbml_model: sbml.Model):
targets = set()
def _collect_event_assignment_parameter_targets(
sbml_model: sbml.Model,
) -> list[sp.Symbol]:
targets = []
sbml_parameters = sbml_model.getListOfParameters()
sbml_parameter_ids = [p.getId() for p in sbml_parameters]
for event in sbml_model.getListOfEvents():
for event_assignment in event.getListOfEventAssignments():
target_id = event_assignment.getVariable()
if target_id in sbml_parameter_ids:
targets.add(
targets.append(
_get_identifier_symbol(
sbml_parameters[sbml_parameter_ids.index(target_id)]
)
Expand Down
16 changes: 16 additions & 0 deletions python/tests/test_swig_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,19 @@ 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):
for solver1 in (solver_type(), amici.SolverPtr(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()
)
9 changes: 9 additions & 0 deletions swig/solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,18 @@ def __repr__(self):
%pythoncode %{
def __repr__(self):
return _solver_repr(self)

def __deepcopy__(self, memo):
return self.clone()
%}
};

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

%newobject amici::Solver::clone;
// Process symbols in header
Expand Down
3 changes: 3 additions & 0 deletions swig/std_unique_ptr.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ namespace std {
struct unique_ptr {
typedef Type* pointer;

%apply SWIGTYPE *DISOWN { pointer Ptr };
explicit unique_ptr( pointer Ptr );
%clear pointer Ptr;
unique_ptr (unique_ptr&& Right);

template<class Type2, Class Del2> unique_ptr( unique_ptr<Type2, Del2>&& Right );
unique_ptr( const unique_ptr& Right) = delete;

Expand Down

0 comments on commit 4bd8c80

Please sign in to comment.