flamingpy.codes.StabilizerGraph

class flamingpy.codes.StabilizerGraph(ec=None, code=None)[source]

Bases: abc.ABC

An abstraction for a stabilizer graph.

Stablizer graphs are a intermediate representations of qubit codes used by decoders such as minimum weight perfect matching (MWPM).

The nodes of a stabilizer graph are every stabilizer element in a code and every boundary point (coming from the type of boundary determined by the error complex – primal or dual). Two stabilizers (or a stabilizer and a boundary point) sharing a vertex are connected by an edge whose weight is equal to the weight assigned to that vertex in the code. The weight is computed on the fly while computing the shortest path.

The main function of a stabilizer graph is to be fed into the decoder. In the case of MWPM, it is used to compute the shortest paths between many nodes in order to construct the matching graph.

Parameters
  • ec (str, optional) – the error complex (“primal” or “dual”). Determines whether the graph is generated from primal or dual stabilizers in the code.

  • code (SurfaceCode, optional) – the code from which to initialize the graph.

Note

Both ec and code must be provided to initialize the graph with the proper edges. If one of them is not provided, the graph is left empty.

stabilizers

All the stabilizer nodes of the graph.

Type

List[Stabilizer]

{ec}_low_bound_points

All the points on the code boundary with smaller coordinates. ‘ec’ can be ‘primal’ or ‘dual’.

Type

List[Tuple[Int, Int, Int]]

{ec}_high_bound_points

All the points on the code boundary with larger coordinates. ‘ec’ can be ‘primal’ or ‘dual’.

Type

List[Tuple[Int, Int, Int]]

Note

One has first to assign weights and bit values to the nodes of the lattice. This can be achieved, e.g,. by applying CV noise, conducting homodyne measurements, computing the phase error probabilities, and translating the outcomes.

add_edge(node1, node2[, common_vertex])

Insert a node into the graph and return the updated stabilizer graph.

add_high_bound_point(point)

Add a boundary point with an edge to the 'high' point to the graph.

add_high_bound_points(points)

Add many boundary points with edges to the 'high' point to the graph.

add_low_bound_point(point)

Add a boundary point with an edge to the 'low' point to the graph.

add_low_bound_points(points)

Add many boundary points with edges to the 'low' point to the graph.

add_node(node)

Insert a node into the stabilizer graph.

add_stabilizer(stabilizer)

Add a stabilizer node to the stabilizer graph.

add_stabilizers(stabilizers)

Add many stabilizer nodes to the stabilizer graph.

assign_weights(code)

Assign the weights to the graph based on the weight of the common vertex of each stabilizer pair of the code.

bound_points()

Return an iterable for all boundary points of the graph.

connect_nodes()

Add an edge between each pair of nodes sharing a common vertex.

draw(**kwargs)

Draw the stabilizer graph with matplotlib.

edge_data(node1, node2)

Return a view of the edge data as a dict.

edges()

Return an iterable of node pairs corresponding to the edges of the graph.

has_bound_points()

Check if the graph has any boundary points.

neighbors(node)

Return the neighbours of node.

nodes()

Return an iterable of all nodes in the graph.

odd_parity_stabilizers()

Return an iterable of all stabilizer nodes with an odd parity.

out_edges(node)

Return the edges incident to node.

real_edges()

Returns an iterable of all edges excluding the ones connected to the 'low' or 'high' points.

real_nodes()

Return an iterable of all nodes excluding the 'low' and 'high' points.

shortest_paths_from_high()

Compute the shortest path from the 'high' node to every other node in the graph.

shortest_paths_from_low()

Compute the shortest path from the 'low' node to every other node in the graph.

shortest_paths_without_high_low(source)

Compute the shortest path from source to every other node in the graph, except the 'high' and 'low' connector.

to_nx()

Convert the same graph into a NxStabilizerGraph.

add_edge(node1, node2, common_vertex=None)[source]

Insert a node into the graph and return the updated stabilizer graph.

This should not distinguish between stabilizer and boundary points.

Parameters
  • node1 (Stabilizer or Tuple[Int, Int, Int]) – The first node of the edge.

  • node2 (Stabilizer or Tuple[Int, Int, Int]) – The second node of the edge.

  • common_vertex (optional) – The vertex shared by the two nodes in the corresponding code.

Returns

The updated stabilizer graph.

add_high_bound_point(point)[source]

Add a boundary point with an edge to the ‘high’ point to the graph.

Parameters

point (Tuple[int, int, int]) – The boundary point to add.

Returns

The updated stabilizer graph.

add_high_bound_points(points)[source]

Add many boundary points with edges to the ‘high’ point to the graph.

Parameters

points (iterable of Tuple[int, int, int]) – The boundary points to add.

Returns

The updated stabilizer graph.

add_low_bound_point(point)[source]

Add a boundary point with an edge to the ‘low’ point to the graph.

Parameters

point (Tuple[int, int, int]) – The boundary point to add.

Returns

The updated stabilizer graph.

add_low_bound_points(points)[source]

Add many boundary points with edges to the ‘low’ point to the graph.

Parameters

points (iterable of Tuple[int, int, int]) – The boundary points to add.

Returns

The updated stabilizer graph.

add_node(node)[source]

Insert a node into the stabilizer graph.

This should not distinguish between stabilizer and boundary points.

Returns

The updated stabilizer graph.

add_stabilizer(stabilizer)[source]

Add a stabilizer node to the stabilizer graph.

Parameters

stabilizer (Stabilizer) – The stabilizer to add.

Returns

The updated stabilizer graph.

add_stabilizers(stabilizers)[source]

Add many stabilizer nodes to the stabilizer graph.

Parameters

stabilizers (iterable of Stabilizer) – The stabilizers to add.

Returns

The updated stabilizer graph.

assign_weights(code)[source]

Assign the weights to the graph based on the weight of the common vertex of each stabilizer pair of the code.

bound_points()[source]

Return an iterable for all boundary points of the graph.

connect_nodes()[source]

Add an edge between each pair of nodes sharing a common vertex.

Returns

The updated stabilizer graph.

draw(**kwargs)[source]

Draw the stabilizer graph with matplotlib.

See flamingpy.utils.viz.draw_dec_graph for more details.

edge_data(node1, node2)[source]

Return a view of the edge data as a dict.

Parameters
  • node1 (Stabilizer or Tuple[Int, Int, Int]) – The first node of the edge.

  • node2 (Stabilizer or Tuple[Int, Int, Int]) – The second node of the edge.

Raises

KeyError if there is no edge between the given nodes.

edges()[source]

Return an iterable of node pairs corresponding to the edges of the graph.

has_bound_points()[source]

Check if the graph has any boundary points.

neighbors(node)[source]

Return the neighbours of node.

nodes()[source]

Return an iterable of all nodes in the graph.

odd_parity_stabilizers()[source]

Return an iterable of all stabilizer nodes with an odd parity.

out_edges(node)[source]

Return the edges incident to node.

real_edges()[source]

Returns an iterable of all edges excluding the ones connected to the ‘low’ or ‘high’ points.

real_nodes()[source]

Return an iterable of all nodes excluding the ‘low’ and ‘high’ points.

shortest_paths_from_high()[source]

Compute the shortest path from the ‘high’ node to every other node in the graph.

This assumes that the edge weights are asssigned.

Returns

The first dictionary maps a target node to the weight

of the corresponding path. The second one maps a target node to the list of nodes along the corresponding path.

Return type

(dict, dict)

shortest_paths_from_low()[source]

Compute the shortest path from the ‘low’ node to every other node in the graph.

This assumes that the edge weights are asssigned.

Returns

The first dictionary maps a target node to the weight

of the corresponding path. The second one maps a target node to the list of nodes along the corresponding path.

Return type

(dict, dict)

shortest_paths_without_high_low(source)[source]

Compute the shortest path from source to every other node in the graph, except the ‘high’ and ‘low’ connector.

This assumes that the edge weights are asssigned.

Note: a path can’t use the ‘high’ and ‘low’ node.

Parameters

source – The source node for each path.

Returns

The first dictionary maps a target node to the weight

of the corresponding path. The second one maps a target node to the list of nodes along the corresponding path.

Return type

(dict, dict)

to_nx()[source]

Convert the same graph into a NxStabilizerGraph.

This involves converting the graph representation to a networkx graph representation.

Contents

Home

Background

Using FlamingPy

Development

Getting Help

Python API