Shortcuts

# qiskit.quantum_info.PauliTable¶

class PauliTable(data)[소스]

Symplectic representation of a list Pauli matrices.

Symplectic Representation

The symplectic representation of a single-qubit Pauli matrix is a pair of boolean values $$[x, z]$$ such that the Pauli matrix is given by $$P = (-i)^{z * x} \sigma_z^z.\sigma_x^x$$. The correspondence between labels, symplectic representation, and matrices for single-qubit Paulis are shown in Table 1.

Table 8 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}$$

The full Pauli table is a M x 2N boolean matrix:

$\begin{split}\left(\begin{array}{ccc|ccc} x_{0,0} & ... & x_{0,N-1} & z_{0,0} & ... & z_{0,N-1} \\ x_{1,0} & ... & x_{1,N-1} & z_{1,0} & ... & z_{1,N-1} \\ \vdots & \ddots & \vdots & \vdots & \ddots & \vdots \\ x_{M-1,0} & ... & x_{M-1,N-1} & z_{M-1,0} & ... & z_{M-1,N-1} \end{array}\right)\end{split}$

where each row is a block vector $$[X_i, Z_i]$$ with $$X = [x_{i,0}, ..., x_{i,N-1}]$$, $$Z = [z_{i,0}, ..., z_{i,N-1}]$$ is the symplectic representation of an N-qubit Pauli. This representation is based on reference .

PauliTable’s can be created from a list of labels using from_labels(), and converted to a list of labels or a list of matrices using to_labels() and to_matrix() respectively.

Group Product

The Pauli’s in the Pauli table do not represent the full Pauli as they are restricted to having +1 phase. The dot-product for the Pauli’s is defined to discard any phase obtained from matrix multiplication so that we have $$X.Z = Z.X = Y$$, etc. This means that for the PauliTable class the operator methods compose() and dot() are equivalent.

A.B

I

X

Y

Z

I

I

X

Y

Z

X

X

I

Z

Y

Y

Y

Z

I

X

Z

Z

Y

X

I

Qubit Ordering

The qubits are ordered in the table such the least significant qubit [x_{i, 0}, z_{i, 0}] is the first element of each of the $$X_i, Z_i$$ vector blocks. This is the opposite order to position in string labels or matrix tensor products where the least significant qubit is the right-most string character. For example Pauli "ZX" has "X" on qubit-0 and "Z" on qubit 1, and would have symplectic vectors $$x=[1, 0]$$, $$z=[0, 1]$$.

Data Access

Subsets of rows can be accessed using the list access [] operator and will return a table view of part of the PauliTable. The underlying Numpy array can be directly accessed using the array property, and the sub-arrays for only the X or Z blocks can be accessed using the X and Z properties respectively.

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.

참조

1. S. Aaronson, D. Gottesman, Improved Simulation of Stabilizer Circuits, Phys. Rev. A 70, 052328 (2004). arXiv:quant-ph/0406196

Initialize the PauliTable.

매개변수

data (array or str or ScalarOp or PauliTable) – input data.

예외

QiskitError – if input array is invalid shape.

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

__init__(data)[소스]

Initialize the PauliTable.

매개변수

data (array or str or ScalarOp or PauliTable) – input data.

예외

QiskitError – if input array is invalid shape.

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

Methods

 __init__(data) Initialize the PauliTable. add(other) Return the linear operator self + other. Return the adjoint of the operator. Return indexes of rows that commute other. argsort([weight]) Return indices for sorting the rows of the table. commutes(pauli) Return list of commutation properties for each row with a Pauli. commutes_with_all(other) Return indexes of rows that commute other. compose(other[, qargs, front]) Return the compose output product of two tables. Not implemented. Make a deep copy of current operator. delete(ind[, qubit]) Return a copy with Pauli rows deleted from table. dot(other[, qargs]) Return the dot output product of two tables. expand(other) Return the expand output product of two tables. from_labels(labels) Construct a PauliTable from a list of Pauli strings. input_dims([qargs]) Return tuple of input dimension for specified subsystems. insert(ind, value[, qubit]) Insert Pauli’s into the table. Return a label representation iterator. matrix_iter([sparse]) Return a matrix representation iterator. multiply(other) Return the linear operator other * self. output_dims([qargs]) Return tuple of output dimension for specified subsystems. Return the compose of a operator with itself n times. reshape([input_dims, output_dims]) Return a shallow copy with reshaped input and output subsystem dimensions. set_atol(value) Set the class default absolute tolerance parameter for float comparisons. set_rtol(value) Set the class default relative tolerance parameter for float comparisons. sort([weight]) Sort the rows of the table. subtract(other) Return the linear operator self - other. tensor(other) Return the tensor output product of two tables. to_labels([array]) Convert a PauliTable to a list Pauli string labels. to_matrix([sparse, array]) Convert to a list or array of Pauli matrices. Not implemented. unique([return_index, return_counts]) Return unique Paulis from the table.

Attributes

 X The X block of the array. Z The Z block of the array. array The underlying boolean array. atol The default absolute tolerance parameter for float comparisons. dim Return tuple (input_shape, output_shape). num_qubits Return the number of qubits if a N-qubit operator or None otherwise. qargs Return the qargs for the operator. rtol The relative tolerance parameter for float comparisons. shape The full shape of the array() size The number of Pauli rows in the table.
property X

The X block of the array.

property Z

The Z block of the array.

add(other)

Return the linear operator self + other.

DEPRECATED: use operator + other instead.

매개변수

other (BaseOperator) – an operator object.

반환값

the operator self + other.

반환 형식

BaseOperator

adjoint()

Return the adjoint of the operator.

anticommutes_with_all(other)[소스]

Return indexes of rows that commute other.

If other is a multi-row Pauli table the returned vector indexes rows of the current PauliTable that anti-commute with all Pauli’s in other. If no rows satisfy the condition the returned array will be empty.

매개변수

other (PauliTable) – a single Pauli or multi-row PauliTable.

반환값

index array of the anti-commuting rows.

반환 형식

array

argsort(weight=False)[소스]

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 Pauli’s of a given weight are still ordered lexicographically.

매개변수

weight (bool) – optionally sort by weight if True (Default: False).

반환값

the indices for sorting the table.

반환 형식

array

property array

The underlying boolean array.

property atol

The default absolute tolerance parameter for float comparisons.

commutes(pauli)[소스]

Return list of commutation properties for each row with a Pauli.

The returned vector is the same length as the size of the table and contains True for rows that commute with the Pauli, and False for the rows that anti-commute.

매개변수

pauli (PauliTable) – a single Pauli row.

반환값

The boolean vector of which rows commute or anti-commute.

반환 형식

array

예외

QiskitError – if input is not a single Pauli row.

commutes_with_all(other)[소스]

Return indexes of rows that commute other.

If other is a multi-row Pauli table the returned vector indexes rows of the current PauliTable that commute with all Pauli’s in other. If no rows satisfy the condition the returned array will be empty.

매개변수

other (PauliTable) – a single Pauli or multi-row PauliTable.

반환값

index array of the commuting rows.

반환 형식

array

compose(other, qargs=None, front=True)[소스]

Return the compose output product of two tables.

This returns the combination of the dot product of all Paulis in the current table with all Pauli’s in the other table and discards the complex phase from the product. Note that for PauliTables this method is equivalent to dot() and hence the front kwarg does not change the output.

Example

from qiskit.quantum_info.operators import PauliTable

current = PauliTable.from_labels(['I', 'X'])
other =  PauliTable.from_labels(['Y', 'Z'])
print(current.compose(other))

PauliTable: ['Y', 'Z', 'Z', 'Y']

매개변수
• other (PauliTable) – another PauliTable.

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

• front (bool) – If True use dot composition method [default: False].

반환값

the compose outer product table.

반환 형식

PauliTable

예외

QiskitError – if other cannot be converted to a PauliTable.

conjugate()[소스]

Not implemented.

copy()

Make a deep copy of current operator.

delete(ind, qubit=False)[소스]

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 and Z arrays.

매개변수
• ind (int or list) – index(es) to delete.

• qubit (bool) – if True delete qubit columns, otherwise delete Pauli rows (Default: False).

반환값

the resulting table with the entries removed.

반환 형식

PauliTable

예외

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

property dim

Return tuple (input_shape, output_shape).

dot(other, qargs=None)[소스]

Return the dot output product of two tables.

This returns the combination of the dot product of all Paulis in the current table with all Pauli’s in the other table and discards the complex phase from the product. Note that for PauliTables this method is equivalent to compose().

Example

from qiskit.quantum_info.operators import PauliTable

current = PauliTable.from_labels(['I', 'X'])
other =  PauliTable.from_labels(['Y', 'Z'])
print(current.dot(other))

PauliTable: ['Y', 'Z', 'Z', 'Y']

매개변수
• other (PauliTable) – another PauliTable.

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

반환값

the dot outer product table.

반환 형식

PauliTable

예외

QiskitError – if other cannot be converted to a PauliTable.

expand(other)[소스]

Return the expand output product of two tables.

This returns the combination of the tensor product of all Paulis in the other table with all Pauli’s in the current table, with the current tables qubits being the least-significant in the returned table. This is the opposite tensor order to tensor().

Example

from qiskit.quantum_info.operators import PauliTable

current = PauliTable.from_labels(['I', 'X'])
other =  PauliTable.from_labels(['Y', 'Z'])
print(current.expand(other))

PauliTable: ['YI', 'ZI', 'YX', 'ZX']

매개변수

other (PauliTable) – another PauliTable.

반환값

the expand outer product table.

반환 형식

PauliTable

예외

QiskitError – if other cannot be converted to a PauliTable.

classmethod from_labels(labels)[소스]

Construct a PauliTable from a list of Pauli strings.

매개변수

labels (list) – Pauli string label(es).

반환값

the constructed PauliTable.

반환 형식

PauliTable

예외
• 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(ind, value, qubit=False)[소스]

Insert Pauli’s into the table.

When inserting qubits the qubit index is the same as the column index of the underlying X and Z arrays.

매개변수
• ind (int) – index to insert at.

• value (PauliTable) – values to insert.

• qubit (bool) – if True delete qubit columns, otherwise delete Pauli rows (Default: False).

반환값

the resulting table with the entries inserted.

반환 형식

PauliTable

예외

QiskitError – if the insertion index is invalid.

label_iter()[소스]

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.

반환값

label iterator object for the PauliTable.

반환 형식

LabelIterator

matrix_iter(sparse=False)[소스]

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.

매개변수

sparse (bool) – optionally return sparse CSR matrices if True, otherwise return Numpy array matrices (Default: False)

반환값

matrix iterator object for the PauliTable.

반환 형식

MatrixIterator

multiply(other)

Return the linear operator other * self.

DEPRECATED: use other * operator instead.

매개변수

other (complex) – a complex number.

반환값

the linear operator other * self.

반환 형식

BaseOperator

예외

NotImplementedError – if subclass does not support multiplication.

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.

power(n)

Return the compose of a operator with itself n times.

매개변수

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

반환값

the n-times composed operator.

반환 형식

BaseOperator

예외

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.

reshape(input_dims=None, output_dims=None)

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

Arg:
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].

반환값

returns self with reshaped input and output dimensions.

반환 형식

BaseOperator

예외

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

property rtol

The relative tolerance parameter for float comparisons.

classmethod set_atol(value)

Set the class default absolute tolerance parameter for float comparisons.

DEPRECATED: use operator.atol = value instead

classmethod set_rtol(value)

Set the class default relative tolerance parameter for float comparisons.

DEPRECATED: use operator.rtol = value instead

property shape

The full shape of the array()

property size

The number of Pauli rows in the table.

sort(weight=False)[소스]

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 Pauli’s 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 PauliTable

# 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 = PauliTable.from_labels(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
PauliTable: ['IY', 'ZY', 'XZ', 'XI', 'ZI', 'YZ', 'YX', 'II', 'IZ', 'IX', 'XX', 'XY', 'ZZ', 'YY', 'ZX', 'YI']
Lexicographically sorted
PauliTable: ['II', 'IX', 'IY', 'IZ', 'XI', 'XX', 'XY', 'XZ', 'YI', 'YX', 'YY', 'YZ', 'ZI', 'ZX', 'ZY', 'ZZ']
Weight sorted
PauliTable: ['II', 'IX', 'IY', 'IZ', 'XI', 'YI', 'ZI', 'XX', 'XY', 'XZ', 'YX', 'YY', 'YZ', 'ZX', 'ZY', 'ZZ']

매개변수

weight (bool) – optionally sort by weight if True (Default: False).

반환값

a sorted copy of the original table.

반환 형식

PauliTable

subtract(other)

Return the linear operator self - other.

DEPRECATED: use operator - other instead.

매개변수

other (BaseOperator) – an operator object.

반환값

the operator self - other.

반환 형식

BaseOperator

tensor(other)[소스]

Return the tensor output product of two tables.

This returns the combination of the tensor product of all Paulis in the current table with all Pauli’s in the other table, with the other tables qubits being the least-significant in the returned table. This is the opposite tensor order to expand().

Example

from qiskit.quantum_info.operators import PauliTable

current = PauliTable.from_labels(['I', 'X'])
other =  PauliTable.from_labels(['Y', 'Z'])
print(current.tensor(other))

PauliTable: ['IY', 'IZ', 'XY', 'XZ']

매개변수

other (PauliTable) – another PauliTable.

반환값

the tensor outer product table.

반환 형식

PauliTable

예외

QiskitError – if other cannot be converted to a PauliTable.

to_labels(array=False)[소스]

Convert a PauliTable to a list Pauli string labels.

For large PauliTables converting using the array=True kwarg will be more efficient since it allocates memory for the full Numpy array of labels in advance.

Table 9 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}$$

매개변수

array (bool) – return a Numpy array if True, otherwise return a list (Default: False).

반환값

The rows of the PauliTable in label form.

반환 형식

list or array

to_matrix(sparse=False, array=False)[소스]

Convert to a list or array of Pauli matrices.

For large PauliTables 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 10 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}$$

매개변수
• sparse (bool) – if True return sparse CSR matrices, otherwise return dense Numpy arrays (Default: False).

• array (bool) – return as rank-3 numpy array if True, otherwise return a list of Numpy arrays (Default: False).

반환값

A list of dense Pauli matrices if array=False and sparse=False. list: A list of sparse Pauli matrices if array=False and sparse=True. array: A dense rank-3 array of Pauli matrices if array=True.

반환 형식

list

transpose()[소스]

Not implemented.

unique(return_index=False, return_counts=False)[소스]

Return unique Paulis from the table.

Example

from qiskit.quantum_info.operators import PauliTable

pt = PauliTable.from_labels(['X', 'Y', 'X', 'I', 'I', 'Z', 'X', 'Z'])
unique = pt.unique()
print(unique)

PauliTable: ['X', 'Y', 'I', 'Z']

매개변수
• return_index (bool) – If True, also return the indices that result in the unique array. (Default: False)

• return_counts (bool) – If True, also return the number of times each unique item appears in the table.

반환값

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 is True.

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 is True.

반환 형식

PauliTable