loom.eka.utilities.stab_array
Copyright (c) Entropica Labs Pte Ltd 2025.
Use, distribution and reproduction of this program in its source or compiled form is prohibited without the express written consent of Entropica Labs Pte Ltd.
- class loom.eka.utilities.stab_array.StabArray(array, validated=False)[source]
Bases:
PauliArrayA StabArray is a collection of commuting SignedPauliOps acting on the same qubit register.
- Parameters:
array (np.ndarray) – The numpy array containing the stabilizers.
validated (bool, optional) – Whether the input array has already been validated, by default False.
- nqubits
The number of qubits that the PauliArray operators act on.
- Type:
int
- x
The array representing the X-component of the PauliArray in binary representation.
- Type:
np.ndarray
- z
The array representing the Z-component of the PauliArray in binary representation.
- Type:
np.ndarray
Initialization of a StabArray.
- Parameters:
array (np.ndarray) – The numpy array containing the stabilizers.
validated (bool, optional) – Whether the input array has already been validated, by default False.
- Raises:
TypeError – When the input is not a numpy array.
ValueError – When the input array is not 2-dimensional or contains values other than 0 and 1.
AntiCommutationError – When the input array contains anti-commuting operators.
- DTYPE
alias of
int8
-
array:
ndarray
- property as_paulistrings: list[str]
Representation of Pauli operators in the StabArray as a list of strings.
- copy()[source]
Returns a deep copy of the StabArray object.
- Returns:
Deep copy of the StabArray object
- Return type:
- classmethod from_signed_pauli_ops(signed_pauli_ops, validated=False)[source]
Create a StabArray from a sequence of SignedPauliOps.
- Parameters:
signed_pauli_ops (Sequence[SignedPauliOp]) – The sequence of SignedPauliOps to be converted to a StabArray.
- Returns:
The StabArray created from the sequence of SignedPauliOps.
- Return type:
- Raises:
TypeError – When the input sequence contains elements that are not of type SignedPauliOp.
ValueError – When the input sequence contains elements with different numbers of qubits.
- property is_irreducible: bool
Checks whether the StabArray is irreducible, i.e. if it contains no stabilizers that can be generated as a product of other stabilizers.
- property is_trivial: bool
Checks whether the StabArray is trivial, i.e. if it contains no stabilizers.
- property nstabs: int
The number of stabilizers in the StabArray.
- loom.eka.utilities.stab_array.find_destabarray(stabarr, partial_destabarray=None)[source]
Given a stabilizer array of a state, find the destabilizer array.
- Parameters:
stabilizer_array (StabArray) – The stabilizer array of a state. It must contain n independent stabilizers where n is the number of qubits.
partial_destabarray (StabArray, optional) – A destabilizer array that partially destabilizes the state, i.e. it contains m < n operators that each anti-commute with exactly one state stabilizer. The final destabilizer array will contain these operators in the appropriate rows.
- Returns:
The destabilizer array.
- Return type:
- loom.eka.utilities.stab_array.invert_bookkeeping_matrix(bookkeeping_matrix)[source]
Invert the bookkeeping matrix.
- Parameters:
bookkeeping_matrix (np.ndarray) – The bookkeeping matrix to be inverted.
- Returns:
The inverted bookkeeping matrix.
- Return type:
np.ndarray
- loom.eka.utilities.stab_array.is_stabarray_equivalent(stab_arr0, stab_arr1)[source]
Check if two stabilizer arrays are equivalent.
- Parameters:
stab_arr0 (np.ndarray) – A stabilizer array to be compared with another.
stab_arr1 (np.ndarray) – A stabilizer array to be compared with another.
- Returns:
Whether the stabilizer arrays are equivalent.
- Return type:
bool
- loom.eka.utilities.stab_array.is_subset_of_stabarray(pauli_obj_sub, stab_arr_super)[source]
Check if a StabArray or SignedPauliOp is a subset of a StabArray.
- Parameters:
pauli_obj_sub (SignedPauliOp | StabArray) – The SignedPauliOp or StabArray to be checked if it is a subset.
stab_arr_super (StabArray) – The StabArray to be checked if it is a superset.
- Returns:
Whether the StabArray or SignedPauliOp is a subset of the StabArray.
- Return type:
bool
- loom.eka.utilities.stab_array.reduce_stabarray(stabarr)[source]
Perform stabilizer BGE and then remove any trivial operators.
- loom.eka.utilities.stab_array.reduce_stabarray_with_bookkeeping(stabarr)[source]
Perform stabilizer BGE and then remove any trivial operators. Also return the bookkeeping matrix, which is a matrix that keeps track of the row operations that were performed on the stabilizer array.
- loom.eka.utilities.stab_array.reindex_stabarray(stab_array, new_idcs)[source]
Returns an instance of a stabilizer array but with the qubit columns reindexed.
- loom.eka.utilities.stab_array.sparse_formatter(stab_list, **keywords)[source]
Given a set of Pauli string operators, return a list of dicts, where dict keys are
{'sign', 'X', 'Y', 'Z'}. For keysX,Y,Z, value is a list of indices/positions where the i-th qubit in the Pauli operator is respectively either X, Y, Z.There is a keyword option, to allow the user to pass a dictionary to convert from qubit index in CliffordSim, to some other indexing that is more convenient for the user.
- Parameters:
stab_array (set[str]) – An unordered list of strings, where each string represents a Pauli string for a stabilizer operator in the set.
keywords ({'convert_dict'}) – By supplying a dictionary that converts between qubit indices in CliffordSim into qubit IDs in an embedded QEC code, that user can return dicts where the values refer directly to IDs in an embedded QEC code.
- Returns:
output_format – Reformats each string in the sparse format. E.g. +ZXIIYXZII gets returned as
{'sign':'+', 'X':(1,5), 'Z':(0,6), 'Y':(4,)}- Return type:
list[dict]
- loom.eka.utilities.stab_array.stabarray_bge(stabarr)[source]
Perform binary gaussian elimination on a stabilizer array.
- loom.eka.utilities.stab_array.stabarray_bge_with_bookkeeping(stabarr)[source]
Performs binary gaussian elimination on a stabilizer array and returns the array in its reduced row echelon form. Reference: https://en.wikipedia.org/wiki/Row_echelon_form#Reduced_row_echelon_form
Bookkeeping matrix explanation: It also returns the bookkeeping matrix, which is a matrix that keeps track of the row operations that were performed on the stabilizer array, i.e. how to transform the input stabilizer array into the reduced row echelon form. If the (i, j)-th element of the bookkeeping matrix is True, then the i-th stabilizer of the row echelon form contains the j-th row of the initial stabilizer array. In other words, to get the i-th stabilizer of the row echelon form, one should multiply all the stabilizers of the initial stabilizer array with index j that have a True value in the (i, j)-th element of the bookkeeping matrix.
- Parameters:
stabarr (StabArray) – The stabilizer array to perform binary gaussian elimination on.
- Returns:
A tuple containing the reduced stabilizer array and the bookkeeping matrix, i.e. the matrix that keeps track of the row operations that were performed on the stabilizer array.
- Return type:
tuple[StabArray, np.ndarray]
- loom.eka.utilities.stab_array.stabarray_standard_form(stabarr)[source]
Transform a stabilizer array into a standard form. Note that this means that the stabilizer array is reduced and reindexed.
Reduce the stabilizer array.
2. Reorder the qubits such that the X part of the stabilizer array becomes of the form
(I, A) (0, 0)
where I is the identity matrix of size r and A is a r x (n-r) matrix and the 0 arrays have n-k-r rows.
Multiply rows of the stabilizer array so that it becomes of the form
(I, A1, A2 | B, 0, C) (0, 0, 0 | D, I, E)
where I is the identity matrix, A1, A2, B, C, D and E are matrices.
Dimension explanation:
The left blocks comprise the X part of the stabilizer array and the right blocks comprise the Z part of the stabilizer array.
The top blocks have r rows and the bottom blocks have n-k-r rows, where n is the number of qubits, k is the number of logical qubits and r is the rank of the X part of the stabilizer array.
From left to right, the number of columns in the blocks are r, n-k-r, k for each of the Z and X parts.
More info:
Nielsen, M. A., & Chuang, I. L. (2011). (p.470-471) Quantum Computation and Quantum Information: 10th Anniversary Edition. Cambridge University Press
- Parameters:
stabarr (StabArray) – The stabilizer array to be transformed.
- Returns:
A tuple containing the reindexed stabilizer array, the rank of the X part of the stabilizer array and the inverse qubit map. The inverse qubit map can be used to reindex the stabilizer array to the original qubit order.
- Return type:
tuple[StabArray, int, list[int]]
- loom.eka.utilities.stab_array.subtract_stabarrays(stab_array, stab_array_to_remove)[source]
Given 2 stabilizer arrays, remove from the first one any occurrence of stabilizers found in the second one.