qldpc.decoders.custom
Custom decoder classes.
Attributes
Classes
Template class for a decoder that can decode in batches. |
|
Decoder for a composite syndrome from multiple independent code blocks. |
|
Template class for a decoder. |
|
Decoder that maps corrupted code words to corrected code words. |
|
The generalized Union-Find (GUF) decoder in https://arxiv.org/abs/2103.08049. |
|
Decoder based on solving an integer linear program (ILP). |
|
Wrapper class for Relay-BP decoders, introduced in arXiv:2506.01779. |
Module Contents
- class qldpc.decoders.custom.BatchDecoder[source]
Bases:
ProtocolTemplate class for a decoder that can decode in batches.
- class qldpc.decoders.custom.CompositeDecoder(*decoders_and_syndrome_lengths: tuple[Decoder, int])[source]
Decoder for a composite syndrome from multiple independent code blocks.
A CompositeDecoder is instantiated from a sequence of tuples, where each tuple contains
the decoder for a one code block
the length of a syndrome vector for that code block.
When asked to decode a syndrome, a CompositeDecoder splits the syndrome into segments of appropriate lengths, and decodes these segments independently with their corresponding decoders.
Decoded segments are concatenated. Any number of the decoders may have an erasure bit; a CompositeDecoder collects them into the single erasure bit that it advertises as its own, which is set whenever any code block is erased.
- decode(syndrome: numpy.typing.NDArray[numpy.int_]) numpy.typing.NDArray[numpy.int_][source]
Decode an error syndrome by parts.
- static from_copies(decoder: Decoder, syndrome_length: int, num_copies: int) CompositeDecoder[source]
Initialize a CompositeDecoder from copies of a given decoder and syndrome_length.
- decode_batch_implemented
- erasing_decoders
- has_erasure_bit
- slices
- class qldpc.decoders.custom.DirectDecoder(decode_func: collections.abc.Callable[[numpy.typing.NDArray[numpy.int_]], numpy.typing.NDArray[numpy.int_]], decode_batch_func: collections.abc.Callable[[numpy.typing.NDArray[numpy.int_]], numpy.typing.NDArray[numpy.int_]] | None = None)[source]
Decoder that maps corrupted code words to corrected code words.
In contrast, an “indirect” decoder maps a syndrome to an error.
A DirectDecoder can be instantiated from:
an indirect decoder, and
a parity check matrix.
When asked to decode a candidate code word, a DirectDecoder first computes a syndrome, decodes the syndrome with an indirect decoder to infer an error, and then subtracts the error from the candidate word.
- decode(word: numpy.typing.NDArray[numpy.int_]) numpy.typing.NDArray[numpy.int_][source]
Decode a corrupted code word and return a corrected code word.
- static from_indirect(decoder: Decoder, matrix: qldpc.math.IntegerArray) DirectDecoder[source]
Instantiate a DirectDecoder from an indirect decoder and a parity check matrix.
- decode_batch_func = None
- decode_func
- class qldpc.decoders.custom.GUFDecoder(matrix: qldpc.math.IntegerArray, *, max_weight: int | None = None, symplectic: bool = False, add_erasure_bit: bool = False)[source]
The generalized Union-Find (GUF) decoder in https://arxiv.org/abs/2103.08049.
If passed a max_weight argument, this decoder tries to find an error with
weight <= max_weight, and returns the first such error that it finds. If no such error is found, this decoder returns the minimum-weight error that it found while trying. Be warned that passing a max_weight makes this decoder have worst-case exponential runtime.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 and Z support of a stabilizer. Decoded errors are likewise vectors that indicate their X and Z support by the first and second half of their entries.If initialized with
add_erasure_bit=True, this decoder appends a bit to all decoded errors, set to 1 when its search exhausts without finding an error that reproduces the syndrome, and to 0 otherwise. Without that bit, an exhausted search is reported as the all-zero error, which is indistinguishable from the error inferred for a trivial syndrome.Warning: this implementation of the generalized Union-Find decoder is highly unoptimized. For one, it is written entirely in Python. Moreover, this implementation does not factor an error set into connected components.
- decode(syndrome: numpy.typing.NDArray[numpy.int_], *, max_weight: int | None = None) numpy.typing.NDArray[numpy.int_][source]
Decode an error syndrome and return an inferred error.
If the search exhausts without finding an error that reproduces the given syndrome, return the all-zero error, whose appended erasure bit is set if this decoder tracks one.
- get_sub_problem_indices(syndrome: numpy.typing.NDArray[numpy.int_], error_set: set[qldpc.objects.Node]) tuple[list[int], list[int]][source]
Syndrome and data bit indices for decoding on the interior of the given error set.
- code: qldpc.codes.AbstractCode
- default_max_weight = None
- get_weight: collections.abc.Callable[[numpy.typing.NDArray[numpy.int_]], numpy.intp | numpy.typing.NDArray[numpy.int_]]
- graph
- has_erasure_bit = False
- symplectic = False
- class qldpc.decoders.custom.ILPDecoder(matrix: qldpc.math.IntegerArray, *, add_erasure_bit: bool = False, **decoder_args: object)[source]
Decoder based on solving an integer linear program (ILP).
An integer program that is allowed to run to completion either finds an error of minimum weight that reproduces the syndrome or proves that no error reproduces it, so an inferred error that does not reproduce the syndrome means the solver stopped early, at a point it never proved feasible.
time_limitandmip_max_nodesare the arguments that ask it to stop early.If initialized with
add_erasure_bit=True, this decoder appends a bit to all decoded errors, set to 1 for a syndrome that it cannot explain and to 0 otherwise. Without that bit there is no way to report such a syndrome, so it is rejected instead.A syndrome goes unexplained either because the inferred error does not reproduce it, or because the program reports no solution for it at all. The second case also warns, since a program reports no solution both when it proves that no error reproduces the syndrome and when it fails.
All remaining keyword arguments are passed to cvxpy.Problem.solve.
- cvxpy_constraints_for_syndrome(syndrome: numpy.typing.NDArray[numpy.int_]) list[cvxpy.Constraint][source]
Build cvxpy constraints of the form
matrix @ variables == syndrome (mod q).This method relaxes each constraint of the form
expression = val mod qtoexpression = val + q t, where t is a nonnegative integer built out of boolean variables {b_j} ast = sum_j 2^j b_j.Since the variables are nonnegative and val is reduced mod q,
expression - valis a nonnegative multiple of q, so t is nonnegative, and it is bounded above by the largest value thatexpressioncan take, less val, in units of q. Enough bits to reach that bound reach every value below it too, since a binary expansion represents every integer in range.
- decode(syndrome: numpy.typing.NDArray[numpy.int_]) numpy.typing.NDArray[numpy.int_][source]
Decode an error syndrome and return an inferred error.
- decoder_args
- has_erasure_bit = False
- matrix
- modulus
- variable_constraints = []
- class qldpc.decoders.custom.RelayBPDecoder(pcm_or_dem: qldpc.math.IntegerArray | stim.DetectorErrorModel, error_priors: numpy.typing.NDArray[numpy.floating] | collections.abc.Sequence[float] | None = None, *, name: str = 'RelayDecoderF32', observable_error_matrix: qldpc.math.IntegerArray | None = None, include_decode_result: bool = False, add_erasure_bit: bool = False, **decoder_args: object)[source]
Wrapper class for Relay-BP decoders, introduced in arXiv:2506.01779.
Requires relay_bp to be installed, for example via “pip install ‘qldpc[relay-bp]’”.
This class first constructs a relay_bp.decoder.DynDecoder decoder by class name, such as “RelayDecoderF32”; see help(relay_bp) for more options. To enable parallelized decoding, which as of relay-bp==0.2.1 is only implemented for the relay_bp.ObservableDecoderRunner class, RelayBPDecoder wraps the relay_bp.decoder.DynDecoder in a relay_bp.ObservableDecoderRunner at initialization time.
IMPORTANT POINTS TO NOTE:
- relay_bp.ObservableDecoderRunner expects to be passed an observable_error_matrix when
initialized. If a RelayBPDecoder is initialized without an observable_error_matrix, this matrix is set to np.empty((0, 0), dtype=np.uint8). All observable-related methods of the decoder will subsequently fail.
- RelayBPDecoder “wants” to be a subclass of relay_bp.ObservableDecoderRunner. However, the
latter does not allow subclassing because it is implemented in rust and exposed to Python via bindings. As a hack, if a decoder: RelayBPDecoder is asked for a method or attribute it does not recognize, such as decoder.decode_observables_batch(detectors, parallel=True) or decoder.decode_detailed(detectors), it tries to pass all arguments to an identically-named method of relay_bp.ObservableDecoderRunner. A consequence of this hack is that most of the methods that are recognized by RelayBPDecoder in practice do not appear in its documentation. See help(relay_bp.ObservableDecoderRunner) for a list of all RelayBPDecoder methods.
For details about Relay-BP decoders, see:
Documentation: https://pypi.org/project/relay-bp
Reference: https://arxiv.org/abs/2506.01779
If initialized with
add_erasure_bit=True, this decoder appends a bit to all decoded errors, set to 1 when the error Relay-BP settles on does not reproduce the syndrome and to 0 otherwise.- decode(/, detectors) numpy.typing.NDArray[numpy.int_][source]
Decode an error syndrome and return an inferred error.
Typecast detectors to np.uint8 for compatibility with the relay_bp package.
- decode_batch(/, detectors: bool, parallel: bool = False, progress_bar: bool = True, leave_progress_bar_on_finish=False) numpy.typing.NDArray[numpy.int_][source]
Decode a batch of error syndromes and return inferred errors.
Typecast detectors to np.uint8 for compatibility with the relay_bp package.
- decoder
- has_erasure_bit = False
- pcm_transposed
- qldpc.decoders.custom.PLACEHOLDER_ERROR_RATE = 0.001