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

MAINT: minimize_ipopt: fix late binding bug when defining constraint Jacobians #208

Merged
merged 1 commit into from
May 20, 2023

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented May 20, 2023

As reported in #194 (comment), minimize_ipopt fails on the scipy.optimize.minimize example with three constraints. This is due to a late binding gotcha when the constraint Jacobians are defined in a loop. This fixes that bug and demonstrates that the example problem is solved successfully after the fix.

Try me before and after.
from cyipopt import minimize_ipopt

fun = lambda x: (x[0] - 1)**2 + (x[1] - 2.5)**2
cons = ({'type': 'ineq', 'fun': lambda x:  x[0] - 2 * x[1] + 2},
        {'type': 'ineq', 'fun': lambda x: -x[0] - 2 * x[1] + 6},
        {'type': 'ineq', 'fun': lambda x: -x[0] + 2 * x[1] + 2})
bnds = ((0, None), (0, None))

res = minimize_ipopt(fun, (2, 0), bounds=bnds, constraints=cons)

Incidentally, this also fixes an unreported bug: kwargs was being passed to approx_fprime. but approx_fprime doesn't accept kwargs. Another instance of this bug is fixed in https://github.com/mechmotum/cyipopt/pull/200/files#r1198383113.

@mdhaber mdhaber changed the title MAINT: minimize_ipopt: fix late binding bug MAINT: minimize_ipopt: fix late binding bug when defining constraint Jacobians May 20, 2023
@moorepants
Copy link
Collaborator

LGTM

@moorepants moorepants merged commit 0157f2f into mechmotum:master May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants