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], Sized

A tensor product of operators.

Constituent operators are considered in no particular order.

Implements basic arithmetic like addition and multiplication with other Operator, OperatorProduct and OperatorPolynomial instances.

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.

property n_operators: int

The number of operators in this tensor product.

__len__() int

The number of operators in this tensor product.

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 OperatorProduct and is defined by the singleton I.

is_all(cls: type[OtherOperatorT]) TypeGuard[OperatorProduct[OtherOperatorT]]

Check whether all contained operators are instances of cls.

property is_mixed: bool

Check whether all contained operators are of the same type.

property name: str

Dynamically generated name for this operator.

Where applicable the name must coincide with the OpenQASM standard.

qubits: frozenset[Qubit]
get_hermitian_conjugate() Self

Return the hermitian conjugate (\(\dagger\)) of this operator.

is_hermitian: bool
__neg__() OperatorPolynomial[OperatorT_co]

The negation operator -.

Returns:

An OperatorPolynomial with self as 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, another OperatorProduct or a OperatorPolynomial.

Returns:

If other is a Coefficient, returns an OperatorPolynomial with self as a single term with coefficient other. If other is another OperatorProduct, returns a new OperatorProduct with the union of self’s and other’s operators. If other is an OperatorPolynomial, distributively multiply self onto every term of other.

Raises:

ParityOSUniquenessError – If some operators act on the same qubit(s) in self and other in the case other is another OperatorProduct or a OperatorPolynomial.

__add__(other: int | OperatorProduct[OtherOperatorT] | OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[OperatorT_co | OtherOperatorT]

The addition operator +.

Parameters:

other – An int, another OperatorProduct or an OperatorPolynomial.

Returns:

If other is another OperatorProduct, returns a two-term OperatorPolynomial with self and other as terms with unit coefficients. If other is an OperatorPolynomial, add self as a term with unit coefficient to other. If other is 0, returns self, enabling sums of OperatorProduct instances.

__sub__(other: OperatorProduct[OtherOperatorT] | OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[OperatorT_co | OtherOperatorT]

The subtraction operator -.

Parameters:

other – Another OperatorProduct or an OperatorPolynomial.

Returns:

self + (-other), see __add__ and __neg__.

parityos.operators.operator_product.I = OperatorProduct(operators=frozenset())

The singleton identity operator represented as an empty OperatorProduct.