BUG: optimize.minimize backwards compatability in scipy 1.9
See original GitHub issueDescribe your issue.
Hi, we have some code that works with scipy 1.8 but crashes 1.9. An example to reproduce is below. The issue arises in the code than transforms between the new/old bounds definition, but is actually related to the way x0 is defined.
You can ‘fix’ this by changing start
to start = np.array([0.0])
. We can actually do this in our code too, but I wanted to check if this behavior is intentional or whether this lack of backward compatibility constitutes a bug?
Reproducing Code Example
'''
example which will run on scipy 1.8 but not scipy 1.9
'''
from scipy.optimize import minimize
import numpy as np
def objective(x):
return(x+10)**2
bounds = np.array([[-20, 20]])
start = np.array([0.0]).reshape(-1, 1)
res = minimize(objective, start, bounds=bounds, method="L-BFGS-B")
Error message
TypeError: object of type 'Bounds' has no len()
SciPy/NumPy/Python version information
1.8/1.9
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
SciPy 1.9.0 Release Notes — SciPy v1.9.3 Manual
Our development attention will now shift to bug-fix releases on the 1.9.x ... the output Laplacian: * array is a numpy array (backward...
Read more >SciPy: doc/release/1.2.0-notes.rst - Fossies
The one-dimensional nonlinear solvers have been given a unified interface scipy.optimize.root_scalar, similar to the scipy.optimize.root interface for multi- ...
Read more >scipy/scipy: SciPy 1.9.0rc1 | Zenodo
Add a full_output parameter to scipy.optimize.curve_fit to output ... format of the output Laplacian: array is a numpy array (backward compatible default); ...
Read more >Mailman 3 ANN: SciPy 1.9.0 - NumPy-Discussion - python.org
It contains many new features, numerous bug-fixes, improved test coverage and better documentation. There have been a number of deprecations and API changes...
Read more >SciPy 0.15.0 Release Notes — SciPy v1.0.0 Reference Guide
optimize.minimize provides a generic interface to nonlinear programming optimizers. Currently the only method supported is simplex which ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
At the start of
minimize
this code is called:Because there is more than one dimension in
start
the array is squeezed. We do this squeeze becauseminimize
is only designed to work with 1D arrays (problems are experienced with ndim > 1). You should’ve seen thisDeprecationWarning
when you ran your code. When the code squeezesnp.array([[0.0]])
you end up withnp.array(0.0)
, which has shape()
. Whenx0.shape[0]
is requested anIndexError
is raised,IndexError: tuple index out of range
. I get a different error than you see.We could fix scipy to make it back compatible by doing
x0 = np.atleast_1d(np.squeeze(x0))
. However, as you can see from the code snippet above we’re going to raise an Error ifx0.ndim > 1
in scipy 1.11. This probably makes it less important to make a ‘fix’ in scipy; can you fix the downstream code here?Hmm I do think this was an unintentional mistake on our part to remove all the dimensions, so from that perspective, yes. We might be able to get it in 1.9.1. I can’t push the buttons, but I can review quickly if it’s the one-liner you described, @andyfaff.