Miscellaneous

Sparse Pauli

Module to deal with binary sparse matrices, in the compressed sparse row (CSR) format.

It is mostly a wrapper around scipy.sparse, making sure that everything is in the correct format and is done as efficiently as possible.

panqec.bsparse.dot(a, b)

Dot product between two row vectors a and b

panqec.bsparse.empty_row(n_cols: int)

Create an empty sparse row in the csr format

panqec.bsparse.equal(a, b)

Test if two matrices are equal, or if a matrix equal a unique number everywhere

panqec.bsparse.hsplit(matrix)

Split a row matrix into two row matrices with half the number of columns

panqec.bsparse.insert_mod2(index: int, row_matrix)

Insert 1 at ‘index’ in the row matrix, modulo 2

panqec.bsparse.is_one(index: int, row_matrix)

Return True if row_matrix[index] is nonzero

panqec.bsparse.zero_matrix(shape)

Create a zero sparse matrix in the csr format

panqec.bsparse.zero_row(n_cols: int)

Create a zero sparse row in the csr format

Dense Pauli

Bit array or vector representations of Paulis for 3Di codes.

Although qecsim already has such an implementation, some of these extra routines are useful specifically for dealing with the 3D code.

Author:

Eric Huang

panqec.bpauli.apply_deformation(deformation_indices: List[bool] | ndarray, bsf: ndarray) ndarray

Return Hadamard-deformed bsf at given indices.

panqec.bpauli.brank(matrix)

Rank of a binary matrix.

panqec.bpauli.bs_prod(a, b) ndarray

Array of 0 for commutes and 1 for anticommutes bvectors.

panqec.bpauli.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. :param bsf: Binary symplectic vector or matrix. :type bsf: numpy.array (1d or 2d) :return: Pauli operators. :rtype: str or list of str

panqec.bpauli.bsf_wt(bsf)

Return weight of given binary symplectic form. :param bsf: Binary symplectic vector or matrix. :type bsf: numpy.array (1d or 2d) or csr_matrix :return: Weight :rtype: int

panqec.bpauli.bvector_to_int(bvector: ndarray) int

Convert bvector to integer for effecient storage.

panqec.bpauli.bvectors_to_ints(bvector_list: list) list

List of bvectors to integers for efficient storage.

panqec.bpauli.get_effective_error(total_error, logicals_x, logicals_z) ndarray

Effective Pauli error on logical qubits after decoding.

panqec.bpauli.gf2_rank(rows)

Find rank of a matrix over GF2 given as list of binary ints.

From https://stackoverflow.com/questions/56856378

panqec.bpauli.int_to_bvector(int_rep: int, n: int) ndarray

Convert integer representation to n-qubit Pauli bvector.

panqec.bpauli.ints_to_bvectors(int_list: list, n: int) list

Convert list of integers back to bvectors.

Utilities

Micellaneous useful utilities.

Many of these are copied from the internet.

Author:

Eric Huang

class panqec.utils.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Special json encoder for numpy types

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
panqec.utils.edge_coords(axis_xyz_list, size)

Convert list of (axis, x, y, z) into coordinates.

panqec.utils.face_coords(axis_xyz_list, size)

Convert list of (axis, x, y, z) into coordinates.

panqec.utils.find_nearest(array, value)

Find the nearest element in array to given value.

Parameters:
  • array (Union[List, np.ndarray]) – The array with values in it.

  • value (Union[float, int]) – The value to compare to.

Returns:

nearest_value – The element in the array that is nearest to the given value.

Return type:

Union[float, int]

panqec.utils.fmt_confidence_interval(estimate, left, right, sn=None, unit=None, sn_cutoff=8)

Format confidence interval for latex.

panqec.utils.fmt_uncertainty(x, dx, sn=None, sn_cutoff=8, unit=None)

Format uncertainty for latex.

panqec.utils.format_polynomial(symbol, coefficients, digits=3)

Polynomial as nice-looking string.

panqec.utils.get_direction_from_bias_ratio(pauli: str, eta) dict

Get noise params given Pauli and bias.

panqec.utils.get_label(name: str, parameters: Dict[str, Any]) str

Get label filtering entries from class name and parameters.

Parameters:
  • name (str) – The name of the class.

  • parameters (Dict[str, Any]) – The dictionary of parameters used to intialize an instance of that class.

Returns:

label – The formatted label.

Return type:

str

Examples

>>> get_label('Toric2DCode', {'L_x': 5, 'L_y': 6, 'L_z': 7})
'Toric2DCode(L_x=5, L_y=6, L_z=7)'
panqec.utils.hash_json(dictionary)

Produce MD5 hash of dictionary

panqec.utils.list_where(array)

Get locations of binary list as sorted list of tuples.

panqec.utils.nested_map(function: Callable)

Return function that applies function to nested lists.

panqec.utils.rescale_prob(x_data, *params)

Rescaled physical error rate.

panqec.utils.set_where(array)

Get locations of binary list as sorted list of tuples.

panqec.utils.simple_print(a, zeros=True)

Print binary array in space-saving manner.

Examples

>>> simple_print(np.eye(3))
100
010
001
>>> simple_print(np.eye(3), zeros=False)
1
 1
  1
panqec.utils.sizeof_fmt(num, suffix='B')

Size to human readable format.

From stack overflow.

IO

Routines for input and output.

This includes routines to produce, merge and analyse data produced by simulations.

Author:

Eric Huang

panqec.io.dump_results(export_json: str, results_dict: dict, verbose: bool = True)

Save results dict to json file.

panqec.io.serialize_results(i_trial: int, n_trials: int, L_list: ndarray, p_list: ndarray, L_repeats: ndarray, start_time: datetime, time_elapsed: timedelta, time_remaining: timedelta, eta: datetime, p_est: ndarray, p_se: ndarray, n_fail: ndarray, n_try: ndarray, effective_errors: list) dict

Convert results to dict.