constraint¶
Representations of constraints on qubits.
- class parityos.optimization.constraint.Constraint¶
Bases:
HasFrozenUnorderedQubits[QubitT],ABCInterface for constraints between qubits.
- abstractmethod is_satisfied(state: PauliBasisState[QubitT, Z[Never]]) bool¶
Evaluate whether the constraint is satisfied by the given state.
Caution
All qubits from the constraint must be present in
state.- Parameters:
state – A pauli basis state.
- Returns:
Whether the state satisfies the constraint.
- Raises:
ParityOSException – If not all of the given qubits are present in this state.
- class parityos.optimization.constraint.ConstraintT¶
A
TypeVarrepresenting aConstraint.alias of TypeVar(‘ConstraintT’, bound=
Constraint)
- class parityos.optimization.constraint.ProductConstraint(operator_product: OperatorProduct[Z[QubitT]], parity: Parity = Parity.even)¶
Bases:
Constraint[QubitT]A product constraint given by a tensor product of
ZOperators.Constraints arising from the parity mapping are of this type.
Product constraints can have even or odd
Parity. For a state to satisfy this constrain, the constrained qubits in the state must have this parity.- Raises:
ParityOSTypeError – If not all of the given operators are
Zoperators.
- operator_product: OperatorProduct[Z[QubitT]]¶
Tensor product of
Zoperators acting on the constrained qubits.
- classmethod from_qubits(qubits: QubitT | Iterable[QubitT], parity: Parity = Parity.even) Self¶
Construct a
ProductConstraintfrom qubits alone.
- is_satisfied(state: PauliBasisState[QubitT, Z[Never]]) bool¶
Evaluate whether the constraint is satisfied by the given state.
Caution
All qubits from the constraint must be present in
state.- Parameters:
state – A pauli basis state.
- Returns:
Whether the state satisfies the constraint.
- Raises:
ParityOSException – If not all of the given qubits are present in this state.
- class parityos.optimization.constraint.SumConstraint(operator_polynomial: OperatorPolynomial[Z[QubitT]], value=0.0)¶
Bases:
Constraint[QubitT]A constraint given by an
OperatorPolynomialofZoperators.Sum constraints are fulfilled for a state, if the
operator_polynomialevaluates tovalueunder the state.- Raises:
ParityOSTypeError – If not all of the given operators are
Zoperators.
- operator_polynomial: OperatorPolynomial[Z[QubitT]]¶
Linear combination of tensor products of
Zoperators acting on the constrained qubits.
- is_satisfied(state: PauliBasisState[QubitT, Z[Never]]) bool¶
Evaluate whether the constraint is satisfied by the given state.
Caution
All qubits from the constraint must be present in
state.- Parameters:
state – A pauli basis state.
- Returns:
Whether the state satisfies the constraint.
- Raises:
ParityOSException – If not all of the given qubits are present in this state.