loom.validator.utilities
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.
- loom.validator.utilities.all_possible_pauli_strings(n_qubits)[source]
Returns all possible sparse Pauli strings for a given number of qubits. The sparse Pauli strings are generated by iterating over all possible combinations of X and Z operators for each qubit. The list size scales exponentially with the number of qubits (as 2*4**n_qubits), so it is important to consider the performance implications when working with large number of (logical) qubits.
- Parameters:
n_qubits (int) – The number of qubits.
- Returns:
The list of all possible sparse Pauli strings for the given number of qubits.
- Return type:
list[str]
- loom.validator.utilities.get_all_cliffordsim_registers_with_random_flags(cat_engine)[source]
Get all the classical registers in the given cliffordsim engine.
- Parameters:
cat_engine (Engine) – The cliffordsim engine that contains the classical registers.
- Returns:
A dictionary where the keys are the classical register names and the values are tuples containing the value of the register and a flag indicating whether the register is a result of a random measurement (True) or not (False). If the register is not a result of a measurement, the flag is set to None.
- Return type:
dict[str, tuple[int, bool | None]]
- loom.validator.utilities.get_parity_from_cbits(cat_engine, cbits)[source]
Get the parity of the cbits in the given list.
- Parameters:
cat_engine (Engine) – The cliffordsim engine that contains the runtime results.
cbits (tuple[str | int, ...]) – The list of cbits to check. The cbits can be either strings or integers. The integers are treated as constant values (0 or 1) that can flip the expected parity. The strings are the labels of the classical channels whose values are to be retrieved at runtime. The register name is the first part of the label, e.g. c_(0_0)_0 -> c.
- Returns:
The parity of the cbits. The parity is calculated by XORing the values of all of the cbits.
- Return type:
int
- loom.validator.utilities.logical_state_transformations_to_check(x_operators_sparse_pauli_map, z_operators_sparse_pauli_map)[source]
Returns the logical state transformations to check for a logical operation. The input is the sparse Pauli strings for the individual X and Z operators. The output is a list of tuples where each tuple contains the input and expected output logical states for the logical operation.
Example: For a CNOT gate from qubit 0 to qubit 1 we know that:
X0 -> X0X1
X1 -> X1
Z0 -> Z0
Z1 -> Z1Z0
Thus, we can find the logical state transformations for the CNOT gate by calling this function with the following inputs:
x_operators_sparse_pauli_map = [“X0X1”, “X1”]
z_operators_sparse_pauli_map = [“Z0”, “Z1Z0”]
This will return the list of logical state transformations to check for the CNOT gate which will be a list containing the following tuples:
(LogicalState((‘+Z0’, ‘+Z1’)), (LogicalState((‘+Z0’, ‘+Z0Z1’)),)) \(\ket{00} -> \ket{00}\)
(LogicalState((‘+X0’, ‘+X1’)), (LogicalState((‘+X0X1’, ‘+X1’)),)) \(\ket{++}-> \ket{++}\)
(LogicalState((‘+Z0’, ‘+X1’)), (LogicalState((‘+Z0’, ‘+X1’)),)) \(\ket{0+} -> \ket{0+}\)
(LogicalState((‘+X0’, ‘+Z1’)), (LogicalState((‘+X0X1’, ‘+Z0Z1’)),)) \(\ket{+0} ->\) Bell pair
The format of the tuples is such that they can be used as input for validator logical state transformation checks.
- Parameters:
x_operators_sparse_pauli_map (list[str]) – The list of sparse Pauli strings describing how each X operator is transformed. No sign is needed and the order matches the transformation of the logical operators X0, X1, …
z_operators_sparse_pauli_map (list[str]) – The list of sparse Pauli strings describing how each Z operator is transformed. No sign is needed and the order matches the transformation of the logical operators Z0, Z1, …
- Returns:
The list of logical state transformations to check.
- Return type:
list[tuple[LogicalState, tuple[LogicalState]]]
- loom.validator.utilities.logical_states_to_check(n_logical_qubits)[source]
Returns the logical states to check for a given number of logical qubits. These logical states are constructed in such a way that if these are transformed correctly, then all the logical states should be transformed correctly for a Clifford gate operation. The selection is done such that the effect of the gate on each input logical operator is isolated.
For example, to verify the effect on the input logical operators Z1, X1 (logical qubit 1) for a 3-logical-qubit system, the effect should be captured by checking the output of the logical states: {+Z0, +Z1, +Z2}, {+Z0, +X1, +Z2}, {+X0, +X1, +X2} and {+X0, +Z1, +X2}. We can see that the action of the gate on the logical qubit 1 is isolated by keeping the logical qubits 0 and 2 in the same state for the first two and the last two states while changing the state of the logical qubit 1.
NOTE: The above has not been mathematically proven, but it is a reasonable assumption that hasn’t been disproven yet.
- Parameters:
n_logical_qubits (int) – The number of logical qubits.
- Returns:
The list of logical states to check.
- Return type:
list[LogicalState]