rotation_operator

Defines a rotation operator that represents an exponential of a hermitian operator.

parityos.operators.rotation_operator.DEFAULT_ANGLE = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True))

This symbol can be used as a placeholder for rotations by an unknown angle or as default value.

class parityos.operators.rotation_operator.RotationOperator

Bases: Operator[QubitT_co], Parameterized, Generic[QubitT_co, HermitianT_co], ABC

A rotation operator.

\[R(A) = \exp\left(- i \frac{A}{2}\right)\]

where \(A\) is a hermitian OperatorPolynomial.

The coefficient(s) of the term(s) in operator represent the rotation angle(s).

property exponent: OperatorPolynomial[HermitianT_co]

The hermitian operator in the exponent defining the rotation axis.

property is_hermitian: bool

Rotation operators are generally not hermitian.

class parityos.operators.rotation_operator.GeneralRotationOperator(exponent: HermitianOperator[QubitT_co] | OperatorProduct[HermitianOperator[QubitT_co]] | OperatorPolynomial[HermitianOperator[QubitT_co]])

Bases: RotationOperator[QubitT_co, HermitianOperator[QubitT_co]]

General rotation operator taking any hermitian OperatorPolynomial as exponent.

If the target exponent corresponds to any of the concrete implementations below, an instance of the respective concrete operator class is created.

Examples

>>> op = GeneralRotationOperator(2*Z(get_q(0)))
>>> assert type(op).__name__ == "RZ"
>>> op = GeneralRotationOperator(-X(get_q(0))*X(get_q(1)))
>>> assert type(op).__name__ == "RXX"
>>> op = GeneralRotationOperator(X(get_q(0))*Y(get_q(1)))
>>> assert type(op).__name__ == "GeneralRotationOperator"
Raises:

TypeError – If exponent is not hermitian.

exponent: OperatorPolynomial[HermitianOperator[QubitT_co]]

The hermitian operator in the exponent defining the rotation axis. See RotationOperator.

property name: str

Dynamically generated name for this operator.

Where applicable the name must coincide with the OpenQASM standard.

qubits: frozenset[QubitT_co]
ordered_qubits: tuple[QubitT_co, ...]
get_hermitian_conjugate() Self

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

parameters: frozenset[Parameter]
substitute_parameters(old_to_new: Mapping[Parameter, Symbolic | complex]) Self

Substitute symbolic parameters with new symbolic expressions or numeric values.

Parameters:

old_to_new – Mapping from existing parameter symbols to new values (numeric or symbolic).

Returns:

Copy of self with replaced parameters.

parityos.operators.rotation_operator.get_concrete_rotation(rotation_type: type[SingleAngleRotationT_co], qubits: Sequence[QubitT], angle: Symbolic | complex) SingleAngleRotationT_co

Create a concrete single angle rotation operator from given type, qubits and angle.

Disambiguates between different types of concrete rotation operators with different __init__ signatures and calls the correct constructor based on the input.

Parameters:
  • rotation_type – Concrete single angle rotation type to create.

  • qubits – Qubits of the concrete rotation to create.

  • angle – Angle of the concrete rotation to create.

Returns:

An instance of rotation_type with given qubits and angle.

Raises:
class parityos.operators.rotation_operator.HasAngle(angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: object

Mixin that defines an angle attribute.

angle: Symbolic | complex

The angle that parametrizes this object

class parityos.operators.rotation_operator.SingleAngleRotation(angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: HasAngle, RotationOperator[QubitT_co, HermitianT_co], ABC

Interface for rotation operators with a single angle and operator (product) as exponent.

get_hermitian_conjugate() Self

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

property parameters: frozenset[Parameter]

The symbolic parameters parameterizing this object.

substitute_parameters(old_to_new: Mapping[Parameter, Symbolic | complex]) Self

Substitute symbolic parameters with new symbolic expressions or numeric values.

Parameters:

old_to_new – Mapping from existing parameter symbols to new values (numeric or symbolic).

Returns:

Copy of self with replaced parameters.

class parityos.operators.rotation_operator.SingleAngleRotationT_co

A covariant TypeVar representing a SingleAngleRotation.

alias of TypeVar(‘SingleAngleRotationT_co’, bound=SingleAngleRotation, covariant=True)

class parityos.operators.rotation_operator.HasSingleOperatorExponent(angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: SingleAngleRotation[QubitT_co, HermitianT_co], ABC

Mixin class for rotation operators with single operator exponents.

property exponent: OperatorPolynomial[HermitianT_co]

The hermitian operator in the exponent defining the rotation axis.

class parityos.operators.rotation_operator.HasOperatorProductExponent(angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: SingleAngleRotation[QubitT_co, HermitianSingleT_co], ABC

Mixin class for rotation operators with operator product exponents.

property exponent: OperatorPolynomial[HermitianSingleT_co]

The hermitian operator in the exponent defining the rotation axis.

class parityos.operators.rotation_operator.SingleQubitRotation(qubit: QubitT_co, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: HasSingleOperatorExponent[QubitT_co, HermitianSingleT_co], SingleQubitOperator[QubitT_co], ABC

Interface for single qubit rotations with one single qubit operator as exponent.

Examples: RX, RY, RZ.

qubit: QubitT_co

The single qubit this operator acts on.

class parityos.operators.rotation_operator.SingleQubitRotationT_co

A covariant TypeVar representing a SingleQubitRotation.

alias of TypeVar(‘SingleQubitRotationT_co’, bound=SingleQubitRotation, covariant=True)

class parityos.operators.rotation_operator.UnorderedMultiQubitProductRotation(qubits: Iterable[QubitT_co], angle: Coefficient = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: HasOperatorProductExponent[QubitT_co, HermitianSingleT_co], UnorderedMultiQubitOperator[QubitT_co], ABC

Base class for multi-qubit rotation with a product of single-qubit operators as exponent, that is symmetric under operator permutations.

Examples: RXX, RYY, RZZ

class parityos.operators.rotation_operator.UnorderedMultiQubitRotation(qubits: Iterable[QubitT_co], angle: Coefficient = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: HasSingleOperatorExponent[QubitT_co, HermitianUnorderedMultiT_co], UnorderedMultiQubitOperator[QubitT_co], ABC

Interface for multi-qubit rotations with one multi-qubit operator as exponent acting on an unordered set of qubits, that is symmetric under qubit permutation.

Example: RExchangeTerm

class parityos.operators.rotation_operator.UnorderedMultiQubitRotationT_co

A covariant TypeVar representing an UnorderedMultiQubitProductRotation or an UnorderedMultiQubitRotation.

alias of TypeVar(‘UnorderedMultiQubitRotationT_co’, bound=UnorderedMultiQubitProductRotation | UnorderedMultiQubitRotation, covariant=True)

class parityos.operators.rotation_operator.OrderedMultiQubitRotation(ordered_qubits, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: HasSingleOperatorExponent[QubitT_co, HermitianOrderedMultiT_co], OrderedMultiQubitOperator[QubitT_co], ABC

Interface for multi-qubit rotations with one multi-qubit operator as exponent acting on an ordered sequence of qubits.

class parityos.operators.rotation_operator.OrderedMultiQubitProductRotation(ordered_qubits, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: HasOperatorProductExponent[QubitT_co, HermitianSingleT_co], OrderedMultiQubitOperator[QubitT_co], ABC

Base class for multi-qubit rotation with an ordered product of single-qubit operators as exponent.

Example: RXZ

class parityos.operators.rotation_operator.OrderedMultiQubitT_co

A covariant TypeVar representing an OrderedMultiQubitRotation or an OrderedMultiQubitProductRotation.

alias of TypeVar(‘OrderedMultiQubitT_co’, bound=OrderedMultiQubitRotation | OrderedMultiQubitProductRotation, covariant=True)

final class parityos.operators.rotation_operator.RX(qubit: QubitT_co, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: SingleQubitRotation[QubitT_co, X[QubitT_co]]

Rotation by \(\varphi\) = angle around the X axis.

\[\mathrm{RX}(\varphi) = \exp\left(- i\frac{\varphi}{2} X\right)\]
exponent_type

alias of X

final class parityos.operators.rotation_operator.RY(qubit: QubitT_co, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: SingleQubitRotation[QubitT_co, Y[QubitT_co]]

Rotation by \(\varphi\) = angle around the Y axis.

\[\mathrm{RY}(\varphi) = \exp\left(- i\frac{\varphi}{2} Y\right)\]
exponent_type

alias of Y

final class parityos.operators.rotation_operator.RZ(qubit: QubitT_co, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: SingleQubitRotation[QubitT_co, Z[QubitT_co]]

Rotation by \(\varphi\) = angle around the Z axis.

\[\mathrm{RZ}(\varphi) = \exp\left(- i\frac{\varphi}{2} Z\right)\]
exponent_type

alias of Z

final class parityos.operators.rotation_operator.RXX(qubits: Iterable[QubitT_co], angle: Coefficient = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: UnorderedMultiQubitProductRotation[QubitT_co, X[QubitT_co]]

Joint two-qubit rotation by \(\varphi\) = angle around the X axis.

\[\mathrm{RXX}(\varphi) = \exp\left(- i\frac{\varphi}{2} X \otimes X\right)\]
n_qubits: ClassVar[int] = 2

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

final class parityos.operators.rotation_operator.RYY(qubits: Iterable[QubitT_co], angle: Coefficient = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: UnorderedMultiQubitProductRotation[QubitT_co, Y[QubitT_co]]

Joint two-qubit rotation by \(\varphi\) = angle around the Y axis.

\[\mathrm{RYY}(\varphi) = \exp\left(- i\frac{\varphi}{2} Y \otimes Y\right)\]
n_qubits: ClassVar[int] = 2

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

final class parityos.operators.rotation_operator.RZZ(qubits: Iterable[QubitT_co], angle: Coefficient = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: UnorderedMultiQubitProductRotation[QubitT_co, Z[QubitT_co]]

Joint two-qubit rotation by \(\varphi\) = angle around the Z axis.

\[\mathrm{RZZ}(\varphi) = \exp\left(- i\frac{\varphi}{2} Z \otimes Z\right)\]
n_qubits: ClassVar[int] = 2

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

final class parityos.operators.rotation_operator.RXZ(ordered_qubits, angle: Symbolic | complex = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: OrderedMultiQubitProductRotation[QubitT_co, X[QubitT_co] | Z[QubitT_co]]

Joint two-qubit rotation by \(\varphi\) = angle around the XZ axis.

\[\mathrm{RXZ}(\varphi) = \exp\left(- i\frac{\varphi}{2} X \otimes Z\right)\]
n_qubits: ClassVar[int] = 2

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

final class parityos.operators.rotation_operator.RExchangeTerm(qubits: Iterable[QubitT_co], angle: Coefficient = Parameter(name='DEFAULT_ANGLE', assumptions=ParameterAssumptions(zero=None, nonzero=None, positive=None, negative=None, rational=None, irrational=None, integer=None, even=None, odd=None, real=True, finite=True)))

Bases: UnorderedMultiQubitRotation[QubitT_co, ExchangeTerm[QubitT_co]]

Evolution under the Exchange Interaction.

\[\mathrm{REx}(\varphi) = \exp\left(- i\frac{\varphi}{2} \left[X \otimes X + Y \otimes Y\right]\right)\]
n_qubits: ClassVar[int] = 2

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

exponent_type

alias of ExchangeTerm