qldpc.decoders.sinter

Decoders for sinter to sample quantum error correction circuits.

Exceptions

DecoderNotCompiledError

Common base class for all non-exit exceptions.

Classes

CompiledSequentialWindowDecoder

Decoder usable by Sinter for decoding circuit errors, compiled to a specific circuit.

CompiledSinterDecoder

Decoder usable by Sinter for decoding circuit errors, compiled to a specific circuit.

CompiledSubgraphDecoder

Decoder usable by Sinter for decoding circuit errors, compiled to a specific circuit.

CompiledTrivialDecoder

A compiled trivial decoder that unconditionally predicts null errors/logical flips.

SequentialSinterDecoder

Deprecated alias for SequentialWindowDecoder.

SequentialWindowDecoder

Decoder usable by Sinter for decoding circuit errors.

SinterDecoder

Decoder usable by Sinter for decoding circuit errors.

SlidingWindowDecoder

Decoder usable by Sinter for decoding circuit errors.

SubgraphDecoder

Decoder usable by Sinter for decoding circuit errors.

SubgraphSinterDecoder

Deprecated alias for SubgraphDecoder.

TrivialDecoder

A trivial decoder that unconditionally predicts null errors/logical flips.

Module Contents

exception qldpc.decoders.sinter.DecoderNotCompiledError[source]

Bases: Exception

Common base class for all non-exit exceptions.

class qldpc.decoders.sinter.CompiledSequentialWindowDecoder(dem_arrays: qldpc.decoders.dems.DetectorErrorModelArrays, window_detectors: collections.abc.Sequence[collections.abc.Sequence[int] | slice], window_errors: collections.abc.Sequence[tuple[collections.abc.Sequence[int] | slice, collections.abc.Sequence[int] | slice]], window_decoders: collections.abc.Sequence[qldpc.decoders.retrieval.Decoder])[source]

Bases: CompiledSinterDecoder

Decoder usable by Sinter for decoding circuit errors, compiled to a specific circuit.

This decoder splits a decoding problem into (possibly overlapping) windows that are decoded sequentially.

Instances of this class are meant to be constructed by a SequentialWindowDecoder, whose .compile_decoder_for_dem method returns a CompiledSequentialWindowDecoder. See help(SequentialWindowDecoder).

decode_shots(detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Predicts observable flips from the given detection events.

This method accepts and returns boolean data.

See help(sinter.CompiledDecoder) for additional information.

decode_shots_to_error(detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Predicts a net circuit error from the given detection events.

The error predicted for an erased shot is a guess, and this method reports no erasures, so use .decode_shots_to_error_and_erasure to tell the two apart.

This method accepts and returns boolean data.

decode_shots_to_error_and_erasure(detection_event_data: numpy.typing.NDArray[numpy.uint8]) → tuple[numpy.typing.NDArray[numpy.uint8], numpy.typing.NDArray[numpy.bool_]][source]

Predicts a net circuit error, and whether any window erased, per shot.

A shot is erased if any of its windows is, and an erased shot still commits whatever error its windows inferred, which no window could explain and which the windows after it are then decoded against. Sinter and qldpc.circuits.get_logical_error_and_discard_rate discard an erased shot, so the error committed for it does not reach a rate either of them reports.

This method accepts and returns boolean data.

dem_arrays
num_detectors
num_erasure_bits
num_observables
window_decoders
window_detectors
window_errors
class qldpc.decoders.sinter.CompiledSinterDecoder(dem_arrays: qldpc.decoders.dems.DetectorErrorModelArrays, decoder: qldpc.decoders.retrieval.Decoder)[source]

Bases: qldpc.decoders.retrieval.Decoder, sinter.CompiledDecoder

Decoder usable by Sinter for decoding circuit errors, compiled to a specific circuit.

Instances of this class are meant to be constructed by a SinterDecoder, whose .compile_decoder_for_dem method returns a CompiledSinterDecoder.

When the decoder being wrapped signals erasure with an erasure bit, .decode_shots appends one erasure bit to the observable flips of every shot, and .decode_shots_bit_packed reports those erasure bits in one whole byte added past the packed observable flips. Sinter reads that added byte as a request to discard the shot, so an erasure becomes a discarded shot rather than a predicted flip of an observable that the sampled circuit does not have.

decode(syndrome: numpy.typing.NDArray[numpy.int_]) → numpy.typing.NDArray[numpy.int_][source]

Alias for CompiledSinterDecoder.decode_shots.

Predicts observable flips.

decode_shots(detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Predicts observable flips from the given detection events.

This method accepts and returns boolean data.

See help(sinter.CompiledDecoder) for additional information.

decode_shots_bit_packed(bit_packed_detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Predicts observable flips from the given detection events.

This method accepts and returns bit-packed data.

See help(sinter.CompiledDecoder) for additional information.

pack_observable_flips(observable_flips: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Bit-pack predicted observable flips, signalling erasure in one whole added byte.

Sinter discards a shot whose bit-packed prediction is exactly one byte wider than the observables of the sampled circuit require, and whose extra byte is nonzero. Erasure is signalled in that byte, which keeps the packed predictions aligned with the observables that the circuit actually reports. A shot is erased if any erasure bit is set.

The added byte is read by the sampler that sinter runs a decoder under, and is not part of the return shape that sinter documents for a compiled decoder, which is one byte per eight observables. A sinter release can therefore change how the byte is read without contradicting its own documentation.

packbits(data: numpy.typing.NDArray[numpy.uint8], axis: int = -1) → numpy.typing.NDArray[numpy.uint8][source]

Bit-pack the data along an axis.

Working with bit-packed data is more memory and compute-efficient, which is why Sinter generally passes around bit-packed data.

unpack_detection_event_data(bit_packed_detection_event_data: numpy.typing.NDArray[numpy.uint8], axis: int = -1) → numpy.typing.NDArray[numpy.uint8][source]

Unpack the bit-packed data along an axis.

By default, bit_packed_detection_event_data is assumed to be a two-dimensional array in which each row contains bit-packed detection events from one sample of a detector error model (DEM). In this case, the unpacked data is a boolean matrix whose entry in row ss and column kk specify whether detector kk was flipped in sample ss of a DEM.

decoder
dem_arrays
num_detectors: int
num_erasure_bits: int = 0
num_observables: int
class qldpc.decoders.sinter.CompiledSubgraphDecoder(subgraph_detectors: collections.abc.Sequence[collections.abc.Sequence[int] | slice], subgraph_observables: collections.abc.Sequence[collections.abc.Sequence[int] | slice], subgraph_decoders: collections.abc.Sequence[CompiledSinterDecoder], num_detectors: int, num_observables: int, num_erasure_bits: int = 0)[source]

Bases: CompiledSinterDecoder

Decoder usable by Sinter for decoding circuit errors, compiled to a specific circuit.

This decoder splits a decoding problem into subgraphs that are decoded independently.

Instances of this class are meant to be constructed by a SubgraphDecoder, whose .compile_decoder_for_dem method returns a CompiledSubgraphDecoder. See help(SubgraphDecoder).

decode_shots(detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Predicts observable flips from the given detection events.

This method accepts and returns boolean data.

See help(sinter.CompiledDecoder) for additional information.

num_detectors
num_erasure_bits = 0
num_observables
subgraph_decoders
subgraph_detectors
subgraph_observables
class qldpc.decoders.sinter.CompiledTrivialDecoder(num_detectors: int, num_observables: int)[source]

Bases: CompiledSinterDecoder

A compiled trivial decoder that unconditionally predicts null errors/logical flips.

decode_shots(detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Unconditionally predicts no observable flips.

This method accepts and returns boolean data.

See help(sinter.CompiledDecoder) for additional information.

decode_shots_bit_packed(bit_packed_detection_event_data: numpy.typing.NDArray[numpy.uint8]) → numpy.typing.NDArray[numpy.uint8][source]

Unconditionally predicts no observable flips.

This method accepts and returns bit-packed data.

See help(sinter.CompiledDecoder) for additional information.

num_detectors
num_observables
packed_observable_size
class qldpc.decoders.sinter.SequentialSinterDecoder(detection_regions: collections.abc.Sequence[collections.abc.Collection[int]], commit_regions: collections.abc.Sequence[collections.abc.Collection[int]] | None = None, *, simplify: bool = True, decompose_errors: bool = False, **decoder_kwargs: object)[source]

Bases: SequentialWindowDecoder

Deprecated alias for SequentialWindowDecoder.

class qldpc.decoders.sinter.SequentialWindowDecoder(detection_regions: collections.abc.Sequence[collections.abc.Collection[int]], commit_regions: collections.abc.Sequence[collections.abc.Collection[int]] | None = None, *, simplify: bool = True, decompose_errors: bool = False, **decoder_kwargs: object)[source]

Bases: SinterDecoder

Decoder usable by Sinter for decoding circuit errors.

A SequentialWindowDecoder splits a detector error model into (possibly overlapping) “windows”. Each window is defined by two sets of detectors, which in turn define a “detection region” and a “commit region” for that window. Each region consists of a (given) set of detectors and the (induced) set of error mechanisms that trigger those detectors.

Windows are decoded sequentially, one by one. To decode a window, we first decode the syndrome in its detection region. We then “commit” to the decoded circuit error in the commit region, which entails

  1. removing the error mechanisms in the commit region from all subsequent windows, and

  2. emulating the active correction of committed errors by appropriately updating the syndromes in subsequent windows.

The net circuit error inferred by decoding all windows is used to predict observable flips.

A window decoder that signals erasure erases the whole shot, and all the windows share the one erasure bit that the compiled decoder reports.

A SequentialWindowDecoder initialized without specifying commit regions sets the commit region of each window to the corresponding detection region.

A special case of SequentialWindowDecoder is a SlidingWindowDecoder, in which case this decoding method is known as the “overlapping recovery method” in arXiv:quant-ph/0110143, which is explained more nicely in arXiv:2012.15403 and arXiv:2209.08552.

compile_decoder_for_dem(dem: stim.DetectorErrorModel) → CompiledSequentialWindowDecoder[source]

Creates a decoder preconfigured for the given detector error model.

See help(sinter.Decoder) for additional information.

windows
class qldpc.decoders.sinter.SinterDecoder(*, simplify: bool = True, decompose_errors: bool = False, **decoder_kwargs: object)[source]

Bases: qldpc.decoders.retrieval.Decoder, sinter.Decoder

Decoder usable by Sinter for decoding circuit errors.

compile_decoder_for_dem(dem: stim.DetectorErrorModel) → CompiledSinterDecoder[source]

Creates a decoder preconfigured for the given detector error model.

See help(sinter.Decoder) for additional information.

decode(syndrome: numpy.typing.NDArray[numpy.int_]) → numpy.typing.NDArray[numpy.int_][source]

Decode an error syndrome and return an inferred error.

decode_via_files(*, num_shots: int, num_dets: int, num_obs: int, dem_path: pathlib.Path, dets_b8_in_path: pathlib.Path, obs_predictions_b8_out_path: pathlib.Path, tmp_dir: pathlib.Path) → None[source]

Predict observable flips for detection events read from a file, and write them to a file.

See help(sinter.Decoder) for additional information.

A file of predictions holds exactly one observable flip per observable, with no room for the byte in which a decoder asks for a shot to be discarded, so an erased shot is reported here with the observable flips that its decoder predicts for it anyway. Sample with sinter.collect or with qldpc.circuits.get_logical_error_and_discard_rate to have erased shots discarded instead of predicted.

decoder_kwargs
decompose_errors = False
simplify = True
class qldpc.decoders.sinter.SlidingWindowDecoder(window_size: int, stride: int, detector_subsets: collections.abc.Collection[collections.abc.Collection[int]] | None = None, detector_to_time: collections.abc.Callable[[int], int] | None = None, *, simplify: bool = True, decompose_errors: bool = False, **decoder_kwargs: object)[source]

Bases: SequentialWindowDecoder

Decoder usable by Sinter for decoding circuit errors.

A SlidingWindowDecoder is a SequentialWindowDecoder whose windows are constructed by grouping detectors based on a time coordinate. The amount of overlapping rounds between adjacent windows is determined by the window size and stride. For example, a window size of w and a stride of s indicates adjacent windows will overlap on w - s rounds. The “commit region” for each window therefore corresponds to the first s rounds in the window.

Visually:

Time:      |------------------------------------------------------------>

Window 1:  [ ........... Detection Region ........... ]
           [ Commit Region ]
               |
               +---> 1. Decode errors in Detection Region.
                     2. Commit to errors in Commit Region.
                     3. Update syndromes in future windows based on committed errors.
                     4. Slide window forward.
                                          |
                                          v
Window 2:                   [ ........... Detection Region ........... ]
                            [ Commit Region ]
                                |
                                v
                               ...

If provided a sequence of subsets of detectors, construct sliding windows for each subset. This functionality is used to independently decode X and Z sectors of a CSS code.

This decoding method is known as the “overlapping recovery method” in arXiv:quant-ph/0110143, which is explained more nicely in arXiv:2012.15403 and arXiv:2209.08552.

compile_decoder_for_dem(dem: stim.DetectorErrorModel) → CompiledSequentialWindowDecoder[source]

Creates a decoder preconfigured for the given detector error model.

WARNING: if this decoder was initialized with a detector_to_time mapping, it is assumed that the mapping is both valid and compatible with the detector error model provided here.

See help(sinter.Decoder) for additional information.

detector_subsets = None
detector_to_time = None
stride
window_size
class qldpc.decoders.sinter.SubgraphDecoder(subgraph_detectors: collections.abc.Sequence[collections.abc.Collection[int]], subgraph_observables: collections.abc.Sequence[collections.abc.Collection[int]] | None = None, *, simplify: bool = True, decompose_errors: bool = False, **decoder_kwargs: object)[source]

Bases: SinterDecoder

Decoder usable by Sinter for decoding circuit errors.

A SubgraphDecoder splits the Tanner graph of a detector error model into subgraphs, and decodes these subgraphs independently. Each subgraph is defined by a subset of detectors, S. When compiling a SubgraphDecoder for a specific detector error model D, this decoder constructs, for each subgraph S, a smaller detector error model D_S that restricts D to the detectors in S and the error mechanisms that flip the detectors in S.

A SubgraphDecoder may optionally assign each subgraph S a set of observables, O_S, in which case the subgraph detector error model D_S only considers (and predicts corrections for) the observables in O_S.

The subgraphs predict observable flips independently, and their predictions are combined by exclusive or. Every observable therefore has to be assigned to the subgraphs in a way that lets exactly one of them predict each of its flips: if two subgraphs both witness an error mechanism and both own an observable that the mechanism flips, then both predict that flip and the two predictions cancel. Compiling a SubgraphDecoder warns when a detector error model and a partition permit that, and when a detector belongs to no subgraph at all.

As an example, a SubgraphDecoder is useful for independently decoding the X and Z sectors of a CSS code, where each sector owns the observables of the opposite type.

compile_decoder_for_dem(dem: stim.DetectorErrorModel) → CompiledSubgraphDecoder[source]

Creates a decoder preconfigured for the given detector error model.

See help(sinter.Decoder) for additional information.

num_subgraphs
subgraph_detectors
subgraph_observables = None
class qldpc.decoders.sinter.SubgraphSinterDecoder(subgraph_detectors: collections.abc.Sequence[collections.abc.Collection[int]], subgraph_observables: collections.abc.Sequence[collections.abc.Collection[int]] | None = None, *, simplify: bool = True, decompose_errors: bool = False, **decoder_kwargs: object)[source]

Bases: SubgraphDecoder

Deprecated alias for SubgraphDecoder.

class qldpc.decoders.sinter.TrivialDecoder[source]

Bases: SinterDecoder

A trivial decoder that unconditionally predicts null errors/logical flips.

compile_decoder_for_dem(dem: stim.DetectorErrorModel) → CompiledSinterDecoder[source]

Creates a decoder preconfigured for the given detector error model.

See help(sinter.Decoder) for additional information.