qldpc.decoders.lookup

Lookup-table decoder classes.

Classes

LookupDecoder

Decoder based on a lookup table that maps syndromes to errors.

WeightedLookupDecoder

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, and observable_flip_matrix from 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 with weight <= max_weight in order of decreasing weight. For each error, the decoder computes the corresponding syndrome, and nominally adds an syndrome -> error entry to the lookup table, overriding any past entry for syndrome.

If provided an error_channel of 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 candidate syndrome -> new_error entry encountered during enumeration will only override a past entry in the lookup table if penalty_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-provided penalty_func, which must map an error (represented as a binary vector of length num_primitive_error_mechanisms) to a real number (i.e., a penalty).

If provided an observable_flip_matrix (shape num_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 of weight <= max_weight that this decoder enumerates. This decoder then assigns each syndrome the highest-probability individual error from 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 representative error. In this case the decoded output is a vector of length num_observables over the field of the parity check matrix. Predicting observable flips requires an observable_flip_matrix.

If provided a post_select collection 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 to LookupDecoder.decode should 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 an observable_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. Letting prob_top and prob_rest be the net probabilities of the most likely observable flip and of all other flips combined (summed over the enumerated weight <= max_weight errors, grouped as above), the decoder assigns the most likely flip iff it is at least confidence_ratio times 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 positive confidence_ratio therefore auto-enables the erasure bit, setting add_erasure_bit=True. At the extreme, confidence_ratio=np.inf keeps 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 a QuditCode, 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: LookupDecoder

Decoder 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_]]]]