Shortcuts

# qiskit.quantum_info.Pauli¶

class Pauli(z=None, x=None, label=None)[소스]

A simple class representing Pauli Operators.

The form is P_zx = (-i)^dot(z,x) Z^z X^x where z and x are elements of Z_2^n. That is, there are 4^n elements (no phases in this group).

For example, for 1 qubit P_00 = Z^0 X^0 = I P_01 = X P_10 = Z P_11 = -iZX = (-i) iY = Y

The overload __mul__ does not track the sign: P1*P2 = Z^(z1+z2) X^(x1+x2) but sgn_prod does __mul__ and track the phase: P1*P2 = (-i)^dot(z1+z2,x1+x2) Z^(z1+z2) X^(x1+x2) where the sums are taken modulo 2.

Pauli vectors z and x are supposed to be defined as boolean numpy arrays.

Ref. Jeroen Dehaene and Bart De Moor Clifford group, stabilizer states, and linear and quadratic operations over GF(2) Phys. Rev. A 68, 042318 – Published 20 October 2003

Make the Pauli object.

Note that, for the qubit index:
• Order of z, x vectors is q_0 … q_{n-1},

• Order of pauli label is q_{n-1} … q_0

E.g.,
• z and x vectors: z = [z_0 … z_{n-1}], x = [x_0 … x_{n-1}]

• a pauli is $P_{n-1} otimes … otimes P_0$

매개변수
• z (numpy.ndarray) – boolean, z vector

• x (numpy.ndarray) – boolean, x vector

• label (str) – pauli label

__init__(z=None, x=None, label=None)[소스]

Make the Pauli object.

Note that, for the qubit index:
• Order of z, x vectors is q_0 … q_{n-1},

• Order of pauli label is q_{n-1} … q_0

E.g.,
• z and x vectors: z = [z_0 … z_{n-1}], x = [x_0 … x_{n-1}]

• a pauli is $P_{n-1} otimes … otimes P_0$

매개변수
• z (numpy.ndarray) – boolean, z vector

• x (numpy.ndarray) – boolean, x vector

• label (str) – pauli label

Methods

 __init__([z, x, label]) Make the Pauli object. append_paulis([paulis, pauli_labels]) Append pauli at the end. delete_qubits(indices) Delete pauli at the indices. from_label(label) Take pauli string to construct pauli. insert_paulis([indices, paulis, pauli_labels]) Insert or append pauli to the targeted indices. kron(other) Kronecker product of two paulis. pauli_single(num_qubits, index, pauli_label) Generate single qubit pauli at index with pauli_label with length num_qubits. random(num_qubits[, seed]) Return a random Pauli on number of qubits. sgn_prod(p1, p2) Multiply two Paulis and track the phase. Convert to Pauli circuit instruction. Present the pauli labels in I, X, Y, Z format. Convert Pauli to a matrix representation. Convert to Operator object. Convert Pauli to a sparse matrix representation (CSR format). update_x(x[, indices]) Update partial or entire x. update_z(z[, indices]) Update partial or entire z.

Attributes

 num_qubits Number of qubits. x Getter of x. z Getter of z.
append_paulis(paulis=None, pauli_labels=None)[소스]

Append pauli at the end.

매개변수
• paulis (Pauli) – the to-be-inserted or appended pauli

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

반환값

self

반환 형식

Pauli

delete_qubits(indices)[소스]

Delete pauli at the indices.

매개변수

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

반환값

self

반환 형식

Pauli

classmethod from_label(label)[소스]

Take pauli string to construct pauli.

The qubit index of pauli label is q_{n-1} … q_0. E.g., a pauli is $P_{n-1} otimes … otimes P_0$

매개변수

label (str) – pauli label

반환값

the constructed pauli

반환 형식

Pauli

예외

QiskitError – invalid character in the label

insert_paulis(indices=None, paulis=None, pauli_labels=None)[소스]

Insert or append pauli to the targeted indices.

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

매개변수
• 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

참고

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.

반환값

self

반환 형식

Pauli

예외

QiskitError – provide both paulis and pauli_labels at the same time

kron(other)[소스]

Kronecker product of two paulis.

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

매개변수

other (Pauli) – P2

반환값

self

반환 형식

Pauli

property num_qubits

Number of qubits.

classmethod pauli_single(num_qubits, index, pauli_label)[소스]

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

매개변수
• num_qubits (int) – the length of pauli

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

• pauli_label (str) – pauli

반환값

single qubit pauli

반환 형식

Pauli

classmethod random(num_qubits, seed=None)[소스]

Return a random Pauli on number of qubits.

매개변수
• num_qubits (int) – the number of qubits

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

반환값

the random pauli

반환 형식

Pauli

static sgn_prod(p1, p2)[소스]

Multiply two Paulis and track the phase.

$P_3 = P_1 otimes P_2$: X*Y

매개변수
반환값

the multiplied pauli complex: the sign of the multiplication, 1, -1, 1j or -1j

반환 형식

Pauli

to_instruction()[소스]

Convert to Pauli circuit instruction.

to_label()[소스]

Present the pauli labels in I, X, Y, Z format.

Order is $q_{n-1} …. q_0$

반환값

pauli label

반환 형식

str

to_matrix()[소스]

Convert Pauli to a matrix representation.

Order is q_{n-1} …. q_0, i.e., $P_{n-1} otimes … P_0$

반환값

a matrix that represents the pauli.

반환 형식

numpy.array

to_operator()[소스]

Convert to Operator object.

to_spmatrix()[소스]

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

Order is q_{n-1} …. q_0, i.e., $P_{n-1} otimes … P_0$

반환값

a sparse matrix with CSR format that represents the pauli.

반환 형식

scipy.sparse.csr_matrix

update_x(x, indices=None)[소스]

Update partial or entire x.

매개변수
• x (numpy.ndarray or list) – to-be-updated x

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

반환값

self

반환 형식

Pauli

예외

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

update_z(z, indices=None)[소스]

Update partial or entire z.

매개변수
• z (numpy.ndarray or list) – to-be-updated z

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

반환값

self

반환 형식

Pauli

예외

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

property x

Getter of x.

property z

Getter of z.