Skip to content

Commit

Permalink
TST: fixes for SciPy 1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
reneeotten committed Jun 24, 2021
1 parent 3a032b4 commit 9cb4056
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 8 additions & 2 deletions tests/test_ampgo.py
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from numpy.testing import assert_allclose
import pytest
from scipy import __version__ as scipy_version

import lmfit
from lmfit._ampgo import ampgo, tunnel
Expand Down Expand Up @@ -60,8 +61,13 @@ def test_ampgo_local_solver(minimizer_Alpine02):
"""Test AMPGO algorithm with local solver."""
kws = {'local': 'Nelder-Mead'}

msg = r'Method Nelder-Mead cannot handle constraints nor bounds'
with pytest.warns(RuntimeWarning, match=msg):
# bounds in Nelder-Mead are supported since SciPy v1.7.0
# FIXME: clean this up after we require SciPy >= 1.7.0
if int(scipy_version.split('.')[1]) < 7:
msg = r'Method Nelder-Mead cannot handle constraints nor bounds'
with pytest.warns(RuntimeWarning, match=msg):
out = minimizer_Alpine02.minimize(method='ampgo', **kws)
else:
out = minimizer_Alpine02.minimize(method='ampgo', **kws)

out_x = np.array([out.params['x0'].value, out.params['x1'].value])
Expand Down
17 changes: 15 additions & 2 deletions tests/test_shgo.py
Expand Up @@ -4,6 +4,7 @@
from numpy.testing import assert_allclose
import pytest
import scipy
from scipy import __version__ as scipy_version

import lmfit

Expand All @@ -29,7 +30,13 @@ def test_shgo_scipy_vs_lmfit():
bounds = [(-512, 512), (-512, 512)]
result_scipy = scipy.optimize.shgo(eggholder, bounds, n=30,
sampling_method='sobol')
assert len(result_scipy.xl) == 13

# in SciPy v1.7.0: "sobol was fixed and is now using scipy.stats.qmc.Sobol"
# FIXME: clean this up after we require SciPy >= 1.7.0
if int(scipy_version.split('.')[1]) < 7:
assert len(result_scipy.xl) == 13
else:
assert len(result_scipy.xl) == 6

pars = lmfit.Parameters()
pars.add_many(('x0', 0, True, -512, 512), ('x1', 0, True, -512, 512))
Expand All @@ -48,7 +55,13 @@ def test_shgo_scipy_vs_lmfit_2():
bounds = [(-512, 512), (-512, 512)]
result_scipy = scipy.optimize.shgo(eggholder, bounds, n=60, iters=5,
sampling_method='sobol')
assert len(result_scipy.xl) == 39

# in SciPy v1.7.0: "sobol was fixed and is now using scipy.stats.qmc.Sobol"
# FIXME: clean this up after we require SciPy >= 1.7.0
if int(scipy_version.split('.')[1]) < 7:
assert len(result_scipy.xl) == 39
else:
assert len(result_scipy.xl) == 74

pars = lmfit.Parameters()
pars.add_many(('x0', 0, True, -512, 512), ('x1', 0, True, -512, 512))
Expand Down

0 comments on commit 9cb4056

Please sign in to comment.