problem_representation

Representations of combinatorial optimization problems as spin models, optionally with constraints.

class parityos.optimization.problem_representation.ProblemRepresentation(hamiltonian: OperatorPolynomial[Z[QubitT_co]], product_constraints: T | Iterable[T] = NOTHING, sum_constraints: T | Iterable[T] = NOTHING)

Bases: HasFrozenUnorderedQubits[QubitT_co]

Representation of an optimization problem as a spin Hamiltonian (diagonal in the Pauli Z basis) as an OperatorPolynomial of Z operators, together with an optional set of product and/or sum constraints.

Examples

>>> optimization_problem = ProblemRepresentation(
>>>     hamiltonian=0.5 * Z(get_q(0, 0)) - 0.8 * Z(get_q(0, 1)) + 1.2 * Z(get_q(1, 0))
>>>     product_constraints=ProductConstraint(
>>>         Z(get_q(0, 0)) * Z(get_q(0, 1)) * Z(get_q(1, 0)),
>>>         True
>>>     )  # odd parity constraint
>>> )
hamiltonian: OperatorPolynomial[Z[QubitT_co]]

Logical spin Hamiltonian that represents the optimization problem, including all constant, single-qubit and multi-qubit terms.

product_constraints: frozenset[ProductConstraint[QubitT_co]]

Product constraints which must be satisfied by the solutions of the optimization problem. For the compiled problem, this will also contain the required parity constraints. Optional.

sum_constraints: frozenset[SumConstraint[QubitT_co]]

Sum constraints which must be satisfied by the solutions of the optimization problem. Optional.

constraints: frozenset[Constraint[QubitT_co]]

All constraints in this problem.

Comprises product constraints and sum constraints.

qubits: frozenset[QubitT_co]