qiskit_addon_opt_mapper.problems.OptimizationObjective

class OptimizationObjective(optimization_problem, constant=0.0, linear=None, quadratic=None, higher_order=None, sense=ObjSense.MINIMIZE)[source]

Bases: OptimizationProblemElement

Optimization objective element.

Follows:

constant + linear(x) + x^T Q x + sum_{k>=3} H_k(x).

Construct an objective with linear, quadratic, and optional higher-order parts.

Parameters:
  • optimization_problem (Any) – The optimization problem this objective belongs to.

  • constant (float) – The constant part of the objective function.

  • linear (ndarray | spmatrix | list[float] | dict[int | str, float] | None) – The coefficients for the linear part of the objective function.

  • quadratic (ndarray | spmatrix | list[list[float]] | dict[tuple[int | str, int | str], float] | None) – The coefficients for the quadratic part of the objective function.

  • higher_order (dict[int, ndarray | dict[tuple[int | str, ...], float] | list] | None) – A single higher-order expression or a dictionary of {order: coeffs} for multiple orders (k>=3).

  • sense (ObjSense) – The sense of the objective function (e.g., MINIMIZE, MAXIMIZE).

__init__(optimization_problem, constant=0.0, linear=None, quadratic=None, higher_order=None, sense=ObjSense.MINIMIZE)[source]

Construct an objective with linear, quadratic, and optional higher-order parts.

Parameters:
  • optimization_problem (Any) – The optimization problem this objective belongs to.

  • constant (float) – The constant part of the objective function.

  • linear (ndarray | spmatrix | list[float] | dict[str | int, float] | None) – The coefficients for the linear part of the objective function.

  • quadratic (ndarray | spmatrix | list[list[float]] | dict[tuple[int | str, int | str], float] | None) – The coefficients for the quadratic part of the objective function.

  • higher_order (dict[int, ndarray | dict[tuple[str | int, ...], float] | list] | None) – A single higher-order expression or a dictionary of {order: coeffs} for multiple orders (k>=3).

  • sense (ObjSense) – The sense of the objective function (e.g., MINIMIZE, MAXIMIZE).

Return type:

None

Methods

__init__(optimization_problem[, constant, ...])

Construct an objective with linear, quadratic, and optional higher-order parts.

evaluate(x)

Evaluate objective value at x.

evaluate_gradient(x)

Evaluate gradient of the objective at x.

Attributes

constant

Returns the constant part of the objective function.

higher_order

HigherOrderExpression}.

linear

Returns the linear expression corresponding to the left-hand-side of the constraint.

optimization_problem

Returns the parent OptimizationProblem.

quadratic

Returns the quadratic expression corresponding to the left-hand-side of the constraint.

sense

Returns the sense of the objective function.

Sense[source]

alias of ObjSense

property constant: float

Returns the constant part of the objective function.

Returns:

The constant part of the objective function.

evaluate(x)[source]

Evaluate objective value at x.

Parameters:

x (ndarray | list | dict[int | str, float]) – The values of the variables to be evaluated.

Returns:

The objective value given the variable values.

Return type:

float

evaluate_gradient(x)[source]

Evaluate gradient of the objective at x.

Parameters:

x (ndarray | list | dict[int | str, float]) – The values of the variables to be evaluated.

Returns:

The gradient of the objective function given the variable values.

Return type:

ndarray

property higher_order: dict[int, HigherOrderExpression]

HigherOrderExpression}.

Returns:

A dictionary mapping order (k>=3) to HigherOrderExpression.

Type:

Return a shallow copy of {order

property linear: LinearExpression

Returns the linear expression corresponding to the left-hand-side of the constraint.

Returns:

The left-hand-side linear expression.

property optimization_problem: OptimizationProblem

Returns the parent OptimizationProblem.

Returns:

The parent OptimizationProblem.

property quadratic: QuadraticExpression

Returns the quadratic expression corresponding to the left-hand-side of the constraint.

Returns:

The left-hand-side quadratic expression.

property sense: ObjSense

Returns the sense of the objective function.

Returns:

The sense of the objective function (e.g., MINIMIZE, MAXIMIZE).