qldpc.decoders.lookup
Lookup-table decoder classes.
Classes
Decoder based on a lookup table that maps syndromes to errors. |
|
Decoder based on a lookup table that maps syndromes to errors. |
Module Contents
- class qldpc.decoders.lookup.LookupDecoder(pcm_or_dem: qldpc.math.IntegerArray | stim.DetectorErrorModel, max_weight: int, *, error_channel: numpy.typing.NDArray[numpy.floating] | collections.abc.Sequence[float] | None = None, penalty_func: collections.abc.Callable[[numpy.typing.NDArray[numpy.int_] | collections.abc.Sequence[int]], float] | None = None, observable_flip_matrix: qldpc.math.IntegerArray | None = None, predict_observable_flips: bool = False, post_select: collections.abc.Collection[int] = (), add_erasure_bit: bool | None = None, confidence_ratio: float | None = None, symplectic: bool = False)[source]
Decoder based on a lookup table that maps syndromes to errors.
Accepts a parity check matrix (PCM) or detector error model (DEM) for
pcm_or_dem. If provided a DEM, this decoder extracts a PCM,error_channel, andobservable_flip_matrixfrom the DEM, which are used as described below.In addition to a PCM, this decoder needs to be initialized with some choice of
max_weight. The decoder enumerates all errors withweight <= max_weightin order of decreasing weight. For eacherror, the decoder computes the correspondingsyndrome, and nominally adds ansyndrome -> errorentry to the lookup table, overriding any past entry forsyndrome.If provided an
error_channelof independent probabilities for each “primitive” error mechanism (which associated with one column of a PCM, or one entry in a DEM), this method constructs a penalty function,penalty_func, that penalizes unlikely errors. In this case, a candidatesyndrome -> new_errorentry encountered during enumeration will only override a past entry in the lookup table ifpenalty_func(new_error) <= penalty_func(old_error). Errors are enumerated in decreasing weight, so an equal penalty resolves in favor of the lighter error. Alternatively, this decoder supports the use of a user-providedpenalty_func, which must map an error (represented as a binary vector of lengthnum_primitive_error_mechanisms) to a real number (i.e., a penalty).If provided an
observable_flip_matrix(shapenum_observables × num_primitive_errors), this decoder maps each syndrome to an error that induces the most likely observable flip for that syndrome, which may be different from the single most likely error. Concretely: errors consistent with a given syndrome are grouped by their observable flip value; the total probability of each group is the sum of the probabilities of its member errors, restricted to the errors ofweight <= max_weightthat this decoder enumerates. This decoder then assigns eachsyndromethe highest-probability individualerrorfrom the group with the highest total probability.If initialized with
predict_observable_flips=True, this decoder maps each syndrome directly to its most likely observable flip, rather than to a representativeerror. In this case the decoded output is a vector of lengthnum_observablesover the field of the parity check matrix. Predicting observable flips requires anobservable_flip_matrix.If provided a
post_selectcollection of syndrome-bit (i.e., detector) indices, this decoder post-selects on those bits being trivial: when constructing the lookup table, it ignores syndromes that are nonzero on the post-selected bits, and it drops those bits from the syndrome keys in the lookup table. For consistency with the post-selection options in sinter, syndromes passed toLookupDecoder.decodeshould still contain all syndrome bits. A syndrome that is nonzero on a post-selected bit is one that the lookup table was never given, so it decodes identically to a syndrome that was never enumerated.If initialized with
add_erasure_bit=True, this decoder appends a bit to all decoded errors. If asked to decode a syndrome that was not observed when constructing the lookup table, the erasure bit is set to 1. The erasure bit is set to 0 otherwise.If initialized with a positive
confidence_ratio(which then requires anobservable_flip_matrix), this decoder handles ambiguous syndromes – those consistent with more than one observable flip – by declining to guess unless one flip is clearly dominant. Lettingprob_topandprob_restbe the net probabilities of the most likely observable flip and of all other flips combined (summed over the enumeratedweight <= max_weighterrors, grouped as above), the decoder assigns the most likely flip iff it is at leastconfidence_ratiotimes as likely as the rest, i.e.prob_top >= confidence_ratio * prob_rest. Otherwise, the syndrome is omitted from the lookup table, so that it decodes to erasure, identically to a syndrome that was never enumerated. A positiveconfidence_ratiotherefore auto-enables the erasure bit, settingadd_erasure_bit=True. At the extreme,confidence_ratio=np.infkeeps only syndromes whose competing flips have zero net probability, erasing every syndrome with a competing flip that can actually occur.If initialized with
symplectic=True, this decoder treats the provided parity check matrix as that of aQuditCode, with the first and last half of the columns denoting, respectively, the[X|Z]support of a stabilizer. Decoded errors are likewise vectors that indicate[X|Z]support.- decode(syndrome: numpy.typing.NDArray[numpy.int_]) numpy.typing.NDArray[numpy.int_][source]
Decode an error syndrome and return an inferred error.
If initialized with predict_observable_flips=True, return the inferred observable flip.
- default_correction
- has_erasure_bit = False
- predict_observable_flips = False
- syndrome_mask = None
- syndrome_to_error: dict[tuple[int, ...], numpy.typing.NDArray[numpy.int_]]
- class qldpc.decoders.lookup.WeightedLookupDecoder(pcm_or_dem: qldpc.math.IntegerArray | stim.DetectorErrorModel, max_weight: int, *, observable_flip_matrix: qldpc.math.IntegerArray | None = None, predict_observable_flips: bool = False, post_select: collections.abc.Collection[int] = (), add_erasure_bit: bool = False, symplectic: bool = False)[source]
Bases:
LookupDecoderDecoder based on a lookup table that maps syndromes to errors.
A WeightedLookupDecoder is a LookupDecoder that, when initialized, records all errors that are consistent with a given syndrome. The WeightedLookupDecoder then minimizes a penalty function that is provided to the .decode method. A WeightedLookupDecoder can thereby be initialized once, and subsequently asked to decode with different penalty functions.
- decode(syndrome: numpy.typing.NDArray[numpy.int_], penalty_func: collections.abc.Callable[[numpy.typing.NDArray[numpy.int_]], float] | None = lambda vec: ...) numpy.typing.NDArray[numpy.int_][source]
Decode an error syndrome and return an inferred error.
- default_correction
- has_erasure_bit = False
- predict_observable_flips = False
- symplectic = False
- syndrome_mask = None
- syndrome_to_candidates: dict[tuple[int, ...], list[tuple[numpy.typing.NDArray[numpy.int_], numpy.typing.NDArray[numpy.int_]]]]