mqt.qecc.cococo.snake_builder

Generates Stabilizers for n-snakes.

Classes

SnakeBuilderSC

Constructs a n-snake of distance d with a surface code in snake shape on the square lattice substate (leading to brickwall routing graph aka hex graph).

SnakeBuilderSTDW

Constructs a n-snake of distance d color codes with semi transparent domain wall.

SnakeBuilderSteane

Constructs a snake with n Steane patches on specified vertices in G. Without ancillas in the interface.

Functions

convex_hull(points) → list[tuple[float, float]]

Find the convex hull of a set of 2D points.

Module Contents

class SnakeBuilderSC(g: networkx.Graph, positions_rough: list[list[SnakeBuilderSC.__init__.pos]], positions_smooth: list[list[SnakeBuilderSC.__init__.pos]], d: int)[source]

Constructs a n-snake of distance d with a surface code in snake shape on the square lattice substate (leading to brickwall routing graph aka hex graph).

fill_snake() → list[list[mqt.qecc.cococo.types.pos]][source]

Finds the true interior nodes by marking exterior nodes from all four edges.

Requires that we have a closed region present.

Returns:

Positions of ALL nodes in the snakes.

Return type:

list[list[pos]]

static neighbors_ver_hor(node1: mqt.qecc.cococo.types.pos, node2: mqt.qecc.cococo.types.pos) → bool[source]

Checks whether two nodes are neighbors.

Vertical and horizontal neighbors. Not based on initial graph structure because no diagonal edges present.

Parameters:
  • node1 – node1

  • node2 – node2

Returns:

whether both are neighbors.

static neighbors_diag(node1: mqt.qecc.cococo.types.pos, node2: mqt.qecc.cococo.types.pos) → bool[source]

Checks whether two nodes are neighbors.

Diagonal. Not based on initial graph structure because no diagonal edges present.

Parameters:
  • node1 (pos) – node1

  • node2 (pos) – node2

Returns:

whether both are neighbors.

Return type:

bool

collect_qubit_positions() → list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]][source]

Collects the edges on which qubit are placed defining the merged object (snake+logical patches), depending on the given rough/smooth edges/boundaries.

These positions can be used to construct the stabilizers (gen_stars, gen_plaquettes) given the rough/smooth boundaries. Only qubits on horizontal/vertical edges, no new diagonal edges added.

Returns:

List of edges where qubits are placed.

gen_stars() → list[list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]]][source]

Generates star operators.

Returns:

List of lists of edges, where each list determines a star operator.

gen_plaquettes() → list[list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]]][source]

Generates Plaquette Operators.

The algorithm works as follows: 1. Collects all lattice nodes, including boundary and inner nodes. 2. Extends the node set slightly to ensure all possible plaquettes are considered even at the lattice edges. 3. Scans through nodes, treating each as the potential upper-left corner of a square plaquette. 4. Identifies all edges within each square that correspond to actual qubits in the code. 5. Discards trivial plaquettes (single-qubit) and those that violate boundary constraints 6. Collects the remaining edges into plaquette operators.

Returns:

A List of Plaquette Operators. Each Plaquette Operator is a list of tuple[pos, pos] since qubits are placed on edges.

Return type:

list[list[tuple[pos, pos]]]

create_stabs() → tuple[list[list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]]], list[list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]]]][source]

Summarizes all previously defined methods and returns the plaquette stabilizers and star stabilizers of the merged snake object.

Returns:

Returns two lists of stabilizers. The first are the plaquettes, second are the stars. Each list contains the plaquette/star operators respectively. Each Plaquette Operator is a list of tuple[pos, pos] since qubits are placed on edges.

Return type:

tuple[ list[list[tuple[pos, pos]]], list[list[tuple[pos, pos]]] ]

gen_checks() → tuple[numpy.typing.NDArray[int_], numpy.typing.NDArray[int_], dict[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos], int]][source]

Return checks and translation dict.

Returns:

X check matrix, Z check matrix and the translation dict which translates between posiitons on the graph and positions in the check matrix.

plot_stabs(opz: list[tuple[SnakeBuilderSC.plot_stabs.pos, SnakeBuilderSC.plot_stabs.pos]] | None = None, opx: list[tuple[SnakeBuilderSC.plot_stabs.pos, SnakeBuilderSC.plot_stabs.pos]] | None = None, size: tuple[int, int] = (8, 8)) → None[source]

Plots plaquettes and star operators as well as the snake itself.

opz and opx are the logical operators retrieved via mqt.qecc.CSSCode which are already translated as edges on the graph. This only works if gen_checks was called before.

Parameters:
  • opz (list[tuple[pos, pos]] | None, optional) – Logical Operator Z_L as list of qubit positions. Each qubit position is an edge on the graph. Defaults to None.

  • opx (list[tuple[pos, pos]] | None, optional) – Logical Operator Z_L as list of qubit positions. Each qubit position is an edge on the graph. Defaults to None.

  • size (tuple[int, int], optional) – Size of the plot. Defaults to (8, 8).

get_logical_operator_basis() → numpy.typing.NDArray[numpy.int8][source]

Generates Logical Operators of the snake.

Returns:

logical operators.

class SnakeBuilderSTDW(g: networkx.Graph, positions: list[list[SnakeBuilderSTDW.__init__.pos]], d: int)[source]

Constructs a n-snake of distance d color codes with semi transparent domain wall.

find_triangle_edges_corners(n_triangle: int) → list[list[mqt.qecc.cococo.types.pos]][source]

Searches for the graph labels of the vertices in the 3 edges of the given triangle.

Parameters:

n_triangle (int) – label of triangle in self.positions

Returns:

list of positions in the three boundaries/edges of the triangle.

Return type:

list[list[pos]]

find_interface_ancillas(triangle_0: int, triangle_1: int) → list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]][source]

Finds ancilla vertices on the interface between triangle_0 and triangle_1.

Parameters:
  • triangle_0 – label of first triangle in self.positions[triangle_0]

  • triangle_1 – label of second triangle in self.positions[triangle_1] -> must be adjacent to the first!

Returns:

ancilla vertices on the interface between triangle_0 and triangle_1

hex_plaquettes() → list[list[mqt.qecc.cococo.types.pos]][source]

Find all hexagonal plaquettes on original g.

This can become expensive if lattices are too large since calling simple_cycles can become expensive then.

Returns:

all possible hexagonal plaquettes as vertices on g.

Return type:

list[list[pos]]

find_stabilizers() → tuple[list[list[mqt.qecc.cococo.types.pos]], list[list[mqt.qecc.cococo.types.pos]]][source]

Find stabilizers on self.positions.

Returns:

Two lists, first the Z stabilizrs, and second the X stabilizers. There are more Z than X stabilizers because we assume a Z merge by default. but can be interchanged of course for a X merge.

Return type:

tuple[list[list[pos]], list[list[pos]]]

find_separate_stabilizers(n_triangle: int) → list[list[mqt.qecc.cococo.types.pos]][source]

Generates the stabilizers of a plain triangular color code. Not including the interface.

Parameters:

n_triangle (int) – index of triangular patch of interest.

Returns:

stabilizers of the code (both x and z stabilizers because self-dual)

Return type:

list[list[pos]]

integer_labeling() → None[source]

Finds a random integer labeling. Only works after having run find_stabilizers.

plot_stabilizers(plaquettes: list[list[SnakeBuilderSTDW.plot_stabilizers.pos]], size: tuple[int, int] = (7, 7)) → None[source]

Plots the stabilizers, either z_plaquettes or x_plaquettes.

Parameters:
  • plaquettes (list[list[pos]]) – List of stabilizers to plot.

  • size (tuple[int, int], optional) – size of the plot. Defaults to (7, 7).

gen_check_matrix(plaquettes: list[list[mqt.qecc.cococo.types.pos]]) → numpy.typing.NDArray[int_][source]

Takes plaquettes and translates with self.integer_labeling.

Parameters:

plaquettes (list[list[pos]]) – Stabilizers as list of qubit positions.

Returns:

check matrix.

Return type:

npt.NDArray[np.int_]

find_outer_bdry() → list[list[mqt.qecc.cococo.types.pos]][source]

Finds the set of outer boundaries of the triangles (not connected to stdw) for the inner triangles (start and end triangle not included).

Returns:

list of the outer boundaries. each boundary is a list of qubit positions pos.

Return type:

list[list[pos]]

fill_triangle(triangle_idx: int) → list[list[mqt.qecc.cococo.types.pos]][source]

Selects the subset of z stabilizers within the triangle (possibly also including stdw nodes) s.t. each node is maximally touched twice by a plaquette.

Parameters:

triangle_idx (int) – The label of the triangle following the numbering of the input of this class.

Returns:

subset of stabilizers (each a list[pos]).

Return type:

list[list[pos]]

get_neighboring_pairs(single_nodes_in_plaq: list[mqt.qecc.cococo.types.pos]) → list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]][source]

Find pairs of single nodes which are neighbors on the graph.

static filter_disjoint_pairs(all_neighboring_pairs: list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]]) → list[tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos]][source]

Find disjoint pairs of neighboring nodes on a plaquette.

static find_matching_plaquette(pair: tuple[mqt.qecc.cococo.types.pos, mqt.qecc.cococo.types.pos], filtered_z_plaquettes: list[list[mqt.qecc.cococo.types.pos]], subset_stabs: list[list[mqt.qecc.cococo.types.pos]]) → list[mqt.qecc.cococo.types.pos] | None[source]

Find plaquette which shares pair but is not in subset_stabs.

find_stabilizers_zz() → list[list[mqt.qecc.cococo.types.pos]][source]

Summarizes the methods above and joins the subsets per triangle on the STDW.

test_zz_stabs(subset_z_stabs: list[list[mqt.qecc.cococo.types.pos]]) → bool[source]

Checks whether all nodes are touched by stabilizers even number of times besides the logical operators.

class SnakeBuilderSteane(g: networkx.Graph, positions: list[dict[SnakeBuilderSteane.__init__.pos, int]])[source]

Constructs a snake with n Steane patches on specified vertices in G. Without ancillas in the interface.

static compatible_x_stabs() → list[dict[str, list[int]]][source]

Returns the allowed Weight 8 X Stabilizers crossing Steane patches.

static compatible_z_stabs_weight_two() → list[dict[str, int]][source]

Returns allowed weight-2 z stabilizer connections.

static compatible_z_stabs_weight_four() → list[dict[str, list[int]]][source]

Returns allowed weight-4 z stabilizers connections.

static standard_steane() → list[list[int]][source]

Returns the standard separate steane stabilizer plaquettes.

neighboring_vertex(vertex_0: mqt.qecc.cococo.types.pos, vertex_1: mqt.qecc.cococo.types.pos) → bool[source]

Checks whether two vertices are adjacent.

check_interface(i: int) → dict[mqt.qecc.cococo.types.pos, int][source]

Checks which edge of the ith steane tile is connected to the next (i+1) 0,2,1 edge.

check_paired_neighbor(pos_i_new: dict[mqt.qecc.cococo.types.pos, int], pos_i1_new: dict[mqt.qecc.cococo.types.pos, int]) → bool[source]

Checks whether we can find a weight-8 x plaquette which actually connects neighbored plaqeuttes between i and i+1.

generate_x_stabilizers() → list[dict[mqt.qecc.cococo.types.pos, int]][source]

Subsequently builds the X stabilizers. Focus on the big trillerpfeifen weight-8 stabilizers.

find_matching_dict(x_stabilizers: list[dict[mqt.qecc.cococo.types.pos, int]], target_values: list[int], i: int) → dict[mqt.qecc.cococo.types.pos, int][source]

Finds the set of stabilizers in the ith patch which have the desired target_values.

generate_z_stabilizers() → list[dict[mqt.qecc.cococo.types.pos, int]][source]

Builds Z stabilizers based on X stabilizers.

static find_matching_dict_z(x_stabs: list[dict[mqt.qecc.cococo.types.pos, int]], current_patch: dict[mqt.qecc.cococo.types.pos, int], next_patch: dict[mqt.qecc.cococo.types.pos, int]) → dict[mqt.qecc.cococo.types.pos, int] | None[source]

Finds the x stabilizer which connects current_patch and next_patch.

find_disjoint_dict(current_patch: dict[mqt.qecc.cococo.types.pos, int], next_patch: dict[mqt.qecc.cococo.types.pos, int], dict_list: list[dict[str, list[int]]], pair: list[int]) → dict[str, list[int]] | None[source]

Finds a dictionary in which the total of integers in the values is disjoint to the given pair. AND the weight4 must bepairwise neighbors.

translate_checks() → tuple[list[list[int]], list[list[int]]][source]

Translates the x/z_stabilizers into check matrices.

Returns the check_z and checks_x.

plot_stabilizers(stabilizers: list[dict[SnakeBuilderSteane.plot_stabilizers.pos, int]], size: tuple[int, int] = (7, 7)) → None[source]

Plots the faces of the stabilizers for a given list of stabilizers (either x or z).

convex_hull(points: list[tuple[float, float]]) → list[tuple[float, float]][source]

Find the convex hull of a set of 2D points.