Description
Seeing test_fitting_with_initial_values[DogBoxLSQFitter] fail with numpy 1.26.0 installed from MambaForge/Miniforge3 on an M1 Mac.
Expected behavior
Fit should converge for the given values in the test.
How to Reproduce
- Get Astropy including test deps from mamba as
mamba install --update-all astropy asdf-astropy graphviz h5py matplotlib ndcube pytest-astropy pytest-cov scipy spectral-cube
1a. For testing with the release candidates update Astropy via pip install --upgrade 'astropy==6.0.0rc2'
2. Then run import astropy; astropy.test(package='modeling')
3. An error occurs.
______________________________________________________ test_fitting_with_initial_values[DogBoxLSQFitter] _______________________________________________________
fitter = <astropy.modeling.fitting.DogBoxLSQFitter object at 0x14efc3d00>
@pytest.mark.skipif(not HAS_SCIPY, reason="requires scipy")
@pytest.mark.parametrize("fitter", fitters)
def test_fitting_with_initial_values(fitter):
fitter = fitter()
x, y = _fake_gaussian_data()
# Fit the data using a Gaussian with units
g_init = models.Gaussian1D(amplitude=1.0 * u.mJy, mean=3 * u.cm, stddev=2 * u.mm)
> g = fitter(g_init, x, y)
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/astropy/modeling/tests/test_quantities_fitting.py:113:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/astropy/modeling/fitting.py:285: in wrapper
model_new = func(self, model, xdata, ydata, **kwargs)
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/astropy/modeling/fitting.py:1365: in __call__
init_values, fitparams, cov_x = self._run_fitter(
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/astropy/modeling/fitting.py:1524: in _run_fitter
self.fit_info = optimize.least_squares(
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/scipy/optimize/_lsq/least_squares.py:949: in least_squares
result = dogbox(fun_wrapped, jac_wrapped, x0, f0, J0, lb, ub, ftol,
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/scipy/optimize/_lsq/dogbox.py:266: in dogbox
f_new = fun(x_new)
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/scipy/optimize/_lsq/least_squares.py:828: in fun_wrapped
return np.atleast_1d(fun(x, *args, **kwargs))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.modeling.fitting.DogBoxLSQFitter object at 0x14efc3d00>, fps = array([nan, nan, nan])
args = (<Gaussian1D(amplitude=nan, mean=nan, stddev=nan)>, None, array([-500. , -499.49974987, -498.99949975, ..., 49...87, 500. ]), array([-0.04094153, 0.09578867, -0.10388774, ..., -0.04841979,
-0.611328 , 0.38374856]))
model = <Gaussian1D(amplitude=nan, mean=nan, stddev=nan)>, weights = None
meas = array([-0.04094153, 0.09578867, -0.10388774, ..., -0.04841979,
-0.611328 , 0.38374856])
def objective_function(self, fps, *args):
"""
Function to minimize.
Parameters
----------
fps : list
parameters returned by the fitter
args : list
[model, [weights], [input coordinates]]
"""
model = args[0]
weights = args[1]
fitter_to_model_params(model, fps, self._use_min_max_bounds)
meas = args[-1]
if weights is None:
value = np.ravel(model(*args[2:-1]) - meas)
else:
value = np.ravel(weights * (model(*args[2:-1]) - meas))
if not np.all(np.isfinite(value)):
> raise NonFiniteValueError(
"Objective function has encountered a non-finite value, "
"this will cause the fit to fail!\n"
"Please remove non-finite values from your input data before "
"fitting to avoid this error."
)
E astropy.modeling.fitting.NonFiniteValueError: Objective function has encountered a non-finite value, this will cause the fit to fail!
E Please remove non-finite values from your input data before fitting to avoid this error.
../../../opt/miniforge/envs/pip312/lib/python3.12/site-packages/astropy/modeling/fitting.py:1141: NonFiniteValueError
--------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
** On entry to DLASCL parameter number 4 had an illegal value
** On entry to DLASCL parameter number 4 had an illegal value
** On entry to DLASCL parameter number 4 had an illegal value
Happens on Python 3.10-3.12 with Astropy 5.3.4, 6.0.0rc1 and 6.0.0rc2 whenever numpy is installed via mamba/conda/miniforge, which installs this openblas:
~/opt/miniforge/envs/pip312/lib/libopenblas.0.dylib:
@rpath/libopenblas.0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libgfortran.5.dylib (compatibility version 6.0.0, current version 6.0.0)
@rpath/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0)
The fit converges when using pip-installed numpy 1.26.0 or 1.26.2 (pip install --force-reinstall numpy), which is linking against
~/opt/miniforge/envs/pip31/lib/python3.12/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
as well when linking against my own build of OpenBLAS 0.3.25. Tests also pass with all versions on Intel Mac.
So likely this is a precision limit in the arm64 OpenBLAS 0.3.24 packaged with miniforge, though the test may be pushing the limits as well.
Versions
macOS-12.7-arm64-arm-64bit
Python 3.12.0 | packaged by conda-forge | (main, Oct 26 2023, 18:09:17) [Clang 16.0.6 ]
astropy 6.0.0rc2
Numpy 1.26.0
pyerfa 2.0.1.1
Scipy 1.11.3
Matplotlib 3.8.1
Description
Seeing
test_fitting_with_initial_values[DogBoxLSQFitter]fail with numpy 1.26.0 installed from MambaForge/Miniforge3 on an M1 Mac.Expected behavior
Fit should converge for the given values in the test.
How to Reproduce
1a. For testing with the release candidates update Astropy via
pip install --upgrade 'astropy==6.0.0rc2'2. Then run
import astropy; astropy.test(package='modeling')3. An error occurs.
Happens on Python 3.10-3.12 with Astropy 5.3.4, 6.0.0rc1 and 6.0.0rc2 whenever numpy is installed via mamba/conda/miniforge, which installs this openblas:
The fit converges when using pip-installed numpy 1.26.0 or 1.26.2 (
pip install --force-reinstall numpy), which is linking againstas well when linking against my own build of OpenBLAS 0.3.25. Tests also pass with all versions on Intel Mac.
So likely this is a precision limit in the arm64 OpenBLAS 0.3.24 packaged with miniforge, though the test may be pushing the limits as well.
Versions