Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: constraint function is overwritten when equal bounds are used in SLSQP #14859

Closed
andyfaff opened this issue Oct 15, 2021 · 2 comments · Fixed by #14860
Closed

BUG: constraint function is overwritten when equal bounds are used in SLSQP #14859

andyfaff opened this issue Oct 15, 2021 · 2 comments · Fixed by #14860
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Milestone

Comments

@andyfaff
Copy link
Contributor

Describe your issue.

@mdhaber, just after I merged #13096 I realised that the constraints functions are replaced in the user supplied list. This is not a good idea, as we're overwriting user information. I'll make a fix now.

Reproducing Code Example

import numpy as np
from scipy.optimize import minimize

def f (x):
    return x[0]**3 + x[1]**2 + x[2]*x[3]

cfun = lambda x : x[0] + x[1] + x[2] + x[3] - 40

constraints = [{
    'type'  : 'ineq',
    'fun'   : cfun
}]

bounds = [(0, 20)] * 4
bounds[1] = (5, 5)
res_A = minimize (
    f,
    x0          = [1, 2, 3, 4],
    method      = 'SLSQP',
    bounds      = bounds,
    constraints = constraints,
)

assert constraints[0]['fun'] == cfun

Error message

-

SciPy/NumPy/Python version information

Master

@andyfaff andyfaff added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Oct 15, 2021
@andyfaff andyfaff changed the title BUG: BUG: constraint function is overwritten when equal bounds are used in SLSQP Oct 15, 2021
@mdhaber
Copy link
Contributor

mdhaber commented Oct 15, 2021

I see. Good call.

@andyfaff
Copy link
Contributor Author

I think there's another issue, when all parameters have equal bounds, but I'll get to that soon.

andyfaff added a commit that referenced this issue Oct 15, 2021
minimize: copy user constraints if parameter is factored out. Closes #14859
@tylerjereddy tylerjereddy added this to the 1.8.0 milestone Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants