DecodingGraph

class DecodingGraph(code, brute=False, graph=None, hyperedges=None)[source]

Bases: object

Class to construct the decoding graph for the code given by a CodeCircuit object, for use in a decoder. Class to construct the graph corresponding to the possible syndromes of a quantum error correction code, and then run suitable decoders.

Parameters:
  • code (CodeCircuit) – The QEC code circuit object for which this decoding graph will be created. If None, graph will initialized as empty.

  • brute (bool) – Whether to create the graph by analysing the circuits,

  • class (or to use a helper method from the code)

Methods

clean_measurements(nodes)[source]

Removes pairs of nodes that obviously correspond to measurement errors from a list of nodes.

Parameters:

nodes (List) – A list of nodes.

Returns:

The input list of nodes, with pairs removed if they obviously correspond to a measurement error.

Return type:

nodes

edge_in_graph(edge)[source]

Given a pair of node indices for graph, determines whether the edge exists within the graph.

Parameters:

edge (tuple) – Pair of node indices for the graph.

Returns:

Whether the edge is within the graph.

Return type:

in_graph (bool)

get_edge_graph()[source]

Returns a copy of the graph that uses edges to store information about the effects of errors on logical operators. This is done via the ‘fault_ids’ of the edges. No logical nodes are present in such a graph.

Returns:

The edge graph.

Return type:

edge_graph (rx.PyGraph)

get_error_probs(counts, logical='0', method='spitz', return_samples=False)[source]

Generate probabilities of single error events from result counts.

Parameters:
  • counts (dict) – Counts dictionary of the results to be analyzed.

  • logical (string) – Logical value whose results are used.

  • method (string) – Method to used for calculation. Supported

  • 'spitz' (methods are)

  • return_samples (bool) – Whether to also return the number of

  • probability. (samples used to calculated each)

Returns:

Keys are the edges for specific error events, and values are the calculated probabilities.

Return type:

dict

Additional information:

Uses counts to estimate the probability of the errors that create the pairs of nodes specified by the edge. Default calculation method is that of Spitz, et al. https://doi.org/10.1002/qute.201800012

get_node_graph()[source]

Returns a copy of the graph that uses logical nodes to store information about the effects of errors on logical operators. No non-trivial ‘fault_ids’ are present in such a graph.

Returns:

The node graph.

Return type:

node_graph (rx.PyGraph)

make_error_graph(data, all_logicals=True)[source]

Returns error graph.

Parameters:
  • data (Union[str, List]) – Either an ouput string of the code, or a list of

  • code. (nodes for the)

  • all_logicals (bool) – Whether to do all logicals

Returns:

The subgraph of graph which corresponds to the non-trivial syndrome elements in the given string.

node_index(node)[source]

Given a node of graph, returns the corrsponding index.

Parameters:

node (DecodingGraphNode) – Node of the graph.

Returns:

Index corresponding to the node within the graph.

Return type:

n (int)

update_attributes()[source]

Calculates properties of the graph used by node_index and edge_in_graph. If graph is updated this method should called to update these properties.

weight_syndrome_graph(counts=None, method='spitz', error_probs=None)[source]

Generate weighted syndrome graph from result counts.

Parameters:
  • counts (dict) – Counts dictionary of the results used to calculate

  • weights. (the)

  • method (string) – Method to used for calculation. Supported

  • 'spitz' (methods are)

  • error_probs (dict) – probability that the syndrome contains the node pair

  • given. (of a given edge. Overridden by counts if both are)

Additional information:

Uses counts to estimate the probability of the errors that create the pairs of nodes in graph. The edge weights are then replaced with the corresponding -log(p/(1-p).

Attributes

AVAILABLE_METHODS = {'naive', 'spitz'}
METHOD_NAIVE: str = 'naive'
METHOD_SPITZ: str = 'spitz'