qiskit_addon_opt_mapper.problems.HigherOrderConstraint

class HigherOrderConstraint(optimization_problem, name, linear=None, quadratic=None, higher_order=None, sense=ConstraintSense.LE, rhs=0.0)[source]

Bases: Constraint

Constraint in higher order form.

e.g. linear(x) + x^T Q x + sum_{k>=3}  sum_{|t|=k} C_k[t] * prod_{i in t} x[i] sense rhs where sense is one of the ConstraintSense values (e.g., LE, <=) and rhs is a float.

Supports both a single higher-order term (order+coeffs) and multiple via higher_orders={k: coeffs}.

Construct a higher-order constraint with linear, quadratic, and optional higher-order parts.

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

  • name (str) – The name of the constraint.

  • linear (ndarray | spmatrix | list[float] | dict[str | int, float] | None) – Coefficients for the linear part.

  • quadratic (ndarray | spmatrix | list[list[float]] | dict[tuple[int | str, int | str], float] | None) – Coefficients for the quadratic part.

  • 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 (ConstraintSense) – The sense of the constraint (e.g., LE, <=).

  • rhs (float) – The right-hand-side value of the constraint.

__init__(optimization_problem, name, linear=None, quadratic=None, higher_order=None, sense=ConstraintSense.LE, rhs=0.0)[source]

Construct a higher-order constraint with linear, quadratic, and optional higher-order parts.

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

  • name (str) – The name of the constraint.

  • linear (ndarray | spmatrix | list[float] | dict[str | int, float] | None) – Coefficients for the linear part.

  • quadratic (ndarray | spmatrix | list[list[float]] | dict[tuple[int | str, int | str], float] | None) – Coefficients for the quadratic part.

  • 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 (ConstraintSense) – The sense of the constraint (e.g., LE, <=).

  • rhs (float) – The right-hand-side value of the constraint.

Return type:

None

Methods

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

Construct a higher-order constraint with linear, quadratic, and optional higher-order parts.

evaluate(x)

Evaluate the left-hand-side of the constraint.

Attributes

higher_order

HigherOrderExpression}.

linear

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

name

Returns the name of the constraint.

optimization_problem

Returns the parent OptimizationProblem.

quadratic

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

rhs

Returns the right-hand-side of the constraint.

sense

Returns the sense of the constraint.

Sense[source]

alias of ConstraintSense

evaluate(x)[source]

Evaluate the left-hand-side of the constraint.

Parameters:

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

Returns:

The left-hand-side of the constraint given the variable values.

Return type:

float

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 name: str

Returns the name of the constraint.

Returns:

The name of the constraint.

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 rhs: float

Returns the right-hand-side of the constraint.

Returns:

The right-hand-side of the constraint.

property sense: ConstraintSense

Returns the sense of the constraint.

Returns:

The sense of the constraint.