constraint

Representations of constraints on qubits.

class parityos.optimization.constraint.Constraint

Bases: HasFrozenUnorderedQubits[QubitT], ABC

Interface 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 TypeVar representing a Constraint.

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 Z Operators.

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 Z operators.

operator_product: OperatorProduct[Z[QubitT]]

Tensor product of Z operators acting on the constrained qubits.

parity: Parity

The parity of the constraint.

classmethod from_qubits(qubits: QubitT | Iterable[QubitT], parity: Parity = Parity.even) Self

Construct a ProductConstraint from 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.

qubits: frozenset[QubitT]
class parityos.optimization.constraint.SumConstraint(operator_polynomial: OperatorPolynomial[Z[QubitT]], value=0.0)

Bases: Constraint[QubitT]

A constraint given by an OperatorPolynomial of Z operators.

Sum constraints are fulfilled for a state, if the operator_polynomial evaluates to value under the state.

Raises:

ParityOSTypeError – If not all of the given operators are Z operators.

operator_polynomial: OperatorPolynomial[Z[QubitT]]

Linear combination of tensor products of Z operators acting on the constrained qubits.

value: float

Value for which this constraint is fulfilled. Defaults to 0.

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.

qubits: frozenset[QubitT]