# qiskit.quantum_info.Pauli¶

class Pauli(data=None, x=None, *, z=None, label=None)[Quellcode]

N-qubit Pauli operator.

This class represents an operator $$P$$ from the full $$n$$-qubit Pauli group

$P = (-i)^{q} P_{n-1} \otimes ... \otimes P_{0}$

where $$q\in \mathbb{Z}_4$$ and $$P_i \in \{I, X, Y, Z\}$$ are single-qubit Pauli matrices:

$\begin{split}I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}, X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}, Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}.\end{split}$

Initialization

A Pauli object can be initialized in several ways:

Pauli(obj)

where obj is a Pauli string, Pauli or ScalarOp operator, or a Pauli gate or QuantumCircuit containing only Pauli gates.

Pauli((z, x, phase))

where z and x are boolean numpy.ndarrays and phase is an integer in [0, 1, 2, 3].

Pauli((z, x))

equivalent to Pauli((z, x, 0)) with trivial phase.

String representation

An $$n$$-qubit Pauli may be represented by a string consisting of $$n$$ characters from ['I', 'X', 'Y', 'Z'], and optionally phase coefficient in $$['', '-i', '-', 'i']$$. For example: XYZ or '-iZIZ'.

In the string representation qubit-0 corresponds to the right-most Pauli character, and qubit-$$(n-1)$$ to the left-most Pauli character. For example 'XYZ' represents $$X\otimes Y \otimes Z$$ with 'Z' on qubit-0, 'Y' on qubit-1, and 'X' on qubit-3.

The string representation can be converted to a Pauli using the class initialization (Pauli('-iXYZ')). A Pauli object can be converted back to the string representation using the to_label() method or str(pauli).

Bemerkung

Using str to convert a Pauli to a string will truncate the returned string for large numbers of qubits while to_label() will return the full string with no truncation. The default truncation length is 50 characters. The default value can be changed by setting the class __truncate__ attribute to an integer value. If set to 0 no truncation will be performed.

Array Representation

The internal data structure of an $$n$$-qubit Pauli is two length-$$n$$ boolean vectors $$z \in \mathbb{Z}_2^N$$, $$x \in \mathbb{Z}_2^N$$, and an integer $$q \in \mathbb{Z}_4$$ defining the Pauli operator

$P &= (-i)^{q + z\cdot x} Z^z \cdot X^x.$

The $$k$$ and $$x$$ arrays

$\begin{split}P &= P_{n-1} \otimes ... \otimes P_{0} \\ P_k &= (-i)^{z[k] * x[k]} Z^{z[k]}\cdot X^{x[k]}\end{split}$

where z[k] = P.z[k], x[k] = P.x[k] respectively.

The $$z$$ and $$x$$ arrays can be accessed and updated using the z and x properties respectively. The phase integer $$q$$ can be accessed and updated using the phase property.

Matrix Operator Representation

Pauli’s can be converted to $$(2^n, 2^n)$$ Operator using the to_operator() method, or to a dense or sparse complex matrix using the to_matrix() method.

Data Access

The individual qubit Paulis can be accessed and updated using the [] operator which accepts integer, lists, or slices for selecting subsets of Paulis. Note that selecting subsets of Pauli’s will discard the phase of the current Pauli.

For example

Initialize the Pauli.

When using the symplectic array input data both z and x arguments must be provided, however the first (z) argument can be used alone for string label, Pauli operator, or ScalarOp input data.

Parameter
• data (str or tuple or Pauli or ScalarOp) – input data for Pauli. If input is a tuple it must be of the form (z, x) or (z, x, phase) where z and x are boolean Numpy arrays, and phase is an integer from Z_4.

• x (np.ndarray) – DEPRECATED, symplectic x vector.

• z (np.ndarray) – DEPRECATED, symplectic z vector.

• label (str) – DEPRECATED, string label.

Verursacht

QiskitError – if input array is invalid shape.

__init__(data=None, x=None, *, z=None, label=None)[Quellcode]

Initialize the Pauli.

When using the symplectic array input data both z and x arguments must be provided, however the first (z) argument can be used alone for string label, Pauli operator, or ScalarOp input data.

Parameter
• data (str or tuple or Pauli or ScalarOp) – input data for Pauli. If input is a tuple it must be of the form (z, x) or (z, x, phase) where z and x are boolean Numpy arrays, and phase is an integer from Z_4.

• x (np.ndarray) – DEPRECATED, symplectic x vector.

• z (np.ndarray) – DEPRECATED, symplectic z vector.

• label (str) – DEPRECATED, string label.

Verursacht

QiskitError – if input array is invalid shape.

Methods

 __init__([data, x, z, label]) Initialize the Pauli. Return the adjoint of the Operator. anticommutes(other[, qargs]) Return True if other Pauli anticommutes with self. append_paulis([paulis, pauli_labels]) DEPRECATED: Append pauli at the end. commutes(other[, qargs]) Return True if the Pauli commutes with other. compose(other[, qargs, front, inplace]) Return the operator composition with another Pauli. Return the conjugate of each Pauli in the list. Make a deep copy of current operator. delete(qubits) Return a Pauli with qubits deleted. delete_qubits(indices) DEPRECATED: Delete pauli at the indices. dot(other[, qargs, inplace]) Return the right multiplied operator self * other. equiv(other) Return True if Pauli’s are equivalent up to group phase. evolve(other[, qargs]) Heisenberg picture evolution of a Pauli by a Clifford. expand(other) Return the reverse-order tensor product with another Pauli. from_label(*args, **kwargs) DEPRECATED: Construct a Pauli from a string label. input_dims([qargs]) Return tuple of input dimension for specified subsystems. insert(qubits, value) Insert a Pauli at specific qubit value. insert_paulis([indices, paulis, pauli_labels]) DEPRECATED: Insert or append pauli to the targeted indices. Return the inverse of the Pauli. kron(other) DEPRECATED: Kronecker product of two paulis. output_dims([qargs]) Return tuple of output dimension for specified subsystems. pauli_single(num_qubits, index, pauli_label) DEPRECATED: Generate single qubit pauli at index with pauli_label with length num_qubits. Return the compose of a operator with itself n times. random(num_qubits[, seed]) DEPRECATED: Return a random Pauli on number of qubits. reshape([input_dims, output_dims, num_qubits]) Return a shallow copy with reshaped input and output subsystem dimensions. Set the max number of Pauli characters to display before truncation/ sgn_prod(*args, **kwargs) DEPRECATED: Multiply two Paulis and track the phase. tensor(other) Return the tensor product with another Pauli. Convert to Pauli circuit instruction. Convert a Pauli to a string label. to_matrix([sparse]) Convert to a Numpy array or sparse CSR matrix. DEPRECATED Convert Pauli to a sparse matrix representation (CSR format). Return the transpose of each Pauli in the list. update_x(x[, indices]) DEPRECATED: Update partial or entire x. update_z(z[, indices]) DEPRECATED: Update partial or entire z.

Attributes

 dim Return tuple (input_shape, output_shape). num_qubits Return the number of qubits if a N-qubit operator or None otherwise. phase Return the group phase exponent for the Pauli. qargs Return the qargs for the operator. x The x vector for the Pauli. z The z vector for the Pauli.
adjoint()[Quellcode]

Return the adjoint of the Operator.

anticommutes(other, qargs=None)[Quellcode]

Return True if other Pauli anticommutes with self.

Parameter
• other (Pauli) – another Pauli operator.

• qargs (list) – qubits to apply dot product on (default: None).

Rückgabe

True if Pauli’s anticommute, False if they commute.

Rückgabetyp

bool

append_paulis(paulis=None, pauli_labels=None)[Quellcode]

DEPRECATED: Append pauli at the end.

Parameter
• paulis (Pauli) – the to-be-inserted or appended pauli

• pauli_labels (list[str]) – the to-be-inserted or appended pauli label

Rückgabe

self

Rückgabetyp

Pauli

commutes(other, qargs=None)[Quellcode]

Return True if the Pauli commutes with other.

Parameter
• other (Pauli or PauliList) – another Pauli operator.

• qargs (list) – qubits to apply dot product on (default: None).

Rückgabe

True if Pauli’s commute, False if they anti-commute.

Rückgabetyp

bool

compose(other, qargs=None, front=False, inplace=False)[Quellcode]

Return the operator composition with another Pauli.

Parameter
• other (Pauli) – a Pauli object.

• qargs (list or None) – Optional, qubits to apply dot product on (default: None).

• front (bool) – If True compose using right operator multiplication, instead of left multiplication [default: False].

• inplace (bool) – If True update in-place (default: False).

Rückgabe

The composed Pauli.

Rückgabetyp

Pauli

Verursacht

QiskitError – if other cannot be converted to an operator, or has incompatible dimensions for specified subsystems.

Bemerkung

Composition (&) by default is defined as left matrix multiplication for matrix operators, while dot() is defined as right matrix multiplication. That is that A & B == A.compose(B) is equivalent to B.dot(A) when A and B are of the same type.

Setting the front=True kwarg changes this to right matrix multiplication and is equivalent to the dot() method A.dot(B) == A.compose(B, front=True).

conjugate()[Quellcode]

Return the conjugate of each Pauli in the list.

copy()

Make a deep copy of current operator.

delete(qubits)[Quellcode]

Return a Pauli with qubits deleted.

Parameter

qubits (int or list) – qubits to delete from Pauli.

Rückgabe

the resulting Pauli with the specified qubits removed.

Rückgabetyp

Pauli

Verursacht

QiskitError – if ind is out of bounds for the array size or number of qubits.

delete_qubits(indices)[Quellcode]

DEPRECATED: Delete pauli at the indices.

This function is deprecated. Equivalent functionality can be obtained using the delete() method.

Parameter

indices (list[int]) – the indices of to-be-deleted paulis

Rückgabe

self

Rückgabetyp

Pauli

property dim

Return tuple (input_shape, output_shape).

dot(other, qargs=None, inplace=False)[Quellcode]

Return the right multiplied operator self * other.

Parameter
• other (Pauli) – an operator object.

• qargs (list or None) – Optional, qubits to apply dot product on (default: None).

• inplace (bool) – If True update in-place (default: False).

Rückgabe

The operator self * other.

Rückgabetyp

Pauli

equiv(other)[Quellcode]

Return True if Pauli’s are equivalent up to group phase.

Parameter

other (Pauli) – an operator object.

Rückgabe

True if the Pauli’s are equivalent up to group phase.

Rückgabetyp

bool

evolve(other, qargs=None)[Quellcode]

Heisenberg picture evolution of a Pauli by a Clifford.

This returns the Pauli $$P^\prime = C^\dagger.P.C$$.

Parameter
• other (Pauli or Clifford or QuantumCircuit) – The Clifford operator to evolve by.

• qargs (list) – a list of qubits to apply the Clifford to.

Rückgabe

the Pauli $$C^\dagger.P.C$$.

Rückgabetyp

Pauli

Verursacht

QiskitError – if the Clifford number of qubits and qargs don’t match.

expand(other)[Quellcode]

Return the reverse-order tensor product with another Pauli.

Parameter

other (Pauli) – a Pauli object.

Rückgabe

the tensor product $$b \otimes a$$, where $$a$$

is the current Pauli, and $$b$$ is the other Pauli.

Rückgabetyp

Pauli

static from_label(*args, **kwargs)[Quellcode]

DEPRECATED: Construct a Pauli from a string label.

This function is deprecated use Pauli(label) instead.

Parameter

label (str) – Pauli string label.

Rückgabe

the constructed Pauli.

Rückgabetyp

Pauli

Verursacht
• QiskitError – If the input list is empty or contains invalid

• Pauli strings.

input_dims(qargs=None)

Return tuple of input dimension for specified subsystems.

insert(qubits, value)[Quellcode]

Insert a Pauli at specific qubit value.

Parameter
• qubits (int or list) – qubits index to insert at.

• value (Pauli) – value to insert.

Rückgabe

the resulting Pauli with the entries inserted.

Rückgabetyp

Pauli

Verursacht

QiskitError – if the insertion qubits are invalid.

insert_paulis(indices=None, paulis=None, pauli_labels=None)[Quellcode]

DEPRECATED: Insert or append pauli to the targeted indices.

This function is deprecated. Similar functionality can be obtained using the insert() method.

If indices is None, it means append at the end.

Parameter
• indices (list[int]) – the qubit indices to be inserted

• paulis (Pauli) – the to-be-inserted or appended pauli

• pauli_labels (list[str]) – the to-be-inserted or appended pauli label

Bemerkung

the indices refers to the location of original paulis, e.g. if indices = [0, 2], pauli_labels = [‚Z‘, ‚I‘] and original pauli = ‚ZYXI‘ the pauli will be updated to ZY’I’XI’Z‘ ‚Z‘ and ‚I‘ are inserted before the qubit at 0 and 2.

Rückgabe

self

Rückgabetyp

Pauli

Verursacht

QiskitError – provide both paulis and pauli_labels at the same time

inverse()[Quellcode]

Return the inverse of the Pauli.

kron(other)[Quellcode]

DEPRECATED: Kronecker product of two paulis.

This function is deprecated. Use expand() instead.

Order is $P_2 (other) otimes P_1 (self)$

Parameter

other (Pauli) – P2

Rückgabe

self

Rückgabetyp

Pauli

property num_qubits

Return the number of qubits if a N-qubit operator or None otherwise.

output_dims(qargs=None)

Return tuple of output dimension for specified subsystems.

classmethod pauli_single(num_qubits, index, pauli_label)[Quellcode]

DEPRECATED: Generate single qubit pauli at index with pauli_label with length num_qubits.

Parameter
• num_qubits (int) – the length of pauli

• index (int) – the qubit index to insert the single qubit

• pauli_label (str) – pauli

Rückgabe

single qubit pauli

Rückgabetyp

Pauli

property phase

Return the group phase exponent for the Pauli.

power(n)

Return the compose of a operator with itself n times.

Parameter

n (int) – the number of times to compose with self (n>0).

Rückgabe

the n-times composed operator.

Rückgabetyp

Pauli

Verursacht

QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.

property qargs

Return the qargs for the operator.

classmethod random(num_qubits, seed=None)[Quellcode]

DEPRECATED: Return a random Pauli on number of qubits.

This function is deprecated use random_pauli() instead.

Parameter
• num_qubits (int) – the number of qubits

• seed (int) – Optional. To set a random seed.

Rückgabe

the random pauli

Rückgabetyp

Pauli

reshape(input_dims=None, output_dims=None, num_qubits=None)

Return a shallow copy with reshaped input and output subsystem dimensions.

Parameter
• input_dims (None or tuple) – new subsystem input dimensions. If None the original input dims will be preserved [Default: None].

• output_dims (None or tuple) – new subsystem output dimensions. If None the original output dims will be preserved [Default: None].

• num_qubits (None or int) – reshape to an N-qubit operator [Default: None].

Rückgabe

returns self with reshaped input and output dimensions.

Rückgabetyp

BaseOperator

Verursacht

QiskitError – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.

classmethod set_truncation(val)[Quellcode]

Set the max number of Pauli characters to display before truncation/

Parameter

val (int) – the number of characters.

Bemerkung

Truncation will be disabled if the truncation value is set to 0.

static sgn_prod(*args, **kwargs)[Quellcode]

DEPRECATED: Multiply two Paulis and track the phase.

This function is deprecated. The Pauli class now handles full Pauli group multiplication using compose() or dot().

$P_3 = P_1 otimes P_2$: X*Y

Parameter
Rückgabe

the multiplied pauli (without phase) complex: the sign of the multiplication, 1, -1, 1j or -1j

Rückgabetyp

Pauli

tensor(other)[Quellcode]

Return the tensor product with another Pauli.

Parameter

other (Pauli) – a Pauli object.

Rückgabe

the tensor product $$a \otimes b$$, where $$a$$

is the current Pauli, and $$b$$ is the other Pauli.

Rückgabetyp

Pauli

Bemerkung

The tensor product can be obtained using the ^ binary operator. Hence a.tensor(b) is equivalent to a ^ b.

to_instruction()[Quellcode]

Convert to Pauli circuit instruction.

to_label()[Quellcode]

Convert a Pauli to a string label.

Bemerkung

The difference between to_label and __str__() is that the later will truncate the output for large numbers of qubits.

Rückgabe

the Pauli string label.

Rückgabetyp

str

to_matrix(sparse=False)[Quellcode]

Convert to a Numpy array or sparse CSR matrix.

Parameter

sparse (bool) – if True return sparse CSR matrices, otherwise return dense Numpy arrays (default: False).

Rückgabe

The Pauli matrix.

Rückgabetyp

array

to_spmatrix()[Quellcode]

DEPRECATED Convert Pauli to a sparse matrix representation (CSR format).

This function is deprecated. Use to_matrix() with kwarg sparse=True instead.

Rückgabe

a sparse matrix with CSR format that represents the pauli.

Rückgabetyp

scipy.sparse.csr_matrix

transpose()[Quellcode]

Return the transpose of each Pauli in the list.

update_x(x, indices=None)[Quellcode]

DEPRECATED: Update partial or entire x.

This function is deprecated. Use the setter for X instead.

Parameter
• x (numpy.ndarray or list) – to-be-updated x

• indices (numpy.ndarray or list or optional) – to-be-updated qubit indices

Rückgabe

self

Rückgabetyp

Pauli

Verursacht

QiskitError – when updating whole x, the number of qubits must be the same.

update_z(z, indices=None)[Quellcode]

DEPRECATED: Update partial or entire z.

This function is deprecated. Use the setter for Z instead.

Parameter
• z (numpy.ndarray or list) – to-be-updated z

• indices (numpy.ndarray or list or optional) – to-be-updated qubit indices

Rückgabe

self

Rückgabetyp

Pauli

Verursacht

QiskitError – when updating whole z, the number of qubits must be the same.

property x

The x vector for the Pauli.

property z

The z vector for the Pauli.