Skip to content

Commit

Permalink
Add test to guard for refcounting error (#42)
Browse files Browse the repository at this point in the history
* Add test to guard for refcounting error

* tweak test levels

* fix sign

* update AnyODE

* update anyode, avoid increase in None refcount
  • Loading branch information
bjodah authored Apr 26, 2024
1 parent edcf609 commit a3d29d2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .woodpecker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ when:

steps:
- name: build-and-test
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:14 #bjodahimg20dev:v1.1.0
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16 #bjodahimg20dev:v1.1.0
environment:
- PYTHONMALLOC=malloc
commands:
Expand Down
4 changes: 2 additions & 2 deletions pyodeint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def get_include():


def _bs(kwargs):
# DEPRECATED accept 'bs' as short for 'bulirsh_stoer'
# DEPRECATED accept 'bs' as short for 'bulirsch_stoer'
if kwargs.get('method', '-') == 'bs':
warnings.warn('Using method="bs" is depreacted, use "bulirsh_stoer" instead.', DeprecationWarning)
warnings.warn('Using method="bs" is depreacted, use "bulirsch_stoer" instead.', DeprecationWarning)
kwargs['method'] = 'bulirsch_stoer'
return kwargs

Expand Down
26 changes: 22 additions & 4 deletions pyodeint/tests/test_odeint_numpy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# -*- coding: utf-8 -*-
import gc
import os
import sys
import numpy as np
import pytest

from pyodeint import integrate_adaptive, integrate_predefined

def _get_refcount_None():
if hasattr(sys, 'getrefcount'):
gc.collect()
gc.collect()
return sys.getrefcount(None)
else: # e.g. pypy
return 0


decay_analytic = {
0: lambda y0, k, t: (
Expand Down Expand Up @@ -53,7 +63,7 @@ def j(t, y, jmat_out, dfdx_out):

methods = [
('dopri5', False),
('bs', False),
('bulirsch_stoer', False),
# rosenbrock4 suffered a massive performance regression:
# - https://github.com/headmyshoulder/odeint-v2/issues/189
# - https://github.com/bjodah/pyodeint/pull/16
Expand All @@ -70,9 +80,17 @@ def test_integrate_adaptive(method, use_jac):
if not use_jac:
j = None
kwargs = dict(x0=0, xend=3, dx0=1e-10, atol=1e-8, rtol=1e-8, method=method)
# Run twice to catch possible side-effects:
xout, yout, info = integrate_adaptive(f, j, y0, **kwargs)
xout, yout, info = integrate_adaptive(f, j, y0, **kwargs)
# Run multiple times to catch possible side-effects:
nIter = 100
for ii in range(nIter):
if ii == 1:
nNone1 = _get_refcount_None()
xout, yout, info = integrate_adaptive(f, j, y0, **kwargs)
gc.collect()
nNone2 = _get_refcount_None()
delta = nNone2 - nNone1
assert -nIter//10 < delta < nIter//10

assert info['success']
assert info['atol'] == 1e-8 and info['rtol'] == 1e-8
assert info['nfev'] > 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ source /opt-3/cpython-v3.11-apt-deb/bin/activate

python3 setup.py sdist
CC=gcc CXX=g++ python3 -m pip install --ignore-installed dist/*.tar.gz
(cd /; python3 -m pytest --pyargs $PKG_NAME)
(cd /; python3 -m pytest --pyargs $PKG_NAME -v)
CC=gcc CXX=g++ python3 -m pip install -e .[all]
python3 -m pip install pytest-cov pytest-flakes matplotlib sphinx numpydoc sphinx_rtd_theme
PYTHONPATH=$(pwd) PYTHON=python3 ./scripts/run_tests.sh --cov $PKG_NAME --cov-report html
Expand Down

0 comments on commit a3d29d2

Please sign in to comment.