operator_product¶
Representation of tensor products of operators (OperatorProduct).
Operator tensor products naturally arise by multiplying operators that all act on disjoint sets
of qubits. A ProductConstraint or mapping terms in a ParityMapping are natural examples of
operator products.
They support basic arithmetic like addition and multiplication, where multiplication is to be interpreted as tensor product. Operator products can thus easily be assembled by just multiplying the constituent operators.
Example
>>> operator_product = Z(get_q(1)) * Z(get_q(2)) * Z(get_q(3))
- final class parityos.operators.operator_product.OperatorProduct(operators: OperatorT_co | Iterable[OperatorT_co])¶
Bases:
OperatorCompound[OperatorT_co],SizedA tensor product of operators.
Constituent operators are considered in no particular order.
Implements basic arithmetic like addition and multiplication with other
Operator,OperatorProductandOperatorPolynomialinstances.Caution
Constituent operators cannot have overlapping qubits.
- Raises:
ParityOSUniquenessError – If some operators act on the same qubit(s).
- operators: frozenset[OperatorT_co]¶
Constituent operators. Their qubit sets must all be disjoint.
- qubit_to_operator: MappingProxyType¶
Mapping from qubit to the operator that acts on it in this
OperatorProduct.As operators are non-overlapping per definition, each qubit maps to exactly one operator.
- property is_empty: bool¶
Whether this is an empty
OperatorProduct.
- property is_identity: bool¶
Whether this is the identity operator.
The identity is represented by an empty
OperatorProductand is defined by the singletonI.
- is_all(cls: type[OtherOperatorT]) TypeGuard[OperatorProduct[OtherOperatorT]]¶
Check whether all contained operators are instances of
cls.
- property name: str¶
Dynamically generated name for this operator.
Where applicable the name must coincide with the OpenQASM standard.
- __neg__() OperatorPolynomial[OperatorT_co]¶
The negation operator
-.- Returns:
An
OperatorPolynomialwithselfas a single term with coefficient -1.
- __mul__(other: Symbolic | complex) OperatorPolynomial[OperatorT_co]¶
- __mul__(other: OperatorProduct[OtherOperatorT]) OperatorProduct[OperatorT_co | OtherOperatorT]
- __mul__(other: OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[OperatorT_co | OtherOperatorT]
The multiplication operator
*.Multiplication with other operators is to be interpreted as tensor product.
- Parameters:
other – A
Coefficient, anotherOperatorProductor aOperatorPolynomial.- Returns:
If
otheris aCoefficient, returns anOperatorPolynomialwithselfas a single term with coefficientother. Ifotheris anotherOperatorProduct, returns a newOperatorProductwith the union ofself’s andother’s operators. Ifotheris anOperatorPolynomial, distributively multiplyselfonto every term ofother.- Raises:
ParityOSUniquenessError – If some operators act on the same qubit(s) in
selfandotherin the caseotheris anotherOperatorProductor aOperatorPolynomial.
- __add__(other: int | OperatorProduct[OtherOperatorT] | OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[OperatorT_co | OtherOperatorT]¶
The addition operator
+.- Parameters:
other – An
int, anotherOperatorProductor anOperatorPolynomial.- Returns:
If
otheris anotherOperatorProduct, returns a two-termOperatorPolynomialwithselfandotheras terms with unit coefficients. Ifotheris anOperatorPolynomial, addselfas a term with unit coefficient toother. Ifotheris0, returnsself, enabling sums ofOperatorProductinstances.
- __sub__(other: OperatorProduct[OtherOperatorT] | OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[OperatorT_co | OtherOperatorT]¶
The subtraction operator
-.- Parameters:
other – Another
OperatorProductor anOperatorPolynomial.- Returns:
- parityos.operators.operator_product.I = OperatorProduct(operators=frozenset())¶
The singleton identity operator represented as an empty
OperatorProduct.