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.ConstraintSense(*values)¶
Bases:
EnumThe relation between the left-hand and the right-hand side of a
SumConstraint.Strict inequalities are not supported, as mixed-integer programming modelers can not represent them either.
Added in version 3.2.0.
- EQUAL = '='¶
operator_polynomial == value.- Type:
Equality
- LESS_EQUAL = '<='¶
operator_polynomial <= value.- Type:
Less than or equal
- GREATER_EQUAL = '>='¶
operator_polynomial >= value.- Type:
Greater than or equal
- 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, sense=ConstraintSense.EQUAL)¶
Bases:
Constraint[QubitT]A constraint given by an
OperatorPolynomialofZoperators.Sum constraints are fulfilled for a state, if the value of
operator_polynomialunder the state is equal to (ConstraintSense.EQUAL, the default), less than or equal to (ConstraintSense.LESS_EQUAL) or greater than or equal to (ConstraintSense.GREATER_EQUAL)value.Note
Only sum constraints support inequalities: a product of spins can only take the values \(\pm 1\), which is fully covered by the
Parityof aProductConstraint.Changed in version 3.2.0: Added
sensefor inequality constraints.- 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.
- sense: ConstraintSense¶
Relation between
operator_polynomialandvalue. Defaults toConstraintSense.EQUAL.
- property is_equality: bool¶
Whether this is an equality constraint, i.e. its
senseisConstraintSense.EQUAL.
- 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.
ParityOSTypeError – If the constraint is an inequality and the value of the polynomial is not a real number (e.g. due to complex or symbolic coefficients).