paulitools: pauli and binary symplectic tools

qecsim.paulitools

This module contains functions for Pauli strings and binary symplectic vectors / matrices.

In qecsim, a Pauli operator on N qubits is represented, without phase, by either of the following:

  • a string of I, X, Y, Z of length N, such as 'XIZIY', where the nth element operates on the nth qubit.

  • a binary 1d numpy.array of length 2N, such as np.array([1,0,0,0,1,0,0,1,0,1]), where the nth element operates as X on the nth qubit, the N+nth element operates as Z on the nth qubit, and XZ operates as Y (since phase is ignored).

A group of Pauli operators is specified as a list of string, or a 2d numpy.array, respectively.

qecsim.paulitools.bsf_to_pauli(bsf)

Convert the given binary symplectic form to Pauli operator(s).

(1 0 0 0 1 | 0 0 1 0 1) -> XIZIY

Assumptions:

  • bsf is a numpy.array (1d or 2d) in binary symplectic form.

Parameters

bsf (numpy.array (1d or 2d)) – Binary symplectic vector or matrix.

Returns

Pauli operators.

Return type

str or list of str

qecsim.paulitools.bsf_wt(bsf)

Return weight of given binary symplectic form.

Parameters

bsf (numpy.array (1d or 2d)) – Binary symplectic vector or matrix.

Returns

Weight

Return type

int

qecsim.paulitools.bsp(a, b)

Return the binary symplectic product of A with B.

The binary symplectic product \(\odot\) is defined as \(A \odot B \equiv A \Lambda B \bmod 2\) where \(\Lambda = \left[\begin{matrix} 0 & I \\ I & 0 \end{matrix}\right]\).

Assumptions:

  • A and B should be 1d (vector) or 2d (matrix) numpy arrays with elements 0 or 1.

  • A should have an even number of columns (or elements if 1d).

  • B should have an even number of rows (or elements if 1d).

  • A and B should have compatible dimensions for a dot product, as per numpy requirements.

Parameters
  • a (numpy.array (1d or 2d)) – LHS binary symplectic vector or matrix.

  • b (numpy.array (1d or 2d)) – RHS binary symplectic vector or matrix.

Returns

Binary symplectic product of A with B.

Return type

int if A and B vectors; numpy.array (1d if A or B vector, 2d if A and B matrices)

qecsim.paulitools.ibsf(n_qubits, min_weight=0, max_weight=None)

Return an iterator of binary symplectic representations of Paulis in ascending weight.

Parameters
  • n_qubits (int) – Number of physical qubits.

  • min_weight (int) – Minimum weight. (default=0)

  • max_weight (int) – Maximum weight. (default=n_qubits)

Returns

Iterator of binary symplectic representation of Pauli.

Return type

iterator of numpy.array (1d)

qecsim.paulitools.ipauli(n_qubits, min_weight=0, max_weight=None)

Return an iterator of Paulis in ascending weight.

Notes:

  • Each Pauli is a string of I, X, Y, Z such as ‘XIZIY’

Parameters
  • n_qubits (int) – Number of qubits.

  • min_weight (int) – Minimum weight. (default=0)

  • max_weight (int) – Maximum weight. (default=n_qubits)

Returns

Iterator of Paulis.

Return type

iterator of str

qecsim.paulitools.pack(binary_array)

Return packed representation of the given binary array (e.g. binary symplectic form of Pauli).

Parameters

binary_array (numpy.array (1d)) – Binary array.

Returns

Packed binary array as (integer value of binary array, length of binary array)

Return type

(str, int)

qecsim.paulitools.pauli_to_bsf(pauli)

Convert the given Pauli operator(s) to binary symplectic form.

XIZIY -> (1 0 0 0 1 | 0 0 1 0 1)

Assumptions:

  • pauli is a string of I, X, Y, Z such as ‘XIZIY’ or a list of such strings of the same length.

Parameters

pauli (str or list of str) – A single or list of Pauli operators.

Returns

Binary symplectic representation of Pauli.

Return type

numpy.array (1d or 2d)

qecsim.paulitools.pauli_wt(pauli)

Return weight of given Pauli operator(s).

Parameters

pauli (str or list of str) – A single or list of Pauli operators.

Returns

Weight

Return type

int

qecsim.paulitools.unpack(packed_binary_array)

Return a binary array corresponding to the packed representation.

Parameters

packed_binary_array ((str, int)) – Packed binary array as (hex string of binary array, length of binary array)

Returns

Binary array

Return type

numpy.array (1d)