mimiqcircuits.operations.gates.generalized.paulistring

PauliString definition.

Functions

convert_pauli(x)

Return the single qubit gate for a Pauli character.

Classes

PauliString(pauli)

Tensor product of Pauli operators on \(N\) qubits.

class PauliString(pauli)[source]

Bases: Gate

Tensor product of Pauli operators on \(N\) qubits.

Represents \(P_1 \otimes P_2 \otimes \dots \otimes P_N\) with each \(P_i \in \{I, X, Y, Z\}\). The \(i\)-th character of the string acts on the \(i\)-th target qubit. A Pauli string is its own inverse and can only be raised to integer powers.

Parameters:

pauli (str | chr) – A non-empty string of "I", "X", "Y" and "Z" characters, for example "IXXYZ".

Raises:

ValueError – If the string is empty or contains other characters.

Examples

>>> from mimiqcircuits import *
>>> g = PauliString("XYZ")
>>> g.matrix()
[0, 0, 0, 0, 0, 0, 0.0 - 1.0*I, 0]
[0, 0, 0, 0, 0, 0, 0, 0.0 + 1.0*I]
[0, 0, 0, 0, 0.0 + 1.0*I, 0, 0, 0]
[0, 0, 0, 0, 0, 0.0 - 1.0*I, 0, 0]
[0, 0, 0.0 - 1.0*I, 0, 0, 0, 0, 0]
[0, 0, 0, 0.0 + 1.0*I, 0, 0, 0, 0]
[0.0 + 1.0*I, 0, 0, 0, 0, 0, 0, 0]
[0, 0.0 - 1.0*I, 0, 0, 0, 0, 0, 0]

>>> c = Circuit()
>>> c.push(PauliString("XYZ"), 0, 1, 2)
3-qubit circuit with 1 instruction:
└── XYZ @ q[0:2]

>>> g.power(2), g.inverse()
(III, XYZ)
>>> g.decompose()
3-qubit circuit with 3 instructions:
├── X @ q[0]
├── Y @ q[1]
└── Z @ q[2]
classmethod from_string(pauli_expr)[source]

Build a PauliString from a string; same as PauliString(pauli_expr).

property num_qubits

Number of qubits, the length of the string.

property parnames

("pauli",).

Type:

Parameter names

inverse()[source]

Return the inverse of the gate.

Gates with a known inverse return it directly (for example GateS().inverse() is GateSDG()); otherwise the gate is wrapped in Inverse.

unwrappedmatrix()[source]

Return the matrix as a NumPy array with dtype complex128.

unwrapped_matrix()[source]

Return the matrix as a NumPy array of SymEngine numbers (dtype=object).

is_identity()[source]

Return True if every character is "I". Same as isidentity().

evaluate(d)[source]

Return self: a Pauli string has no symbolic parameters.

isidentity()[source]

Return True if every character is "I".