# PauliList¶

class PauliList(data)[source]

Bases: qiskit.quantum_info.operators.symplectic.base_pauli.BasePauli, qiskit.quantum_info.operators.mixins.linear.LinearMixin, qiskit.quantum_info.operators.mixins.group.GroupMixin

List of N-qubit Pauli operators.

This class is an efficient representation of a list of Pauli operators. It supports 1D numpy array indexing returning a Pauli for integer indexes or a PauliList for slice or list indices.

Initialization

A PauliList object can be initialized in several ways.

PauliList(list[str])

where strings are same representation with Pauli.

PauliList(Pauli) and PauliList(list[Pauli])

where Pauli is Pauli.

PauliList.from_symplectic(z, x, phase)

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

For example,

import numpy as np

from qiskit.quantum_info import Pauli, PauliList

# 1. init from list[str]
pauli_list = PauliList(["II", "+ZI", "-iYY"])
print("1. ", pauli_list)

pauli1 = Pauli("iXI")
pauli2 = Pauli("iZZ")

# 2. init from Pauli
print("2. ", PauliList(pauli1))

# 3. init from list[Pauli]
print("3. ", PauliList([pauli1, pauli2]))

# 4. init from np.ndarray
z = np.array([[True, True], [False, False]])
x = np.array([[False, True], [True, False]])
phase = np.array([0, 1])
pauli_list = PauliList.from_symplectic(z, x)
print("4. ", pauli_list)

1.  ['II', 'ZI', '-iYY']
2.  ['iXI']
3.  ['iXI', 'iZZ']
4.  ['YZ', 'IX']


Data Access

The individual Paulis can be accessed and updated using the [] operator which accepts integer, lists, or slices for selecting subsets of PauliList. If integer is given, it returns Pauli not PauliList.

pauli_list = PauliList(["XX", "ZZ", "IZ"])
print("Integer: ", repr(pauli_list[1]))
print("List: ", repr(pauli_list[[0, 2]]))
print("Slice: ", repr(pauli_list[0:2]))

Integer:  Pauli('ZZ')
List:  PauliList(['XX', 'IZ'])
Slice:  PauliList(['XX', 'ZZ'])


Iteration

Rows in the Pauli table can be iterated over like a list. Iteration can also be done using the label or matrix representation of each row using the label_iter() and matrix_iter() methods.

Initialize the PauliList.

Parameters

data (Pauli or list) -- input data for Paulis. If input is a list each item in the list must be a Pauli object or Pauli str.

Raises

QiskitError -- if input array is invalid shape.

The input array is not copied so multiple Pauli tables can share the same underlying array.

Methods

 adjoint Return the adjoint of each Pauli in the list. anticommutes Return True if other Pauli that anticommutes with other. anticommutes_with_all Return indexes of rows that commute other. argsort Return indices for sorting the rows of the table. commutes Return True for each Pauli that commutes with other. commutes_with_all Return indexes of rows that commute other. compose Return the composition self∘other for each Pauli in the list. conjugate Return the conjugate of each Pauli in the list. copy Make a deep copy of current operator. delete Return a copy with Pauli rows deleted from table. dot Return the composition other∘self for each Pauli in the list. equiv Entrywise comparison of Pauli equivalence up to global phase. evolve Evolve the Pauli by a Clifford. expand Return the expand product of each Pauli in the list. from_symplectic Construct a PauliList from a symplectic data. input_dims Return tuple of input dimension for specified subsystems. insert Insert Pauli's into the table. inverse Return the inverse of each Pauli in the list. label_iter Return a label representation iterator. matrix_iter Return a matrix representation iterator. output_dims Return tuple of output dimension for specified subsystems. power Return the compose of a operator with itself n times. reshape Return a shallow copy with reshaped input and output subsystem dimensions. sort Sort the rows of the table. tensor Return the tensor product with each Pauli in the list. to_labels Convert a PauliList to a list Pauli string labels. to_matrix Convert to a list or array of Pauli matrices. transpose Return the transpose of each Pauli in the list. unique Return unique Paulis from the table.

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 phase exponent of the PauliList.

qargs

Return the qargs for the operator.

settings

Return operator settings.

shape

The full shape of the array()

size

The number of Pauli rows in the table.

x

The x array for the symplectic representation.

z

The z array for the symplectic representation.