localuf.decoders.mwpm¶
Classes
|
Minimum weight perfect matching decoder using PyMatching implementation. |
- class localuf.decoders.mwpm.MWPM(code, detector_to_int=None, _edge_weight_modifier=None)[source]¶
Bases:
DecoderMinimum 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.
- 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 byself.CODE.DETECTORS.
- decode(syndrome)[source]¶
Decode syndrome.
- Parameters:
syndrome (set[tuple[int, ...]]) – The set of defect coordinates.
Side effects: * Update
self.correction_vectorandself.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.correctionto 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.drawe.g.margins=(0.1, 0.1).
- complementary_gap(syndrome)[source]¶
Decode
syndromeand 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_NODESisFalse.- 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(). IfNone, all edges in the matching objects will have error probability 0 and weight 1 (before being scaled byself._edge_weight_modifier).
Side effects: * Update
self.noise_level. * Updateself.matching. * Updateself._complementary_gap_matchings.