localuf.decoders.mwpm

Classes

MWPM(code[, detector_to_int, ...])

Minimum weight perfect matching decoder using PyMatching implementation.

class localuf.decoders.mwpm.MWPM(code, detector_to_int=None, _edge_weight_modifier=None)[source]

Bases: Decoder

Minimum weight perfect matching decoder using PyMatching implementation.

Extends Decoder. Compatible so far only with the batch and forward decoding schemes.

Parameters:
  • code (Code)

  • detector_to_int (None | dict[tuple[int, ...], int])

  • _edge_weight_modifier (dict[tuple[tuple[int, ...], tuple[int, ...]], float])

correction_vector: ndarray[tuple[int], dtype[uint8]]

The stored correction as a binary vector whose length is the number of fault IDs.

correction_weight: float = 0

The weight of the stored correction.

DETECTOR_TO_INT

Map from each detector node index to a unique integer in 0..detector_count.

noise_level: None | float

A probability representing the noise strength. This is needed to define nonuniform edge weights of the decoding graph in the circuit-level noise model. If None, all edges are assumed to have weight 1.

reset()[source]

Factory reset.

get_binary_vector(syndrome)[source]

Convert a set of defect coordinates to a binary vector.

Parameters:

syndrome (set[tuple[int, ...]]) – The set of defect coordinates.

Return binary_vector:

A binary vector of length equal to detector count whose ordering is given by self.DETECTOR_TO_INT. If not specified, uses ordering given by self.CODE.DETECTORS.

decode(syndrome)[source]

Decode syndrome.

Parameters:

syndrome (set[tuple[int, ...]]) – The set of defect coordinates.

Side effects: * Update self.correction_vector and self.correction_weight.

decode_to_edge_set(syndrome_vector)[source]

Find the set of edges in the minimum-weight correction.

Parameters:

syndrome_vector (ndarray[tuple[int], dtype[uint8]]) – A binary vector of length equal to detector count representing the set of defects.

Side effect: Set self.correction to the set of edges in the minimum-weight correction.

draw_decode(**kwargs_for_networkx_draw)[source]

Draw all stages of decoding.

Parameters:

kwargs_for_networkx_draw – keyword arguments passed to NetworkX.draw e.g. margins=(0.1, 0.1).

complementary_gap(syndrome)[source]

Decode syndrome and calculate the complementary gap.

Does not require self.decode() to be called first.

Parameters:

syndrome (set[tuple[int, ...]]) – the set of defects.

Return correction_bit:

The parity of number of edges in the minimum-weight correction that connect to the west boundary node.

Return gap:

The complementary gap.

Raises:

ValueError – if self.CODE.MERGED_EQUIVALENT_BOUNDARY_NODES is False.

Return type:

tuple[uint8, float]

set_noise_level(noise_level=None)[source]

Set the noise level of the decoder and preconstruct matching objects.

Parameters:

noise_level (None | float) – A probability that represents the noise strength. This is passed to self.CODE.NOISE.get_edge_weights(). If None, all edges in the matching objects will have error probability 0 and weight 1 (before being scaled by self._edge_weight_modifier).

Side effects: * Update self.noise_level. * Update self.matching. * Update self._complementary_gap_matchings.