Skip to content

Table decoders

Table decoder used by the MSD postselection notebook.

TableDecoderWithConfidence

TableDecoderWithConfidence(
    dem: DetectorErrorModel,
    *,
    num_shots: int = 10**7,
    seed: int | None = None,
    step_size: int | None = None
)

Bases: TableDecoder, ConfidenceDecoder


              flowchart TD
              bloqade.gemini.decoding.table_decoders.TableDecoderWithConfidence[TableDecoderWithConfidence]
              bloqade.gemini.decoding.table_decoders.TableDecoder[TableDecoder]
              bloqade.gemini.decoding.confidence.ConfidenceDecoder[ConfidenceDecoder]

                              bloqade.gemini.decoding.table_decoders.TableDecoder --> bloqade.gemini.decoding.table_decoders.TableDecoderWithConfidence
                
                bloqade.gemini.decoding.confidence.ConfidenceDecoder --> bloqade.gemini.decoding.table_decoders.TableDecoderWithConfidence
                


              click bloqade.gemini.decoding.table_decoders.TableDecoderWithConfidence href "" "bloqade.gemini.decoding.table_decoders.TableDecoderWithConfidence"
              click bloqade.gemini.decoding.table_decoders.TableDecoder href "" "bloqade.gemini.decoding.table_decoders.TableDecoder"
              click bloqade.gemini.decoding.confidence.ConfidenceDecoder href "" "bloqade.gemini.decoding.confidence.ConfidenceDecoder"
            

Dense table decoder with empirical per-syndrome confidence.

Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/table_decoders.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def __init__(
    self,
    dem: stim.DetectorErrorModel,
    *,
    num_shots: int = 10**7,
    seed: int | None = None,
    step_size: int | None = None,
) -> None:
    data_len = dem.num_detectors + dem.num_observables
    if data_len > 64:
        raise ValueError(
            f"Total data length {data_len} (detectors + observables) "
            "exceeds 64 bits and cannot be packed into int64."
        )

    counts_table = np.zeros(2**data_len, dtype=_COUNT_DTYPE)

    super().__init__(dem=dem, det_obs_counts=counts_table)
    self._det_obs_counts = _as_uint32_count_table(self._det_obs_counts)
    self._correction_confidence: np.ndarray | None = None

    if data_len == 0:
        self._det_obs_counts[0] = max(1, min(int(num_shots), _COUNT_MAX))
        return
    self._train_from_dem(num_shots=num_shots, seed=seed, step_size=step_size)

decode

decode(detector_bits: ndarray) -> np.ndarray

Decode detector bits after validating the detector-shot width.

Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/table_decoders.py
154
155
156
157
158
159
160
161
162
163
def decode(self, detector_bits: np.ndarray) -> np.ndarray:
    """Decode detector bits after validating the detector-shot width."""

    validated_bits = _validate_detector_bits(
        detector_bits,
        self.num_detectors,
        allow_batch=True,
        method_name="decode",
    )
    return super().decode(validated_bits)

decode_with_confidence

decode_with_confidence(
    detector_bits: ndarray,
) -> tuple[np.ndarray, np.float64]

Decode one detector syndrome and return its empirical confidence.

Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/table_decoders.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def decode_with_confidence(
    self,
    detector_bits: np.ndarray,
) -> tuple[np.ndarray, np.float64]:
    """Decode one detector syndrome and return its empirical confidence."""

    validated_bits = _validate_detector_bits(
        detector_bits,
        self.num_detectors,
        allow_batch=False,
        method_name="decode_with_confidence",
    )
    correction = np.asarray(self.decode(validated_bits), dtype=np.bool_)
    assert self._correction_confidence is not None
    packed = int(
        pack_boolean_array(
            np.asarray(validated_bits, dtype=np.uint8).reshape(1, -1)
        )[0]
    )
    return correction, np.float64(self._correction_confidence[packed])