PauliList#
- class qiskit.quantum_info.PauliList(data)[código fonte]#
Bases:
BasePauli
,LinearMixin
,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 aPauli
for integer indexes or aPauliList
for slice or list indices.Initialization
A PauliList object can be initialized in several ways.
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, phase) print("4. ", pauli_list)
1. ['II', 'ZI', '-iYY'] 2. ['iXI'] 3. ['iXI', 'iZZ'] 4. ['YZ', '-iIX']
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()
andmatrix_iter()
methods.Initialize the PauliList.
- Parâmetros:
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.
- Levanta:
QiskitError – if input array is invalid shape.
- Additional Information:
The input array is not copied so multiple Pauli tables can share the same underlying array.
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 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.
Methods
- adjoint()[código fonte]#
Return the adjoint of each Pauli in the list.
- anticommutes(other, qargs=None)[código fonte]#
Return
True
if other Pauli that anticommutes with other.
- anticommutes_with_all(other)[código fonte]#
Return indexes of rows that commute other.
If
other
is a multi-row Pauli list the returned vector indexes rows of the current PauliList that anti-commute with all Paulis in other. If no rows satisfy the condition the returned array will be empty.- Parâmetros:
other (PauliList) – a single Pauli or multi-row PauliList.
- Retorno:
index array of the anti-commuting rows.
- Tipo de retorno:
array
- argsort(weight=False, phase=False)[código fonte]#
Return indices for sorting the rows of the table.
The default sort method is lexicographic sorting by qubit number. By using the weight kwarg the output can additionally be sorted by the number of non-identity terms in the Pauli, where the set of all Paulis of a given weight are still ordered lexicographically.
- commutes(other, qargs=None)[código fonte]#
Return True for each Pauli that commutes with other.
- commutes_with_all(other)[código fonte]#
Return indexes of rows that commute
other
.If
other
is a multi-row Pauli list the returned vector indexes rows of the current PauliList that commute with all Paulis in other. If no rows satisfy the condition the returned array will be empty.- Parâmetros:
other (PauliList) – a single Pauli or multi-row PauliList.
- Retorno:
index array of the commuting rows.
- Tipo de retorno:
array
- compose(other, qargs=None, front=False, inplace=False)[código fonte]#
Return the composition self∘other for each Pauli in the list.
- Parâmetros:
- Retorno:
the list of composed Paulis.
- Tipo de retorno:
- Levanta:
QiskitError – if other cannot be converted to a PauliList, does not have either 1 or the same number of Paulis as the current list, or has the wrong number of qubits for the specified
qargs
.
- conjugate()[código fonte]#
Return the conjugate of each Pauli in the list.
- copy()#
Make a deep copy of current operator.
- delete(ind, qubit=False)[código fonte]#
Return a copy with Pauli rows deleted from table.
When deleting qubits the qubit index is the same as the column index of the underlying
X
andZ
arrays.- Parâmetros:
- Retorno:
the resulting table with the entries removed.
- Tipo de retorno:
- Levanta:
QiskitError – if
ind
is out of bounds for the array size or number of qubits.
- dot(other, qargs=None, inplace=False)[código fonte]#
Return the composition other∘self for each Pauli in the list.
- Parâmetros:
- Retorno:
the list of composed Paulis.
- Tipo de retorno:
- Levanta:
QiskitError – if other cannot be converted to a PauliList, does not have either 1 or the same number of Paulis as the current list, or has the wrong number of qubits for the specified
qargs
.
- equiv(other)[código fonte]#
Entrywise comparison of Pauli equivalence up to global phase.
- evolve(other, qargs=None, frame='h')[código fonte]#
Performs either Heisenberg (default) or Schrödinger picture evolution of the Pauli by a Clifford and returns the evolved Pauli.
Schrödinger picture evolution can be chosen by passing parameter
frame='s'
. This option yields a faster calculation.Heisenberg picture evolves the Pauli as \(P^\prime = C^\dagger.P.C\).
Schrödinger picture evolves the Pauli as \(P^\prime = C.P.C^\dagger\).
- Parâmetros:
other (Pauli or Clifford or QuantumCircuit) – The Clifford operator to evolve by.
qargs (list) – a list of qubits to apply the Clifford to.
frame (string) –
'h'
for Heisenberg (default) or's'
for Schrödinger framework.
- Retorno:
the Pauli \(C^\dagger.P.C\) (Heisenberg picture) or the Pauli \(C.P.C^\dagger\) (Schrödinger picture).
- Tipo de retorno:
- Levanta:
QiskitError – if the Clifford number of qubits and qargs don’t match.
- expand(other)[código fonte]#
Return the expand product of each Pauli in the list.
- Parâmetros:
other (PauliList) – another PauliList.
- Retorno:
the list of tensor product Paulis.
- Tipo de retorno:
- Levanta:
QiskitError – if other cannot be converted to a PauliList, does not have either 1 or the same number of Paulis as the current list.
- classmethod from_symplectic(z, x, phase=0)[código fonte]#
Construct a PauliList from a symplectic data.
- Parâmetros:
z (np.ndarray) – 2D boolean Numpy array.
x (np.ndarray) – 2D boolean Numpy array.
phase (np.ndarray or None) – Optional, 1D integer array from Z_4.
- Retorno:
the constructed PauliList.
- Tipo de retorno:
- group_commuting(qubit_wise=False)[código fonte]#
Partition a PauliList into sets of commuting Pauli strings.
- Parâmetros:
qubit_wise (bool) –
whether the commutation rule is applied to the whole operator, or on a per-qubit basis. For example:
>>> from qiskit.quantum_info import PauliList >>> op = PauliList(["XX", "YY", "IZ", "ZZ"]) >>> op.group_commuting() [PauliList(['XX', 'YY']), PauliList(['IZ', 'ZZ'])] >>> op.group_commuting(qubit_wise=True) [PauliList(['XX']), PauliList(['YY']), PauliList(['IZ', 'ZZ'])]
- Retorno:
List of PauliLists where each PauliList contains commuting Pauli operators.
- Tipo de retorno:
- group_qubit_wise_commuting()[código fonte]#
Partition a PauliList into sets of mutually qubit-wise commuting Pauli strings.
- input_dims(qargs=None)#
Return tuple of input dimension for specified subsystems.
- insert(ind, value, qubit=False)[código fonte]#
Insert Paulis into the table.
When inserting qubits the qubit index is the same as the column index of the underlying
X
andZ
arrays.- Parâmetros:
- Retorno:
the resulting table with the entries inserted.
- Tipo de retorno:
- Levanta:
QiskitError – if the insertion index is invalid.
- inverse()[código fonte]#
Return the inverse of each Pauli in the list.
- label_iter()[código fonte]#
Return a label representation iterator.
This is a lazy iterator that converts each row into the string label only as it is used. To convert the entire table to labels use the
to_labels()
method.- Retorno:
label iterator object for the PauliList.
- Tipo de retorno:
LabelIterator
- matrix_iter(sparse=False)[código fonte]#
Return a matrix representation iterator.
This is a lazy iterator that converts each row into the Pauli matrix representation only as it is used. To convert the entire table to matrices use the
to_matrix()
method.- Parâmetros:
sparse (bool) – optionally return sparse CSR matrices if
True
, otherwise return Numpy array matrices (Default:False
)- Retorno:
matrix iterator object for the PauliList.
- Tipo de retorno:
MatrixIterator
- output_dims(qargs=None)#
Return tuple of output dimension for specified subsystems.
- power(n)#
Return the compose of a operator with itself n times.
- Parâmetros:
n (int) – the number of times to compose with self (n>0).
- Retorno:
the n-times composed operator.
- Tipo de retorno:
- Levanta:
QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.
- reshape(input_dims=None, output_dims=None, num_qubits=None)#
Return a shallow copy with reshaped input and output subsystem dimensions.
- Parâmetros:
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].
- Retorno:
returns self with reshaped input and output dimensions.
- Tipo de retorno:
BaseOperator
- Levanta:
QiskitError – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.
- sort(weight=False, phase=False)[código fonte]#
Sort the rows of the table.
The default sort method is lexicographic sorting by qubit number. By using the weight kwarg the output can additionally be sorted by the number of non-identity terms in the Pauli, where the set of all Paulis of a given weight are still ordered lexicographically.
Example
Consider sorting all a random ordering of all 2-qubit Paulis
from numpy.random import shuffle from qiskit.quantum_info.operators import PauliList # 2-qubit labels labels = ['II', 'IX', 'IY', 'IZ', 'XI', 'XX', 'XY', 'XZ', 'YI', 'YX', 'YY', 'YZ', 'ZI', 'ZX', 'ZY', 'ZZ'] # Shuffle Labels shuffle(labels) pt = PauliList(labels) print('Initial Ordering') print(pt) # Lexicographic Ordering srt = pt.sort() print('Lexicographically sorted') print(srt) # Weight Ordering srt = pt.sort(weight=True) print('Weight sorted') print(srt)
Initial Ordering ['YX', 'ZZ', 'XZ', 'YI', 'YZ', 'II', 'XX', 'XI', 'XY', 'YY', 'IX', 'IZ', 'ZY', 'ZI', 'ZX', 'IY'] Lexicographically sorted ['II', 'IX', 'IY', 'IZ', 'XI', 'XX', 'XY', 'XZ', 'YI', 'YX', 'YY', 'YZ', 'ZI', 'ZX', 'ZY', 'ZZ'] Weight sorted ['II', 'IX', 'IY', 'IZ', 'XI', 'YI', 'ZI', 'XX', 'XY', 'XZ', 'YX', 'YY', 'YZ', 'ZX', 'ZY', 'ZZ']
- tensor(other)[código fonte]#
Return the tensor product with each Pauli in the list.
- Parâmetros:
other (PauliList) – another PauliList.
- Retorno:
the list of tensor product Paulis.
- Tipo de retorno:
- Levanta:
QiskitError – if other cannot be converted to a PauliList, does not have either 1 or the same number of Paulis as the current list.
- to_labels(array=False)[código fonte]#
Convert a PauliList to a list Pauli string labels.
For large PauliLists converting using the
array=True
kwarg will be more efficient since it allocates memory for the full Numpy array of labels in advance.Table 3 Pauli Representations# Label
Symplectic
Matrix
"I"
\([0, 0]\)
\(\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\)
"X"
\([1, 0]\)
\(\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\)
"Y"
\([1, 1]\)
\(\begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\)
"Z"
\([0, 1]\)
\(\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\)
- to_matrix(sparse=False, array=False)[código fonte]#
Convert to a list or array of Pauli matrices.
For large PauliLists converting using the
array=True
kwarg will be more efficient since it allocates memory a full rank-3 Numpy array of matrices in advance.Table 4 Pauli Representations# Label
Symplectic
Matrix
"I"
\([0, 0]\)
\(\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\)
"X"
\([1, 0]\)
\(\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\)
"Y"
\([1, 1]\)
\(\begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\)
"Z"
\([0, 1]\)
\(\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\)
- Parâmetros:
- Retorno:
A list of dense Pauli matrices if
array=False` and ``sparse=False`. list: A list of sparse Pauli matrices if ``array=False
andsparse=True
. array: A dense rank-3 array of Pauli matrices ifarray=True
.- Tipo de retorno:
- transpose()[código fonte]#
Return the transpose of each Pauli in the list.
- unique(return_index=False, return_counts=False)[código fonte]#
Return unique Paulis from the table.
Example
from qiskit.quantum_info.operators import PauliList pt = PauliList(['X', 'Y', '-X', 'I', 'I', 'Z', 'X', 'iZ']) unique = pt.unique() print(unique)
['X', 'Y', '-X', 'I', 'Z', 'iZ']
- Parâmetros:
- Retorno:
- unique
the table of the unique rows.
- unique_indices: np.ndarray, optional
The indices of the first occurrences of the unique values in the original array. Only provided if
return_index
isTrue
.- unique_counts: np.array, optional
The number of times each of the unique values comes up in the original array. Only provided if
return_counts
isTrue
.
- Tipo de retorno: