flamingpy.codes.SurfaceCode

class flamingpy.codes.SurfaceCode(distance: Union[int, Tuple[int, int, int]], ec='primal', boundaries='open', polarity=None, backend='rustworkx')[source]

Bases: object

A class for representing the surface code.

Represent the surface code in its measurement-based description. By specifying the distance, error complex, choice of boundaries, and polarity, store the graph state corresponding to the code, the set of stabilizer elements and the stabilizer graph, as well as the syndrome and boundary vertices.

distance

the code distance of the lattice. If int, generates a cube corresponding to a code of distance dims. If a sequence (dx, dy, dz), assumes distances dx, dy, dz in x, y, z directions, respectively.

Type

int or Sequence[int]

dims

a tuple of the spatial extent in x, y, z.

Type

tup

ec

the error complex (‘primal’ or ‘dual’).

Type

str

boundaries

the boundary conditions. The options are:

  • ‘open’: [‘primal’, ‘dual’, ‘dual’] for ‘primal’ EC, [‘primal’, ‘dual’, ‘primal’] for ‘dual’ EC.

  • ‘periodic’: ‘periodic’ in all three directions.

  • ‘toric’: [‘periodic’, ‘periodic’, ‘dual’] for ‘primal’ EC, [‘periodic’, ‘periodic’, ‘primal’] for ‘dual’ EC.

For the “open” and “toric” boundary choice, we imagine qubits are encoded into the x-y plane and propagated in time. The z-axis is interpreted as the temporal axis, which is relevant in quantum memory simulations.

Note that in the z-axis is considered as the temporal dimension in quantum memory simulations.

Type

str

polarity

a function that specifies edge weights. It must be of the following form:

polarity(edge) = weight.

If not supplied, assumes all edges have weight 1.

Type

func

backend

The backend to use for the stabilizer graph. Can be “rustworkx” (the default) or “networkx”. The rustworkx backend should be used when speed is a concern. The networkx backend is provided for historical reasons.

Type

string

graph

the EGraph corresponding to the code, representing the graph state.

Type

EGraph

'{b}'_stab_graph

the stabilizer graph combining stabilizers from error complex b (‘primal’ or ‘dual’). The particular implementation depends on backend.

Type

StabilizerGraph

'{b}'_stabilizers

the stabilizer elements of the code according to the error complex b (‘primal’/’dual’).

Type

List[Stabilizer]

'{b}'_syndrome_coords

the coordinates of the syndrome vertices according to the error complex b (‘primal’/’dual’/’all’).

Type

List[Tuple]

'{b}'_syndrome_inds

the integer indices of the syndrome vertices according to the error comple b (‘primal’/’dual’/’all’).

Type

List[Int]

'{b}'_boundary_coords

the coordinates of the boundary according to the error complex b (‘primal’/’dual’).

Type

list of tup

draw([backend])

Draw the cluster state with matplotlib.

draw_stabilizer_graph(ec, **kwargs)

Draw the stabilizer graph with matplotlib.

generate_stabilizer_coords()

Generate primal and dual stabilizer coordinates.

identify_boundary()

Obtain coordinates of syndrome qubits on the boundary.

identify_stabilizers()

Set the stabilizer and syndrome coordinates of self.

periodic_boundary_stabilizers(ec, stabe, ...)

Dealing with stabilizers at periodic boundaries.

set_ec_stabilizers_and_syndrome(all_six_bodies)

Set syndrome and stabilizers attributes of self.

six_body_dual_stabilizers()

Returns all potential six-body dual stabilizers of self.

draw(backend='matplotlib', **kwargs)[source]

Draw the cluster state with matplotlib.

See flamingpy.utils.viz.draw_EGraph for more details. Use the default colour options: black for primal nodes, grey for dual nodes; blue for weight +1 edges, red for weight -1 edges.

draw_stabilizer_graph(ec, **kwargs)[source]

Draw the stabilizer graph with matplotlib.

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

generate_stabilizer_coords()[source]

Generate primal and dual stabilizer coordinates.

Returns

dict: “primal” and “dual” stabilizers

identify_boundary()[source]

Obtain coordinates of syndrome qubits on the boundary.

The relevant boundaries are determined by the ec string. In the end, the attributes {b}_bound_points are set, where b can be ‘primal’ or ‘dual’.

identify_stabilizers()[source]

Set the stabilizer and syndrome coordinates of self.

Generate a list of Stabilizer objects containing coordinates of all the stabilizer elements according to error complex ec. Furthermore, generate a list of all the relevant syndrome coordinates.

In the end, the {ec}_syndrome_coords, {ec}_syndrome_inds, and {ec}_stabilizers attributes (where ec can be ‘primal’ or ‘dual’) as well as all_syndrome_inds and all_syndrome_coords are set.

periodic_boundary_stabilizers(ec, stabe, actual_stabe)[source]

Dealing with stabilizers at periodic boundaries.

Note this method is directly modifying the reference of actual_stabe.

set_ec_stabilizers_and_syndrome(all_six_bodies)[source]

Set syndrome and stabilizers attributes of self.

Set the {ec}_syndrome_coords, {ec}_syndrome_inds, and {ec}_stabilizers attributes.

This method generates a list of Stabilizer objects containing coordinates of all the stabilizer elements according to error complex ec and sets them in self.

six_body_dual_stabilizers()[source]

Returns all potential six-body dual stabilizers of self.

Contents

Home

Background

Using FlamingPy

Development

Getting Help

Python API