localuf.decoders.uf¶
Classes
|
Abstract base class for the cluster in UF. |
|
The original, algorithmic UF decoder. |
- class localuf.decoders.uf.UF(code, dynamic=False, inclination='default')[source]¶
Bases:
BaseUFThe original, algorithmic UF decoder.
Extends
BaseUF. Incompatible with the frugal decoding scheme.Additional instance constants:
_FORESTERdecides whether to maintain a static or dynamic forest._INCLINATIONa class that decides which boundary the root should be onwhen there is a percolating cluster i.e. one that spans opposite boundaries. Has the
update_boundarymethod.
Additional instance attributes:
parentsmaps each node in the decoding graph to its parent node.clustersmaps each root node to the cluster of that root node.Initially, EVERY node its own cluster; then, only grow active clusters.
active_clustersthe set of clusterswith odd defect count and no boundary node.
forestthe spanning forest after syndrome validation as a list of pairs (edge, node)where node is the further endpoint from the root of the tree in the forest.
digrapha NetworkX digraph offorest.
- Parameters:
code (Code)
dynamic (bool)
inclination (Literal['default', 'west'])
- reset(no_boundaries=False)[source]¶
Factory reset.
- Parameters:
no_boundaries – whether to treat all boundary nodes as detectors too.
- decode(syndrome, draw=False, fig_width=None)[source]¶
Additional inputs over
Decoder.decode():fig_widthfigure width.
- Parameters:
syndrome (set[tuple[int, ...]])
fig_width (float | None)
- complementary_gap(noise_level=None, draw=False, fig_width=None, fig_height=None, **kwargs_for_networkx_draw)[source]¶
Calculate the complementary gap after decoding.
Assumes
self.decode()has already been called. Ifself.CODE.MERGED_EQUIVALENT_BOUNDARY_NODESisFalse, raises aValueError.- Parameters:
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.draw – whether to draw the original and complementary corrections.
fig_width (float | None) – figure width.
fig_height (float | None) – figure height.
kwargs_for_networkx_draw – passed to
networkx.draw().
- Returns:
weight_2 - weight_1the complementary gap.
Side effects:
selfends up in the final state after computing the complementary correction.- All clusters are blind to boundary nodes
so will stop growing only once they have an odd defect count.
- unclustered_node_fraction()[source]¶
Compute the Unclustered Node Fraction DCS.
- Return fraction:
The fraction of nodes that are not in a cluster.
- validate(syndrome, log_history=False)[source]¶
Grow all active clusters until they are inactive.
- Parameters:
syndrome (set[tuple[int, ...]])
- static_merge(cu, cv)[source]¶
Merge clusters
cuandcvalong edgeuvfor static UF.- Parameters:
cu (_Cluster)
cv (_Cluster)
- dynamic_merge(cu, cv, e)[source]¶
Merge clusters
cuandcvalong edgeuvfor dynamic UF.- Parameters:
cu (_Cluster)
cv (_Cluster)
e (tuple[tuple[int, ...], tuple[int, ...]])
- draw_growth(**kwargs)[source]¶
Draw growth of edges using matplotlib.
- Parameters:
growth – A dictionary where each key an edge index; value, its growth value.
syndrome – The set of defects.
highlighted_edges – The set of edges to be highlighted in drawing.
x_offset – The ratio of out-of-screen to along-screen distance.
with_labels – Whether to show node labels.
labels – A dictionary where each key a node index; value, its label as a string.
width – Line width of edges.
arrows – Whether to draw arrows on edges used by pointers. For
Macar, Actis, Snowflakedecoders only.kwargs_for_networkx_draw – Passed to
networkx.draw(). E.g.linewidthsline width of node symbol border.
- property digraph¶
Return a NetworkX digraph representing the spanning forest after syndrome validation.
Note: Requires calling
peel()first.
- draw_forest(x_offset=0.2, node_size=50, width=2.0, edge_color='g', boundary_color='#9cdaed', defect_color='#Ff6666', nondefect_color='#Bef4be', show_boundary_defects=True, **kwargs_for_networkx_draw)[source]¶
Draw spanning forest.
kwargs_for_networkx_drawpassed tonetworkx.draw().Note: Not as informative as draw_peel().
- draw_peel(x_offset=0.2, node_size=50, width=2.0, correction_color='k', boundary_color='#9cdaed', defect_color='#Ff6666', nondefect_color='#Bef4be', show_boundary_defects=True, **kwargs_for_networkx_draw)[source]¶
Draw forest and correction from peeling.
kwargs_for_networkx_drawpassed tonetworkx.draw().Note: Requires calling
peel()first.
- class localuf.decoders.uf.BaseCluster(uf, root, no_boundaries=False)[source]¶
Bases:
ABCAbstract base class for the cluster in UF.
Mathematically, a cluster is a connected subgraph of the decoding graph.
Attributes:
rootthe representative of the cluster.sizethe number of nodes in the cluster.odda Boolean to say if the number of defects in the cluster is odd.boundarythe node in the cluster that is the surface boundary if it exists; else, None.If
cluster.boundarynot None, cluster will never be active in future. If syndrome validation not dynamic, boundary may not be unique!
- Parameters:
uf (UF)
root (tuple[int, ...])