Regression in scipy.optimize when upper-bound = lower-bound to fix a parameter
See original GitHub issueDear Scipy team,
I am the maintainer of a pyFAI and got a bug report that a feature in my code stopped working: https://github.com/silx-kit/pyFAI/issues/1421 On my side the bug comes down to the call to scipy.optimize.fmin_slsqp here: https://github.com/silx-kit/pyFAI/blob/master/pyFAI/geometryRefinement.py#L361
The regression was introduced in scipy v1.5 an now I got a warning with:
WARNING:py.warnings:/opt/VirtualEnv/py38/lib/python3.8/site-packages/scipy/optimize/_numdiff.py:519: RuntimeWarning: invalid value encountered in true_divide
J_transposed[i] = df / dx
and of course the optimization did not work.
Until now my code was offering to the use to “fix” some parameter during the optimization, which helps the optimizer to converge faster to the solution. To “fix” the parameter, I was enforcing both bounds to be equal to the fixed value but since the approx_jacobian in slsqp.py changed to call approx_derivative no more optimization occures.
Reproducing code example:
If I already know the first parameter should be close to 1 and I want to fix it:
>>> f = lambda x:(x[0]-1)**2*(x[1]-3)**2 # solution expected to be (1,3)
>>> scipy.optimize.fmin_slsqp(f, [1,1], bounds=[(1,1), (None, None)])
/opt/VirtualEnv/py38/lib/python3.8/site-packages/scipy/optimize/_numdiff.py:519: RuntimeWarning: invalid value encountered in true_divide
J_transposed[i] = df / dx
Inequality constraints incompatible (Exit mode 4)
Current function value: 0.0
Iterations: 1
Function evaluations: 3
Gradient evaluations: 1
Out[8]: array([1., 1.])
Error message:
There was not exception
Scipy/Numpy/Python version information:
Python: 3.8.0 Numpy: 1.18.4 Scipy: 1.5.0 - 1.5.3
You may consider I have been misusing this feature … but the I need to implement a work around on my side.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
This is a duplicate of #12502, and should be fixed by#12889. Are you able to verify that the modifications made in the latter fix the issue for you?
Closed as duplicate