NonlinearExpressionData

(class from pyomo.contrib.solver.solvers.knitro.utils)

class pyomo.contrib.solver.solvers.knitro.utils.NonlinearExpressionData(expr: Expression, variables: Iterable[VarData], var_map: Mapping[int, int], diff_order: int = 0)[source]

Bases: Function

Holds the data required to evaluate a non-linear expression.

This class stores a Pyomo expression along with its variables and can compute gradient and Hessian information for use with optimization solvers.

variables

list of variables referenced in the expression.

Type:

list[VarData]

func_expr

The Pyomo expression representing the non-linear function.

Type:

Expression

grad_map

Gradient expressions mapped by variable.

Type:

Mapping[VarData, Expression]

hess_map

Hessian expressions mapped by variable pairs.

Type:

Mapping[tuple[VarData, VarData], Expression]

diff_order

Level of differentiation to compute: - 0: function evaluation only - 1: function + gradient - 2: function + gradient + hessian

Type:

int

__init__(expr: Expression, variables: Iterable[VarData], var_map: Mapping[int, int], diff_order: int = 0) None[source]

Initialize NonlinearExpressionData.

Parameters:
  • expr (Expression) – The Pyomo expression to evaluate.

  • variables (Iterable[VarData]) – Variables referenced in the expression.

  • diff_order (int) – Level of differentiation to compute: - 0: function evaluation only - 1: function + gradient - 2: function + gradient + hessian

Methods

__init__(expr, variables, var_map[, diff_order])

Initialize NonlinearExpressionData.

compute_gradient()

Compute gradient expressions for the nonlinear expression.

compute_hessian()

Compute Hessian expressions for the nonlinear expression.

evaluate(x)

gradient(x)

hessian(x, mu)

Attributes

grad_vars

Get the list of variables for which gradients are available.

hess_vars

Get the list of variable pairs for which Hessian entries are available.

variables

func_expr

grad_map

hess_map

diff_order

Member Documentation

compute_gradient() None[source]

Compute gradient expressions for the nonlinear expression.

This method computes the gradient of the expression with respect to all variables and stores the results in the grad attribute.

compute_hessian() None[source]

Compute Hessian expressions for the nonlinear expression.

This method computes the Hessian matrix of the expression with respect to all variables and stores the results in the hess attribute. Only the upper triangle of the Hessian is stored to avoid redundancy.

Note

This method requires that compute_gradient() has been called first.

property grad_vars: list[VarData]

Get the list of variables for which gradients are available.

Returns:

Variables with gradient information.

Return type:

list[VarData]

property hess_vars: list[tuple[VarData, VarData]]

Get the list of variable pairs for which Hessian entries are available.

Returns:

Variable pairs with Hessian information.

Return type:

list[tuple[VarData, VarData]]