operator

Interfaces representing operators and their compounds.

Operators can be parameterized, hermitian and symmetric under qubit permutation. Operators support basic arithmetic like addition and multiplication, where multiplication is to be interpreted as tensor product.

Adding and multiplying operators generates higher order operator compounds, such as OperatorProduct and OperatorPolynomial.

class parityos.operators.operator.OperatorLike

Bases: HasFrozenQubits[QubitT_co], ABC

Interface for all objects that behave like operators acting on a set of qubits.

abstract property name: str

Dynamically generated name for this operator.

Where applicable the name must coincide with the OpenQASM standard.

abstractmethod get_hermitian_conjugate() OperatorLike[QubitT_co]

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

property is_hermitian: bool

Whether this operator is hermitian.

class parityos.operators.operator.Operator

Bases: OperatorLike[QubitT_co], ABC

Interface defining basic arithmetic on OperatorLike objects, like addition and multiplication, where multiplication is to be interpreted as a tensor product.

__neg__() OperatorPolynomial[Self]

The negation operator -.

Returns:

An OperatorPolynomial with a single term containing self with coefficient -1.

__mul__(other: OtherOperatorT | OperatorProduct[OtherOperatorT]) OperatorProduct[Self | OtherOperatorT]
__mul__(other: OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[Self | OtherOperatorT]
__mul__(other: Symbolic | complex) OperatorPolynomial[Self]

The multiplication operator *.

Multiplication between operators is to be interpreted as a tensor product.

Parameters:

other – A scalar Coefficient, another Operator, an OperatorProduct or an OperatorPolynomial.

Returns:

If other is a Coefficient, returns an OperatorPolynomial with a single term containing self with coefficient -1. If other is another Operator, returns a two-element OperatorProduct with self and other as elements. If other is an OperatorProduct, add self to the operators of other. If other is an OperatorPolynomial, multiply self to each term in other.

Raises:

ParityOSUniquenessError – If some operators act on the same qubit(s) in the case other is another Operator, an OperatorProduct or an OperatorPolynomial.

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

The addition operator +.

Parameters:

other – An int, another Operator, an OperatorProduct or an OperatorPolynomial.

Returns:

If other is 0, returns self to enable sum of Operator instances. If other is another Operator or an OperatorProduct, returns a two element OperatorPolynomial with both self and other turned into single element OperatorProduct terms with unit coefficient. If other is an OperatorPolynomial, turn self into a single element OperatorProduct and add it to the terms of other with unit coefficient.

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

The subtraction operator -.

Parameters:

other – An int, another Operator, an OperatorProduct or an OperatorPolynomial.

Returns:

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

class parityos.operators.operator.OperatorT

A TypeVar representing an Operator.

alias of TypeVar(‘OperatorT’, bound=Operator)

class parityos.operators.operator.OperatorT_co

A covariant TypeVar representing an Operator.

alias of TypeVar(‘OperatorT_co’, bound=Operator, covariant=True)

class parityos.operators.operator.OperatorT_contra

A contravariant TypeVar representing an Operator.

alias of TypeVar(‘OperatorT_contra’, bound=Operator, contravariant=True)

class parityos.operators.operator.OtherOperatorT

A TypeVar representing another Operator.

alias of TypeVar(‘OtherOperatorT’, bound=Operator)

class parityos.operators.operator.OperatorCompound

Bases: OperatorLike[Qubit], HasFrozenUnorderedQubits[Qubit], Generic[OperatorT_co], ABC

Interface for containers or operators that act as compound collection of operators, such as OperatorProduct or OperatorPolynomial.

abstractmethod is_all(cls: type[OtherOperatorT]) TypeGuard[OperatorCompound[OtherOperatorT]]

Check whether all contained operators are instances of cls.

abstract property is_mixed: bool

Check whether all contained operators are of the same type.

class parityos.operators.operator.ConcreteOperator

Bases: Operator[QubitT_co], HasFrozenQubits[QubitT_co], ABC

Interface for concrete operator classes that have a pre-defined number of qubits.

n_qubits: ClassVar[int]

The number of qubits this operator acts on. Implementing classes define this as static class variable.

property name: str

Dynamically generated name for this operator.

Where applicable the name must coincide with the OpenQASM standard.

property is_hermitian: bool

Whether this operator is hermitian.

class parityos.operators.operator.OrderedMultiQubitOperator(ordered_qubits)

Bases: ConcreteOperator[QubitT_co], HasFrozenOrderedQubits[QubitT_co], ABC

Interface for elementary operators acting on an ordered sequence of qubits.

As qubit order matters, the qubits are stored as a tuple.

class parityos.operators.operator.OrderedMultiQubitOperatorT_co

A covariant TypeVar representing an OrderedMultiQubitOperator.

alias of TypeVar(‘OrderedMultiQubitOperatorT_co’, bound=OrderedMultiQubitOperator, covariant=True)

class parityos.operators.operator.UnorderedMultiQubitOperator(qubits: Iterable[QubitT_co])

Bases: ConcreteOperator[QubitT_co], HasFrozenUnorderedQubits[QubitT_co], ABC

Interface for elementary operators acting on an unordered set of qubits, that are symmetric under qubit permutation.

As qubit order doesn’t matter, the qubits are stored as a frozenset.

class parityos.operators.operator.UnorderedMultiQubitOperatorT_co

A covariant TypeVar representing an UnorderedMultiQubitOperator.

alias of TypeVar(‘UnorderedMultiQubitOperatorT_co’, bound=UnorderedMultiQubitOperator, covariant=True)

class parityos.operators.operator.SingleQubitOperator(qubit: QubitT_co)

Bases: ConcreteOperator[QubitT_co], HasFrozenOrderedQubits[QubitT_co], ABC

Interface for elementary operators acting on a single qubit.

Adds a qubit attribute.

n_qubits: ClassVar[int] = 1

The number of qubits this operator acts on. Implementing classes define this as static class variable.

qubit: QubitT_co

The single qubit this operator acts on.

ordered_qubits: tuple[QubitT_co, ...]
property name: str

Dynamically generated name for this operator.

Where applicable the name must coincide with the OpenQASM standard.

is_hermitian: bool
class parityos.operators.operator.SingleQubitOperatorT_co

A covariant TypeVar representing a SingleQubitOperator.

alias of TypeVar(‘SingleQubitOperatorT_co’, bound=SingleQubitOperator, covariant=True)

class parityos.operators.operator.HermitianOperator

Bases: Operator[QubitT_co], ABC

Mixin class for hermitian operators.

get_hermitian_conjugate returns a copy of itself and is_hermitian always returns True.

get_hermitian_conjugate() Self

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

property is_hermitian: bool

Whether this operator is hermitian.

class parityos.operators.operator.HermitianOrderedMultiQubitOperator(ordered_qubits)

Bases: OrderedMultiQubitOperator[QubitT_co], HermitianOperator[QubitT_co], ABC

Interface for hermitian operators acting on an ordered sequence of qubits.

class parityos.operators.operator.HermitianUnorderedMultiQubitOperator(qubits: Iterable[QubitT_co])

Bases: UnorderedMultiQubitOperator[QubitT_co], HermitianOperator[QubitT_co], ABC

Interface for hermitian operators acting on an unordered set of qubits, that are symmetric under qubit permutation.

class parityos.operators.operator.HermitianSingleQubitOperator(qubit: QubitT_co)

Bases: SingleQubitOperator[QubitT_co], HermitianOperator[QubitT_co], ABC

Interface for hermitian operators acting on a single qubit.

class parityos.operators.operator.HermitianT

A TypeVar representing a HermitianOperator.

alias of TypeVar(‘HermitianT’, bound=HermitianOperator)

class parityos.operators.operator.HermitianT_co

A covariant TypeVar representing a HermitianOperator.

alias of TypeVar(‘HermitianT_co’, bound=HermitianOperator, covariant=True)

class parityos.operators.operator.HermitianSingleT_co

A covariant TypeVar representing a HermitianSingleQubitOperator.

alias of TypeVar(‘HermitianSingleT_co’, bound=HermitianSingleQubitOperator, covariant=True)

class parityos.operators.operator.HermitianOrderedMultiT_co

A covariant TypeVar representing a HermitianOrderedMultiQubitOperator.

alias of TypeVar(‘HermitianOrderedMultiT_co’, bound=HermitianOrderedMultiQubitOperator, covariant=True)

class parityos.operators.operator.HermitianUnorderedMultiT_co

A covariant TypeVar representing a HermitianUnorderedMultiQubitOperator.

alias of TypeVar(‘HermitianUnorderedMultiT_co’, bound=HermitianUnorderedMultiQubitOperator, covariant=True)

class parityos.operators.operator.PauliOperator(qubit: QubitT_co)

Bases: HermitianSingleQubitOperator[QubitT_co]

Interface for Pauli Operators (X, Y, Z).

class parityos.operators.operator.PauliOperatorT

A TypeVar representing a PauliOperator.

alias of TypeVar(‘PauliOperatorT’, bound=PauliOperator)