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

FIX: allow for print_level greater than 1 and ENH: allow warm start for dual variables #239

Closed
wants to merge 10 commits into from
29 changes: 25 additions & 4 deletions cyipopt/scipy_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ def _wrap_funs(fun, jac, hess, hessp, constraints, kwargs):

def minimize_ipopt(fun,
x0,
mult_g=[],
mult_x_L=[],
mult_x_U=[],
zhengzl18 marked this conversation as resolved.
Show resolved Hide resolved
args=(),
kwargs=None,
method=None,
Expand Down Expand Up @@ -426,6 +429,16 @@ def minimize_ipopt(fun,
x0 : array-like, shape(n, )
Initial guess. Array of real elements of shape (n,),
where ``n`` is the number of independent variables.
mult_g : list, optional
Initial guess for the Lagrange multipliers of the constraints. A list
of real elements of length ``m``, where ``m`` is the number of
constraints.
mult_x_L : list, optional
Initial guess for the Lagrange multipliers of the lower bounds on the
variables. A list of real elements of length ``n``.
mult_x_U : list, optional
Initial guess for the Lagrange multipliers of the upper bounds on the
variables. A list of real elements of length ``n``.
args : tuple, optional
Extra arguments passed to the objective function and its
derivatives (``fun``, ``jac``, and ``hess``).
Expand Down Expand Up @@ -582,9 +595,7 @@ def minimize_ipopt(fun,
# Rename some default scipy options
replace_option(options, b'disp', b'print_level')
replace_option(options, b'maxiter', b'max_iter')
if getattr(options, 'print_level', False) is True:
options[b'print_level'] = 1
else:
if b'print_level' not in options:
options[b'print_level'] = 0
if b'tol' not in options:
options[b'tol'] = tol or 1e-8
Expand All @@ -600,7 +611,17 @@ def minimize_ipopt(fun,
msg = 'Invalid option for IPOPT: {0}: {1} (Original message: "{2}")'
raise TypeError(msg.format(option, value, e))

x, info = nlp.solve(x0)
if len(mult_g) > 0 and len(mult_g) != len(cl):
raise ValueError('`mult_g` must be empty or have length `m`, '
'where `m` is the number of constraints.')
if len(mult_x_L) > 0 and len(mult_x_L) != len(lb):
raise ValueError('`mult_x_L` must be empty or have length `n`, '
'where `n` is the number of decision variables.')
if len(mult_x_U) > 0 and len(mult_x_U) != len(ub):
raise ValueError('`mult_x_U` must be empty or have length `n`, '
'where `n` is the number of decision variables.')

x, info = nlp.solve(x0, lagrange=mult_g, zl=mult_x_L, zu=mult_x_U)

return OptimizeResult(x=x,
success=info['status'] == 0,
Expand Down
Loading