Skip to content

Commit

Permalink
BLD: increase minimum supported NumPy/SciPy versions to 1.23 and 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
reneeotten committed Nov 18, 2023
1 parent ea10c38 commit 14af97b
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 57 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ stages:
displayName: 'Install dependencies'
- script: |
python -m pip install --upgrade build pip wheel
python -m pip install asteval==0.9.28 numpy==1.19.0 scipy==1.6.0 uncertainties==3.1.4
python -m pip install asteval==0.9.28 numpy==1.23.0 scipy==1.8.0 uncertainties==3.1.4
displayName: 'Install minimum required version of dependencies'
- script: |
python -m build
Expand Down
4 changes: 2 additions & 2 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Lmfit works with `Python`_ versions 3.8 and higher. Version
0.9.15 is the final version to support Python 2.7.

Lmfit requires the following Python packages, with versions given:
* `NumPy`_ version 1.19 or higher.
* `SciPy`_ version 1.6 or higher.
* `NumPy`_ version 1.23 or higher.
* `SciPy`_ version 1.8 or higher.
* `asteval`_ version 0.9.28 or higher.
* `uncertainties`_ version 3.1.4 or higher.

Expand Down
28 changes: 7 additions & 21 deletions lmfit/minimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import warnings

import numpy as np
from scipy import __version__ as scipy_version
from scipy.linalg import LinAlgError, inv
from scipy.optimize import basinhopping as scipy_basinhopping
from scipy.optimize import brute as scipy_brute
Expand Down Expand Up @@ -1735,12 +1734,8 @@ def basinhopping(self, params=None, max_nfev=None, **kws):
basinhopping_kws = dict(niter=100, T=1.0, stepsize=0.5,
minimizer_kwargs=None, take_step=None,
accept_test=None, callback=None, interval=50,
disp=False, niter_success=None, seed=None)

# FIXME: update when SciPy requirement is >= 1.8
if int(scipy_version.split('.')[1]) >= 8:
basinhopping_kws.update({'target_accept_rate': 0.5,
'stepwise_factor': 0.9})
disp=False, niter_success=None, seed=None,
target_accept_rate=0.5, stepwise_factor=0.9)

basinhopping_kws.update(self.kws)
basinhopping_kws.update(kws)
Expand Down Expand Up @@ -2118,14 +2113,10 @@ def shgo(self, params=None, max_nfev=None, **kws):

self.set_max_nfev(max_nfev, 200000*(result.nvarys+1))

shgo_kws = dict(constraints=None, n=100, iters=1, callback=None,
shgo_kws = dict(constraints=None, n=None, iters=1, callback=None,
minimizer_kwargs=None, options=None,
sampling_method='simplicial')

# FIXME: update when SciPy requirement is >= 1.7
if int(scipy_version.split('.')[1]) >= 7:
shgo_kws['n'] = None

shgo_kws.update(self.kws)
shgo_kws.update(kws)

Expand Down Expand Up @@ -2196,19 +2187,14 @@ def dual_annealing(self, params=None, max_nfev=None, **kws):
result.method = 'dual_annealing'
self.set_max_nfev(max_nfev, 200000*(result.nvarys+1))

da_kws = dict(maxiter=1000, local_search_options={},
initial_temp=5230.0, restart_temp_ratio=2e-05,
visit=2.62, accept=-5.0, maxfun=2*self.max_nfev,
seed=None, no_local_search=False, callback=None, x0=None)
da_kws = dict(maxiter=1000, minimizer_kwargs=None, initial_temp=5230.0,
restart_temp_ratio=2e-05, visit=2.62, accept=-5.0,
maxfun=2*self.max_nfev, seed=None, no_local_search=False,
callback=None, x0=None)

da_kws.update(self.kws)
da_kws.update(kws)

# FIXME: update when SciPy requirement is >= 1.8
# ``local_search_options`` deprecated in favor of ``minimizer_kwargs``
if int(scipy_version.split('.')[1]) >= 8:
da_kws.update({'minimizer_kwargs': da_kws.pop('local_search_options')})

varying = np.asarray([par.vary for par in self.params.values()])
bounds = np.asarray([(par.min, par.max) for par in
self.params.values()])[varying]
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ python_requires = >=3.8
setup_requires = setuptools_scm
install_requires =
asteval>=0.9.28
numpy>=1.19
scipy>=1.6
numpy>=1.23
scipy>=1.8
uncertainties>=3.1.4

[options.packages.find]
Expand Down
11 changes: 1 addition & 10 deletions tests/test_ampgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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,15 +59,7 @@ def test_ampgo_local_solver(minimizer_Alpine02):
"""Test AMPGO algorithm with local solver."""
kws = {'local': 'Nelder-Mead'}

# 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 = minimizer_Alpine02.minimize(method='ampgo', **kws)
out_x = np.array([out.params['x0'].value, out.params['x1'].value])

assert 'ampgo' and 'Nelder-Mead' in out.method
Expand Down
6 changes: 0 additions & 6 deletions tests/test_basinhopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
from numpy.testing import assert_allclose
import pytest
from scipy import __version__ as scipy_version
from scipy.optimize import basinhopping

import lmfit
Expand Down Expand Up @@ -62,11 +61,6 @@ def residual_2d(params):
assert_allclose(out.params['x0'].value, ret.x[0], rtol=1e-5)
assert_allclose(out.params['x1'].value, ret.x[1], rtol=1e-5)

# FIXME: update when SciPy requirement is >= 1.8
if int(scipy_version.split('.')[1]) >= 8:
assert 'target_accept_rate' in out.call_kws
assert 'stepwise_factor' in out.call_kws


def test_basinhopping_Alpine02(minimizer_Alpine02):
"""Test basinhopping on Alpine02 function."""
Expand Down
8 changes: 0 additions & 8 deletions tests/test_dual_annealing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
from numpy.testing import assert_allclose
import scipy
from scipy import __version__ as scipy_version

import lmfit

Expand Down Expand Up @@ -54,13 +53,6 @@ def test_da_Alpine02(minimizer_Alpine02):
assert_allclose(max(out_x), max(global_optimum), rtol=1e-3)
assert out.method == 'dual_annealing'

# FIXME: update when SciPy requirement is >= 1.8
# ``local_search_options`` deprecated in favor of ``minimizer_kwargs``
if int(scipy_version.split('.')[1]) >= 8:
assert 'minimizer_kwargs' in out.call_kws
else:
assert 'local_search_options' in out.call_kws


def test_da_bounds(minimizer_Alpine02):
"""Test dual_annealing algorithm with bounds."""
Expand Down
7 changes: 0 additions & 7 deletions tests/test_shgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from numpy.testing import assert_allclose
import pytest
import scipy
from scipy import __version__ as scipy_version

import lmfit

Expand Down Expand Up @@ -82,12 +81,6 @@ def test_shgo_sobol_Alpine02(minimizer_Alpine02):
assert_allclose(min(out_x), min(global_optimum), rtol=1e-3)
assert_allclose(max(out_x), max(global_optimum), rtol=1e-3)

# FIXME: update when SciPy requirement is >= 1.7
if int(scipy_version.split('.')[1]) >= 7:
assert out.call_kws['n'] is None
else:
assert out.call_kws['n'] == 100


def test_shgo_bounds(minimizer_Alpine02):
"""Test SHGO algorithm with bounds."""
Expand Down

0 comments on commit 14af97b

Please sign in to comment.