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],ABCInterface 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.
- class parityos.operators.operator.Operator¶
Bases:
OperatorLike[QubitT_co],ABCInterface defining basic arithmetic on
OperatorLikeobjects, like addition and multiplication, where multiplication is to be interpreted as a tensor product.- __neg__() OperatorPolynomial[Self]¶
The negation operator
-.- Returns:
An
OperatorPolynomialwith a single term containingselfwith 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, anotherOperator, anOperatorProductor anOperatorPolynomial.- Returns:
If
otheris aCoefficient, returns anOperatorPolynomialwith a single term containingselfwith coefficient-1. Ifotheris anotherOperator, returns a two-elementOperatorProductwithselfandotheras elements. Ifotheris anOperatorProduct, addselfto the operators ofother. Ifotheris anOperatorPolynomial, multiplyselfto each term inother.- Raises:
ParityOSUniquenessError – If some operators act on the same qubit(s) in the case
otheris anotherOperator, anOperatorProductor anOperatorPolynomial.
- __add__(other: int | OtherOperatorT | OperatorProduct[OtherOperatorT] | OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[Self | OtherOperatorT]¶
The addition operator
+.- Parameters:
other – An
int, anotherOperator, anOperatorProductor anOperatorPolynomial.- Returns:
If
otheris0, returnsselfto enablesumofOperatorinstances. Ifotheris anotherOperatoror anOperatorProduct, returns a two elementOperatorPolynomialwith bothselfandotherturned into single elementOperatorProductterms with unit coefficient. Ifotheris anOperatorPolynomial, turnselfinto a single elementOperatorProductand add it to the terms ofotherwith unit coefficient.
- __sub__(other: OtherOperatorT | OperatorProduct[OtherOperatorT] | OperatorPolynomial[OtherOperatorT]) OperatorPolynomial[Self | OtherOperatorT]¶
The subtraction operator
-.- Parameters:
other – An
int, anotherOperator, anOperatorProductor anOperatorPolynomial.- Returns:
- class parityos.operators.operator.OperatorT¶
A
TypeVarrepresenting anOperator.alias of TypeVar(‘OperatorT’, bound=
Operator)
- class parityos.operators.operator.OperatorT_co¶
A covariant
TypeVarrepresenting anOperator.alias of TypeVar(‘OperatorT_co’, bound=
Operator, covariant=True)
- class parityos.operators.operator.OperatorT_contra¶
A contravariant
TypeVarrepresenting anOperator.alias of TypeVar(‘OperatorT_contra’, bound=
Operator, contravariant=True)
- class parityos.operators.operator.OtherOperatorT¶
A
TypeVarrepresenting anotherOperator.alias of TypeVar(‘OtherOperatorT’, bound=
Operator)
- class parityos.operators.operator.OperatorCompound¶
Bases:
OperatorLike[Qubit],HasFrozenUnorderedQubits[Qubit],Generic[OperatorT_co],ABCInterface for containers or operators that act as compound collection of operators, such as
OperatorProductorOperatorPolynomial.- abstractmethod is_all(cls: type[OtherOperatorT]) TypeGuard[OperatorCompound[OtherOperatorT]]¶
Check whether all contained operators are instances of
cls.
- class parityos.operators.operator.ConcreteOperator¶
Bases:
Operator[QubitT_co],HasFrozenQubits[QubitT_co],ABCInterface 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.
- class parityos.operators.operator.OrderedMultiQubitOperator(ordered_qubits)¶
Bases:
ConcreteOperator[QubitT_co],HasFrozenOrderedQubits[QubitT_co],ABCInterface 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
TypeVarrepresenting anOrderedMultiQubitOperator.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],ABCInterface 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
TypeVarrepresenting anUnorderedMultiQubitOperator.alias of TypeVar(‘UnorderedMultiQubitOperatorT_co’, bound=
UnorderedMultiQubitOperator, covariant=True)
- class parityos.operators.operator.SingleQubitOperator(qubit: QubitT_co)¶
Bases:
ConcreteOperator[QubitT_co],HasFrozenOrderedQubits[QubitT_co],ABCInterface for elementary operators acting on a single qubit.
Adds a
qubitattribute.- n_qubits: ClassVar[int] = 1¶
The number of qubits this operator acts on. Implementing classes define this as static class variable.
- class parityos.operators.operator.SingleQubitOperatorT_co¶
A covariant
TypeVarrepresenting aSingleQubitOperator.alias of TypeVar(‘SingleQubitOperatorT_co’, bound=
SingleQubitOperator, covariant=True)
- class parityos.operators.operator.HermitianOperator¶
Bases:
Operator[QubitT_co],ABCMixin class for hermitian operators.
get_hermitian_conjugatereturns a copy of itself andis_hermitianalways returnsTrue.
- class parityos.operators.operator.HermitianOrderedMultiQubitOperator(ordered_qubits)¶
Bases:
OrderedMultiQubitOperator[QubitT_co],HermitianOperator[QubitT_co],ABCInterface 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],ABCInterface 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],ABCInterface for hermitian operators acting on a single qubit.
- class parityos.operators.operator.HermitianT¶
A
TypeVarrepresenting aHermitianOperator.alias of TypeVar(‘HermitianT’, bound=
HermitianOperator)
- class parityos.operators.operator.HermitianT_co¶
A covariant
TypeVarrepresenting aHermitianOperator.alias of TypeVar(‘HermitianT_co’, bound=
HermitianOperator, covariant=True)
- class parityos.operators.operator.HermitianSingleT_co¶
A covariant
TypeVarrepresenting aHermitianSingleQubitOperator.alias of TypeVar(‘HermitianSingleT_co’, bound=
HermitianSingleQubitOperator, covariant=True)
- class parityos.operators.operator.HermitianOrderedMultiT_co¶
A covariant
TypeVarrepresenting aHermitianOrderedMultiQubitOperator.alias of TypeVar(‘HermitianOrderedMultiT_co’, bound=
HermitianOrderedMultiQubitOperator, covariant=True)
- class parityos.operators.operator.HermitianUnorderedMultiT_co¶
A covariant
TypeVarrepresenting aHermitianUnorderedMultiQubitOperator.alias of TypeVar(‘HermitianUnorderedMultiT_co’, bound=
HermitianUnorderedMultiQubitOperator, covariant=True)
- class parityos.operators.operator.PauliOperator(qubit: QubitT_co)¶
- class parityos.operators.operator.PauliOperatorT¶
A
TypeVarrepresenting aPauliOperator.alias of TypeVar(‘PauliOperatorT’, bound=
PauliOperator)