qiskit_addon_opt_mapper.problems.HigherOrderExpression¶
- class HigherOrderExpression(optimization_problem, coefficients)[source]¶
 Bases:
OptimizationProblemElementRepresentation of a symmetric k-th order expression by its coefficients.
We represent a symmetric polynomial term of order k as
f(x) = sum_{t} C[t] * prod_{i in t} x[i], where t is a multiset of variable indices of length k.When dealing with multidimensional array indices, the value is stored only at the lexicographically smallest permutation of the indices (obtained by sorting them in ascending order).
For example, for a 4th-order term
2⋅x1⋅x2⋅x3⋅x4, the coefficient “2” is stored atdict((1, 2, 3, 4)). Other permutations likedict((2, 1, 4, 3))ordict((4, 3, 2, 1))are left empty.Creates a new higher-order expression.
- Parameters:
 optimization_problem (Any) – The parent OptimizationProblem.
coefficients (ndarray | dict[Key, float] | list) – Coefficients as either: - A dense ndarray or list with shape (n,)*k, or - A dict mapping a tuple of variable indices/names (length k) to float. Keys are canonicalized to ascending order and summed.
- __init__(optimization_problem, coefficients)[source]¶
 Creates a new higher-order expression.
- Parameters:
 optimization_problem (Any) – The parent OptimizationProblem.
coefficients (ndarray | dict[Key, float] | list) – Coefficients as either: - A dense ndarray or list with shape (n,)*k, or - A dict mapping a tuple of variable indices/names (length k) to float. Keys are canonicalized to ascending order and summed.
- Return type:
 None
Methods
__init__(optimization_problem, coefficients)Creates a new higher-order expression.
evaluate(x)Evaluate the expression: sum_{t} C[t] * prod_{i in t} x[i].
Evaluate gradient wrt x.
to_array([symmetric])Returns a dense tensor.
to_dict([use_name])Returns the internal coefficients as a dictionary.
Attributes
Returns the lower bound and the upper bound of the linear expression.
Returns a copy of internal (canonical) coefficient dictionary.
Returns the number of variables in this expression.
Returns the parent OptimizationProblem.
Returns the order of the polynomial (k >= 3).
- property bounds: ExpressionBounds¶
 Returns the lower bound and the upper bound of the linear expression.
- Returns:
 The lower bound and the upper bound of the linear expression
- property coefficients: dict[tuple[int, ...], float]¶
 Returns a copy of internal (canonical) coefficient dictionary.
- evaluate_gradient(x)[source]¶
 Evaluate gradient wrt x.
For each m, g[m] = sum_{t} C[t] * (count_m_in_t) * prod_{i in t / {one m}}.
- property optimization_problem: OptimizationProblem¶
 Returns the parent OptimizationProblem.
- Returns:
 The parent OptimizationProblem.