Code elements

class qsurface.codes.elements.Qubit(loc, z=0, *args, **kwargs)

General type qubit object.

# This class mainly serves as a superclass or template to other more useful qubit types, which have the apprioate subclass attributes and subclass methods. For other types to to the ‘See Also’ section.

Parameters
  • loc (Tuple[float, float]) – Location of the qubit in coordinates.

  • z (float) – Layer position of qubit. Different layers correspond to time instances of a surface for faulty measurement simulations.

class qsurface.codes.elements.DataQubit(*args, **kwargs)

Data type qubit object.

The state of a data-qubit is determined by two Edge objects stored in the self.edges dictionary. Each of the edges are part of a separate graph on the surface lattice.

edges

Dictionary of edges with the error type as key (e.g. "x" or "z").

self.edges = {“x”: Edge_x, “z”, Edge_z}

Type

dict of Edge

state

A class property that calls to each of the edges stored at the self.edges attribute and returns all edge states as a dictionary.

Type

dict of bool

reinitialized

Indicator for a reinitialized (replaced) data qubit.

Type

bool

class qsurface.codes.elements.AncillaQubit(*args, state_type='default', **kwargs)

General type qubit object.

An ancilla-qubit is entangled to one or more DataQubit objects. The self.state_type attribute determines the state on which the measurement is applied. A single measurement is applied when the class property self.state is called. The state of the last measurement is stored in self.measured_state for state access without prompting a new measurement.

Parameters

state_type (str, {"x", "z"}) – Type of ‘codes.elements.Edge’ objects belonging to the DataQubit objects entangled to the current ancilla-qubit for stabilizer measurements.

parity_qubits

All qubits in this dictionary are entangled to the current ancilla for stabilizer measurements.

Type

dict of DataQubit

z_neighbors

Neighbor ancilla in the z direction that is an instance of the same qubit at a different time, required for faulty measurements.

Type

{codes.elements.AncillaQubit: PseudoEdge}

state

Property that measures the parity of the qubits in self.parity_qubits.

Type

bool

measured_state

The result of the last parity measurement.

Type

bool

syndrome

Whether the current ancilla is a syndrome.

Type

bool

measurement_error

Whether an error occurred during the last measurement.

Type

bool

Examples

The state of the entangled DataQubit is located at:

>>> AncillaQubit.parity_qubits[key].edges[AncillaQubit.state_type]
True
measure(p_bitflip_plaq=0, p_bitflip_star=0, **kwargs)

Applies a parity measurement on the ancilla.

The functions loops over all the data qubits in self.parity_qubits. For every edge associated with the entangled state on the data qubit, the value of a parity boolean is flipped.

Parameters
  • p_bitflip_plaq (float) – Bitflip rate for plaquette (XXXX) operators.

  • p_bitflip_star (float) – Bitflip rate for star (ZZZZ) operators.

Return type

bool

class qsurface.codes.elements.Edge(qubit, state_type='', initial_state=None, **kwargs)

A state object belonging to a DataQubit object.

An edge cannot have open vertices and must be spanned by two nodes. In this case, the two nodes must be AncillaQubit objects, and are stored in self.nodes.

Parameters
  • qubit (DataQubit) – Parent qubit object.

  • state_type (str) – Error type associated with the current edge.

  • initial_state (Optional[bool]) – State of the object after initialization.

nodes

The vertices that spans the edge.

Type

list of two ~.codes.elements.AncillaQubit` objects

state

The current quantum state on the edge object.

Type

bool

add_node(node, **kwargs)

Adds a node to the edge’s self.nodes attribute.

class qsurface.codes.elements.PseudoQubit(*args, state_type='default', **kwargs)

Boundary element, imitates codes.elements.AncillaQubit.

Edges needs to be spanned by two nodes. For data qubits on the boundary, one of its edges additionally requires an ancilla qubit like node, which is the pseudo-qubit.

measure(p_bitflip_plaq=0, p_bitflip_star=0, **kwargs)

Applies a parity measurement on the ancilla.

The functions loops over all the data qubits in self.parity_qubits. For every edge associated with the entangled state on the data qubit, the value of a parity boolean is flipped.

Parameters
  • p_bitflip_plaq (float) – Bitflip rate for plaquette (XXXX) operators.

  • p_bitflip_star (float) – Bitflip rate for star (ZZZZ) operators.

Return type

bool

class qsurface.codes.elements.PseudoEdge(qubit, state_type='', initial_state=None, **kwargs)

Vertical edge connecting time instances of ancilla-qubits, imitates codes.elements.Edge.

add_node(node, **kwargs)

Adds a node to the edge’s self.nodes attribute.