Reference

This is the class and function reference of cyipopt. Please refer to the tutorial for further details, as the class and function raw specifications may not be enough to give full guidelines on their uses.

class cyipopt.Problem

Wrapper class for solving optimization problems using the C interface of the Ipopt package.

It can be used to solve general nonlinear programming problems of the form:

\[\min_ {x \in R^n} f(x)\]

subject to

\[ \begin{align}\begin{aligned}g_L \leq g(x) \leq g_U\\x_L \leq x \leq x_U\end{aligned}\end{align} \]

Where \(x\) are the optimization variables (possibly with upper an lower bounds), \(f(x)\) is the objective function and \(g(x)\) are the general nonlinear constraints. The constraints, \(g(x)\), have lower and upper bounds. Note that equality constraints can be specified by setting \(g^i_L = g^i_U\).

Parameters
  • n (integer) – Number of primal variables.

  • m (integer) – Number of constraints.

  • problem_obj (object, optional (default=None)) –

    An object holding the problem’s callbacks. If None, cyipopt will use self, this is useful when subclassing Problem. The object is required to have the following attributes and methods (some are optional):

    • objectivefunction pointer

      Callback function for evaluating objective function. The callback functions accepts one parameter: x (value of the optimization variables at which the objective is to be evaluated). The function should return the objective function value at the point x.

    • constraintsfunction pointer

      Callback function for evaluating constraint functions. The callback functions accepts one parameter: x (value of the optimization variables at which the constraints are to be evaluated). The function should return the constraints values at the point x.

    • gradientfunction pointer

      Callback function for evaluating gradient of objective function. The callback functions accepts one parameter: x (value of the optimization variables at which the gradient is to be evaluated). The function should return the gradient of the objective function at the point x.

    • jacobianfunction pointer

      Callback function for evaluating Jacobian of constraint functions. The callback functions accepts one parameter: x (value of the optimization variables at which the Jacobian is to be evaluated). The function should return the values of the Jacobian as calculated using x. The values should be returned as a 1-dim numpy array (using the same order as you used when specifying the sparsity structure)

    • jacobianstructurefunction pointer, optional (default=None)

      Callback function that accepts no parameters and returns the sparsity structure of the Jacobian (the row and column indices only). If None, the Jacobian is assumed to be dense.

    • hessianfunction pointer, optional (default=None)

      Callback function for evaluating Hessian of the Lagrangian function. The callback functions accepts three parameters x (value of the optimization variables at which the Hessian is to be evaluated), lambda (values for the constraint multipliers at which the Hessian is to be evaluated) objective_factor the factor in front of the objective term in the Hessian. The function should return the values of the Hessian as calculated using x, lambda and objective_factor. The values should be returned as a 1-dim numpy array (using the same order as you used when specifying the sparsity structure). If None, the Hessian is calculated numerically.

    • hessianstructurefunction pointer, optional (default=None)

      Callback function that accepts no parameters and returns the sparsity structure of the Hessian of the lagrangian (the row and column indices only). If None, the Hessian is assumed to be dense.

    • intermediatefunction pointer, optional (default=None)

      Optional. Callback function that is called once per iteration (during the convergence check), and can be used to obtain information about the optimization status while Ipopt solves the problem. If this callback returns False, Ipopt will terminate with the User_Requested_Stop status. The information below corresponeds to the argument list passed to this callback:

      alg_mod:

      Algorithm phase: 0 is for regular, 1 is restoration.

      iter_count:

      The current iteration count.

      obj_value:

      The unscaled objective value at the current point

      inf_pr:

      The scaled primal infeasibility at the current point.

      inf_du:

      The scaled dual infeasibility at the current point.

      mu:

      The value of the barrier parameter.

      d_norm:

      The infinity norm (max) of the primal step.

      regularization_size:

      The value of the regularization term for the Hessian of the Lagrangian in the augmented system.

      alpha_du:

      The stepsize for the dual variables.

      alpha_pr:

      The stepsize for the primal variables.

      ls_trials:

      The number of backtracking line search steps.

      more information can be found in the following link: https://coin-or.github.io/Ipopt/OUTPUT.html

  • lb (array-like, shape(n, )) – Lower bounds on variables, where n is the dimension of x. To assume no lower bounds pass values lower then 10^-19.

  • ub (array-like, shape(n, )) – Upper bounds on variables, where n is the dimension of x. To assume no upper bounds pass values higher then 10^-19.

  • cl (array-like, shape(m, )) – Lower bounds on constraints, where m is the number of constraints. Equality constraints can be specified by setting cl[i] = cu[i].

  • cu (array-like, shape(m, )) – Upper bounds on constraints, where m is the number of constraints. Equality constraints can be specified by setting cl[i] = cu[i].

addOption()

Add a keyword/value option pair to the problem.

Deprecated since version 1.0.0: addOption() will be removed in CyIpopt 1.1.0, it is replaced by add_option() because the latter complies with PEP8.

add_option()

Add a keyword/value option pair to the problem.

See the Ipopt documentaion for details on available options.

Parameters
  • keyword (str) – Option name.

  • val (str, int or float) – Value of the option. The type of val should match the option definition as described in the Ipopt documentation.

close()

Deallocate memory resources used by the Ipopt package.

Called implicitly by the Problem class destructor.

setProblemScaling()

Optional function for setting scaling parameters for the problem.

Deprecated since version 1.0.0: setProblemScaling() will be removed in CyIpopt 1.1.0, it is replaced by set_problem_scaling() because the latter complies with PEP8.

set_problem_scaling()

Optional function for setting scaling parameters for the problem.

To use the scaling parameters set the option nlp_scaling_method to user-scaling.

Parameters
  • obj_scaling (float) – Determines, how Ipopt should internally scale the objective function. For example, if this number is chosen to be 10, then Ipopt solves internally an optimization problem that has 10 times the value of the original objective. In particular, if this value is negative, then Ipopt will maximize the objective function instead of minimizing it.

  • x_scaling (array-like, shape(n, )) – The scaling factors for the variables. If None, no scaling is done.

  • g_scaling (array-like, shape(m, )) – The scaling factors for the constrains. If None, no scaling is done.

solve()

Returns the optimal solution and an info dictionary.

Solves the posed optimization problem starting at point x.

Parameters

x (array-like, shape(n, )) – Initial guess.

Returns

  • x (array, shape(n, )) – Optimal solution.

  • info (dictionary) –

    x: ndarray, shape(n, )

    optimal solution

    g: ndarray, shape(m, )

    constraints at the optimal solution

    obj_val: float

    objective value at optimal solution

    mult_g: ndarray, shape(m, )

    final values of the constraint multipliers

    mult_x_L: ndarray, shape(n, )

    bound multipliers at the solution

    mult_x_U: ndarray, shape(n, )

    bound multipliers at the solution

    status: integer

    gives the status of the algorithm

    status_msg: string

    gives the status of the algorithm as a message

class cyipopt.problem(*args, **kwargs)

Class to continue support for old API.

Deprecated since version 1.0.0: problem will be removed in CyIpopt 1.1.0, it is replaced by Problem because the latter complies with PEP8.

For full documentation of this class including its attributes and methods please see Problem.

This class acts as a wrapper to the new Problem class. It simply issues a FutureWarning to the user before passing all args and kwargs through to Problem.

Returns

Instance created with the args and kwargs parameters.

Return type

Problem

cyipopt.minimize_ipopt(fun, x0, args=(), kwargs=None, method=None, jac=None, hess=None, hessp=None, bounds=None, constraints=(), tol=None, callback=None, options=None)[source]

Minimize a function using ipopt. The call signature is exactly like for scipy.optimize.mimize. In options, all options are directly passed to ipopt. Check [http://www.coin-or.org/Ipopt/documentation/node39.html] for details. The options disp and maxiter are automatically mapped to their ipopt-equivalents print_level and max_iter.

cyipopt.set_logging_level()

Set the logger verbosity to the specified level.

Parameters

level (int) – The verbosity of the logger. This threshold is used to determine which logging messages are logged by this module’s log() function.

cyipopt.setLoggingLevel()

Function to continue support for old API.

Deprecated since version 1.0.0: setLoggingLevel() will be removed in CyIpopt 1.1.0, it is replaced by set_logging_level() because the latter complies with PEP8.

For full documentation of this function please see set_logging_level().

This function acts as a wrapper to the new set_logging_level() function. It simply issues a FutureWarning to the user before passing all args and kwargs through to set_logging_level().