Skip to content

loqs.tools.fttools

A collection of functions to help fault-tolerance testing.

Classes

Attributes

Name Type Value Doc
PAULI_PROPAGATION_GATE_MAP dict[str, str] {'Gh': 'H', 'Gcnot': 'CX'} LoQS gate name -> STIM gate name, for gates this propagation utility knows how to conjugate a Pauli through. Extend as needed for other Clifford gates; anything not here or in PAULI_PROPAGATION_IDLE_GATES raises rather than silently mis-pruning.
PAULI_PROPAGATION_IDLE_GATES frozenset[str] frozenset({'Imrz', 'Gi1Q', 'Gi2Q', 'GiMCM'}) LoQS idle-gate names, which never change a Pauli's support/type and so are skipped during propagation.

Functions

build_discrete_error_injection_program_for_combo

build_discrete_error_injection_program_for_combo(base_program: QuantumProgram, stack_idx_to_modify: int, error_injections: Sequence[tuple[int, str, int]]) -> QuantumProgram

Build a single discrete-error-injected program for one explicit combination of (layer, error_circuit_label, qubit) injections.

A lower-level building block factored out of the per-combo body of build_discrete_error_injection_programs(), for callers that have already decided exactly which fault combination(s) to build (e.g. one representative per Pauli-propagation equivalence class) rather than the full location x label enumeration.

Parameters:

Name Type Description Default
base_program QuantumProgram

The base program to modify.

required
stack_idx_to_modify int

The entry in the InstructionStack of base_program to modify with error_injections as a label kwarg.

required
error_injections Sequence[tuple[int, str, int]]

One entry for a weight-1 error, two for a correlated weight-2 error: (layer, error_circuit_label, qubit).

required

Returns:

Type Description
QuantumProgram

The program with this exact fault combination injected.


build_discrete_error_injection_programs

build_discrete_error_injection_programs(base_program: QuantumProgram, instruction_to_analyze: Instruction, stack_idx_to_modify: int, error_circuit_labels: Sequence[str], post_twoq_gates: bool = False) -> list[QuantumProgram]

Create a series of programs with one discrete error injected each.

This will take a Instruction, use get_possible_discrete_error_locations() to collect the possible error locations, and then create new programs where the error will be injected via error_injections (see build_physical_circuit_instruction for more) as a kwarg to the relevant InstructionLabel.

Parameters:

Name Type Description Default
base_program QuantumProgram

The base program to modify

required
instruction_to_analyze Instruction

The Instruction to get all possible discrete errors for

required
stack_idx_to_modify int

The entry in the InstructionStack of the base_program to modify with error_injections as a label kwarg.

required
error_circuit_labels Sequence[str]

The labels for possible errors to insert.

required
post_twoq_gates bool

Whether to inject weight-1 errors before every gate (False, default) or all weight-2 errors after 2Q gates (True). Also see get_possible_discrete_error_locations(), by default False

False

Returns:

Type Description
list[QuantumProgram]

A list of programs, one for each possible discrete error


build_pruned_discrete_error_injection_programs

build_pruned_discrete_error_injection_programs(base_program: QuantumProgram, instruction_to_analyze: Instruction, stack_idx_to_modify: int, error_circuit_labels: Sequence[str], post_twoq_gates: bool = False) -> tuple[list[QuantumProgram], int]

(programs, total combos before pruning) -- like build_discrete_error_injection_programs(), but builds only one program per Pauli-propagation equivalence-class representative (see prune_error_combos_by_propagation()) instead of every location x label combination. Relaxes "test every circuit location" to "test every distinct propagated error"; use only where that's an acceptable substitution for the exhaustive sweep.


is_stim_pauli_propagation_available

is_stim_pauli_propagation_available() -> bool

Whether the STIM-tableau-based propagation utility can run.


propagate_pauli_signature

propagate_pauli_signature(circuit: PyGSTiPhysicalCircuit, start_layer: int, seed: dict[int, str]) -> tuple[tuple[int, str], ...]

Propagate a seed Pauli fault ({qubit_idx: 'X'/'Y'/'Z'}, applied starting at start_layer, inclusive) forward through circuit's remaining gates using STIM's tableau machinery, and return a hashable, sign-independent signature of the resulting Pauli support at the circuit's end (empty tuple if it propagates away entirely).

Only supports PyGSTiPhysicalCircuit-backed circuits built entirely from gates in PAULI_PROPAGATION_GATE_MAP/ PAULI_PROPAGATION_IDLE_GATES (this needs to be verified by the caller, e.g. no mid-circuit measurement in the segment being propagated through); raises on any other gate so an unrecognized one fails loudly rather than silently mis-pruning.


prune_error_combos_by_propagation

prune_error_combos_by_propagation(circuit: BasePhysicalCircuit, error_labels: Sequence[str], post_twoq_gates: bool = False) -> tuple[list[list[tuple[int, str, int]]], int]

(representative combos, total combos before pruning).

Each representative combo is in error_injections format (one (layer, label, qubit) entry for weight-1, two for weight-2/ post-2-qubit-gate errors), one per distinct propagated-Pauli equivalence class, per propagate_pauli_signature(). If STIM isn't available, returns every combo unpruned (see module comment above).