Codes

Quantum error correcting codes are represented as classes. As stabilizer codes defined on lattices have much in common, the specific classes for each code are inherited from the abstract class panqec.codes.base.StabilizerCode. See Adding a new code to PanQEC for example usage. Note that most of the codes listed here can be visualized in the GUI, for which you can see a demo at gui.quantumcodes.io. Alternatively, you can also run it locally using panqec start-gui and opening localhost:5000 in your browser.

Abstract Classes

class panqec.codes.base.StabilizerCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

Abstract class for generic stabilizer codes (CSS or not)

Any subclass should override the following four methods: - get_qubit_coordinates() to define all the coordinates in the lattice that contain qubits - get_stabilizer_coordinates() to define all the coordinates in the lattice that contain stabilizers - qubit_axis(location) to return the axis of a qubit at a given location (when qubit have an orientation in space, for instance when they are edges)

Using only those methods, a StabilizerCode will then automatically create the corresponding parity-check matrix (in self.stabilizers) and can be used to make a visualization in the GUI or calculate thresholds.

property Hx: csr_matrix

Parity-check matrix corresponding to the X stabilizers of the code. It is a sparse matrix of dimension k x n, where k is the number of X stabilizers and n the number of qubits. Works only for CSS codes.

property Hz: csr_matrix

Parity-check matrix corresponding to the Z stabilizers of the code. It is a sparse matrix of dimension k x n, where k is the number of Z stabilizers and n the number of qubits. Works only for CSS codes.

__init__(L_x: int, L_y: int | None = None, L_z: int | None = None)

Constructor for the StabilizerCode class

Parameters:
  • L_x (int) – Dimension of the lattice in the x direction (or in all directions if L_y and L_z are not given)

  • L_y (int, optional) – Dimension of the lattice in the y direction

  • L_z (int, optional) – Dimension of the lattice in the z direction

property d: int

Distance of the code

abstract property dimension: int

Dimension of the code (usually 2 or 3)

extract_x_syndrome(syndrome: ndarray) ndarray

For CSS codes only. Returns the part of the syndrome that corresponds to X stabilizers.

Parameters:

syndrome (np.ndarray) – Syndrome as a sparse row of dimension 1xm, where m is the number of stabilizers.

Returns:

x_syndrome – Syndrome reduced to X stabilizers

Return type:

np.ndarray

extract_z_syndrome(syndrome: ndarray) ndarray

For CSS codes only. Returns the part of the syndrome that corresponds to Z stabilizers.

Parameters:

syndrome (np.ndarray) – Syndrome as a sparse row of dimension 1xm, where m is the number of stabilizers.

Returns:

z_syndrome – Syndrome reduced to X stabilizers

Return type:

np.ndarray

from_bsf(bsf_operator: ndarray) Dict[Tuple, str]

Convert an operator given as a sparse row in the binary symplectic format to a dictionary qubit_location -> pauli.

Parameters:

bsf_operator (np.ndarray) – Array of dimension (1, 2n) in the binary symplectic format (where n is the number of qubits)

Returns:

operator – Operator given as a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support

Return type:

Dict[Tuple, str]

abstract get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

abstract get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

abstract get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

abstract get_stabilizer(location: Tuple) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

abstract get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property id: str

Returns a string identifying the class (usually the code name)

in_codespace(error: ndarray) bool

Check whether or not a given error is in the codespace, i.e. whether it has a zero syndrome or not.

Parameters:

error (np.ndarray) – Error as an array of size 2n (where n is the number of qubits) in the binary symplectic format

Returns:

Whether or not the error is in the codespace

Return type:

bool

property is_css: bool

Determines if a code is CSS, i.e. if it has separate X and Z stabilizers

is_logical_error(error) bool

Check whether or not a given error is in the codespace, i.e. whether it has a zero syndrome or not.

Parameters:

error (np.ndarray) – Error as an array of size 2n (where n is the number of qubits) in the binary symplectic format

Returns:

Whether or not the error is in the codespace

Return type:

bool

is_qubit(location: Tuple)

Returns whether a given location in the coordinate system corresponds to a qubit or not. It is done by checking that the input location is a key in the dictionary self.qubit_index.

Parameters:

location (Tuple) – Location as a tuple of coordinates

Returns:

Whether the location is a qubit in the coordinate system.

Return type:

Bool

is_stabilizer(location: Tuple, stab_type: str | None = None)

Returns whether a given location in the coordinate system corresponds to a stabilizer or not

property k: int

Number of logical qubits

abstract property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

logical_errors(error: ndarray) ndarray

Return the logical errors, as an array of size 2k (where k is the number of logicals), such that each component is 1 if and only if it anticommutes with the corresponding logical.

By convention, the first k indices correspond to the X logicals and the last k to the the Z logicals

Parameters:

error (np.ndarray) – Error as an array of size 2n (where n is the number of qubits) in the binary symplectic format

Returns:

logical_errors – Array of size 2k (where k is the number of logicals) indicating whether the error commute with each X and Z logical.

Return type:

np.ndarray

property logicals_x: ndarray

Logical X operator, as a k x 2n matrix in the binary symplectic format, where k is the number of logical X operators, and n the number of qubits.

property logicals_z: ndarray

Logical Z operator, as a k x 2n matrix in the binary symplectic format, where k is the number of logical Z operators, and n the number of qubits.

measure_syndrome(error: ndarray) ndarray

Noiseless syndrome corresponding to a given Pauli error.

Parameters:

error (np.ndarray) – Error given as an array of dimension 2n in the binary symplectic format.

Returns:

syndrome – Syndrome, as an array of dimension m (where m is the number of stabilizers)

Return type:

np.ndarray

property n: int

Number of physical qubits

property n_stabilizers: int

Number of stabilizer generators

property params: dict

List of class arguments (as a dictionary), that can be saved and reused to instantiate the same code

abstract qubit_axis(location: Tuple) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

property qubit_coordinates: List[Tuple]

List of all the coordinates that contain a qubit

property qubit_index: Dict[Tuple, int]

Dictionary that assigns an index to a given qubit location

qubit_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input qubit, that can be used by the web visualizer. - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the qubit

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

site(operator: Dict[Tuple, str], pauli: str, location: Tuple) None

Apply a Pauli on operator at site location.

Note that the operator is a (mutable) dict.

Parameters:
  • operator (Operator) – Operator in dictionary representation.

  • pauli (str) – Pauli to apply.

property size: Tuple

Dimensions of the lattice.

property stabilizer_coordinates: List[Tuple]

List of all the coordinates that contain a stabilizer

property stabilizer_index: Dict[Tuple, int]

Dictionary that assigns an index to a given stabilizer location

property stabilizer_matrix: csr_matrix

Parity-check matrix of the code in the binary symplectic format. It is a sparse matrix of dimension k x 2n, where k is the total number of stabilizers and n the number of qubits

stabilizer_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

abstract stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

to_bsf(operator: Dict[Tuple, str]) ndarray

Convert an operator (given as a dictionary qubit_location -> pauli) to an array in the binary symplectic format.

Parameters:

operator (Dict[Tuple, str]) – Operator given as a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support

Returns:

bsf_operator – Array of dimension 2n in the binary symplectic format (where n is the number of qubits)

Return type:

np.ndarray

type_index(stab_type: str) Dict[Tuple, int]

Dictionary of locations and indices for given stabilizer type.

Parameters:

stab_type (str) – Stabilizer type ot index.

Returns:

index – Dictionary of qubit indices for each stabilizer location that matches the given type.

Return type:

Dict[Tuple, int]

property x_indices: ndarray

Indices of the X stabilizers in the parity-check matrix, as a boolean array s.t. x_indices[i] is True if stabilizer H[i] only contain X operators and False otherwise

property z_indices: ndarray

Indices of the Z stabilizers in the parity-check matrix, as a boolean array s.t. z_indices[i] is True if stabilizer H[i] only contain Z operators and False otherwise

2D Surface Codes

class panqec.codes.surface_2d.Planar2DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

2D surface code with open boundary conditions. In this variant of the 2D surface code, there are two types of boundaries: rough and smooth.

As in the Kitaev toric code, the qubits live on edges of the lattice, while stabilizers are defined on faces and vertices. As such, on rough boundaries the edge-most qubits are on edges orthogonal to the boundary forming a ‘rough’ look. On smooth boundaries the edge-most qubits are on edges parallel to the boundary forming a ‘smooth’ look. The boundary conditions and coordinate system used are shown below.

_images/planar_2d_code.svg
Parameters:
  • L_x (int) – The size in the x direction.

  • L_y (Optional[int]) – The size in the y direction. If it is not given, it is assumed to be a square lattice with Lx=Ly.

get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location: Tuple) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_2d.RotatedPlanar2DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

Rotated 2D surface code with open boundaries. These use roughly half the number of qubits but only encode 1 logical qubit.

Parameters:
  • L_x (int) – Number of qubits in the x direction.

  • L_y (Optional[int]) – Number of qubits in the y direction. Assumed square if not given.

Notes

One stabilizer of each type is shown in the figure below. In this picture, the qubits live on the edges and there are two types of stabilizers: vertex Z stabilizers and face X stabilizers. Note the weight-2 stabilizers on the boundaries. The below lattice is of size 5 by 4.

_images/rotated_planar_2d_code.svg

Alternatively, we can consider the the same coordinates, qubits and stabilizers but seen on a rotated lattice, where the lattice live on vertices, and the two types of stabilizers correspond to the color of the checkerboard faces as shown below.

_images/rotated_planar_2d_code_2.svg
get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_type(location: Tuple)

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_2d.Toric2DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

The original 2D toric code introduced by Kitaev. The qubits live on the edges of a 2D periodic square lattice. There are two types of stabilizer generators: vertex operators on vertices, and face operators faces.

The coordinate system used is shown below.

_images/toric_2d_code.svg
Parameters:
  • L_x (int) – The size in the x direction.

  • L_y (Optional[int]) – The size in the y direction. If it is not given, it is assumed to be a square lattice with Lx=Ly.

get_logicals_x() List[Dict[Tuple, str]]

The 2 logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

The 2 logical Z operators.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

3D Surface Codes

class panqec.codes.surface_3d.HollowPlanar3DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)
get_logicals_x() List[Dict[Tuple, str]]

The unique logical X operator.

get_logicals_z() List[Dict[Tuple, str]]

The unique logical Z operator.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.HollowRhombicCode(L_x: int, L_y: int | None = None, L_z: int | None = None)
get_logicals_x() List[Dict[Tuple, str]]

The 3 logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

The 3 logical Z operators.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.Planar3DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

3D surface code on cubic lattice with open boundary conditions.

Parameters:
  • L_x (int) – Number of edges along the x direction (on edges parallel to x).

  • L_y (Optional[int]) – Number of qubits in the y direction (on edges parallel to x).

  • L_z (Optional[int]) – Number of qubits in the z direction (on edges parallel to x).

Notes

Qubits live on edges. Boundaries parallel to the xy plane (i.e. orthogonal to z) are smooth. Boundaries parallel to the zx plane (i.e. orthogonal to y) are rough. Boundaries parallel to the yz plane (i.e. orthogonal to x) are smooth. Similar to panqec.codes.surface_2d.Planar2DCode but extruded in z direction with smooth open boundaries and vertical z edges (with qubits) in between each layers’ vertices. Stabilizers are otherwise the same as that of panqec.codes.surface_3d.Toric3DCode but truncated at the boundaries.

get_logicals_x() List[Dict[Tuple, str]]

The unique logical X operator.

get_logicals_z() List[Dict[Tuple, str]]

The unique logical Z operator.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.RhombicPlanarCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

Toric code on checkerboard lattice with open boundaries.

Similar to panqec.codes.surface_3d.RhombicToricCode but with smooth boundaries on planes orthogonal to the x and z directions and rough boundaries on planes orthogonal to the y direction.

Parameters:
  • L_x (int) – Size of lattice along x direction, which is actually the number of x-edges in the x direction.

  • L_y (Optional[int]) – Size of lattice along y direction, which is actually the number of x-edges in the y direction.

  • L_z (Optional[int]) – Size of lattice along z direction, which is actually the number of x-edges in the z direction.

Notes

Note that it is the same qubit lattice as that of panqec.codes.surface_3d.Planar3DCode but with very different stabilizer generators.

get_logicals_x() List[Dict[Tuple, str]]

The 3 logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

The 3 logical Z operators.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.RhombicToricCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

Toric code on periodic checkerboard lattice.

Parameters:
  • L_x (int) – Size of lattice along x direction. Must be even.

  • L_y (Optional[int]) – Size of lattice along y direction. Must be even.

  • L_z (Optional[int]) – Size of lattice along z direction. Must be even.

Notes

A checkerboard lattice is a cubic lattice for which there are two types of cells: colored and uncolored. For each colored cell, there is a 12-body stabilizer generator with support over the neighbour edges. For each uncolored cell, there is a stabilizer generator for each corner, each of which is a 3-body term with support over the 3 edges adjacent to both that corner vertex and the cell.

get_logicals_x() List[Dict[Tuple, str]]

The 3 logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

The 3 logical Z operators.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.RotatedPlanar3DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

3D surface code with open boundaries on lattice rotated about z axis.

Uses roughly half as many qubits as panqec.codes.surface_3d.Planar3DCode.

Parameters:
  • L_x (int) – Number of qubits in the x direction.

  • L_y (Optional[int) – Number of qubits in the y direction.

  • L_z (Optional[int]) – Number of qubits in the z direction.

Notes

The lattice is stacked with lattices like those in panqec.codes.surface_2d.RotatedPlanar2DCode glued with vertical qubits in between each layer.

get_logicals_x() List[Dict[Tuple, str]]

Get the unique logical X operator.

get_logicals_z() List[Dict[Tuple, str]]

Get the unique logical Z operator.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

qubit_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input qubit, that can be used by the web visualizer. - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the qubit

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.RotatedToric3DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

Rotated Toric Code for good subthreshold scaling with certain Lx, Ly.

Parameters:
  • L_x (int) – Number of qubits in the x direction.

  • L_y (int) – Number of qubits in the y direction.

  • L_z (int) – Number of qubits in the z direction.

Notes

Similar to panqec.codes.surface_2d.RotatedPlanar2DCode but with periodic boundaries in x and y direction on each layer, conected with vertical (z) edge qubits in between each layer except for the top and bottom where the are smooth boundaries on the boundary planes orthogonal to z.

Subthreshold scaling is better in this code with certain values of Lx and Ly in the x and y directions if there are only Z errors because the smallest logical error made of Zs only is of very high weight. See the the paper for more details of the exact conditions for Lx and Ly.

get_logicals_x() List[Dict[Tuple, str]]

Get the logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

Get the logical Z operators.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location: Tuple) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

qubit_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input qubit, that can be used by the web visualizer. - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the qubit

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.surface_3d.Toric3DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

3D surface code on periodic cubic lattice with qubits on edges.

Parameters:
  • L_x (int) – Size in the x direction.

  • L_y (Optional[int]) – Size in the y direction, assumed same as Lx if not given.

  • L_z (Optional[int]) – Size in the z direction, assumed same as Lx if not given.

Notes

The qubits live on the edges of the 3D lattice. There are two types of stabilizer generators: 6-body vertex operators living on vertices, and 4-body face operators living on faces.

In the coordinate system used in this implementation, the origin (0, 0, 0) is a vertex, and each unit cell is a cube of linear size 2.

get_logicals_x() List[Dict[Tuple, str]]

The 3 logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

Get the 3 logical Z operators.

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

2D Color Codes

class panqec.codes.color_2d.Color488Code(L_x: int, L_y: int | None = None, L_z: int | None = None)

2D color code on periodic 4,8,8 lattice.

Parameters:
  • L_x (int) – Number of unit cells in x direction.

  • L_y (Optional[int]) – Number of unit cells in y direction.

Notes

The 4,8,8 lattice is a tessallation of red squares (4), green octagons (8) and blue octagons (8). Qubits live on the vertices. For each colored shape, there are two stabilizer generators, one of all X over the qubits on its corners, and one of all Z over the qubits on its corners.

See EC zoo article for further reading.

get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location: Tuple) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.color_2d.Color666PlanarCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

2D color code on 6,6,6 lattice with open boundaries.

The overall shape of the lattice is roughly a triangle.

Parameters:
  • L_x (int) – Number of unit cells in x direction.

  • L_y (Optional[int]) – Number of unit cells in y direction.

Notes

The 6,6,6 lattice is a tessallation of red hexagons (6), green hexagons (6) and blue hexagons (6). Qubits live on the vertices. For each colored shape, there are two stabilizer generators, one of all X over the qubits on its corners, and one of all Z over the qubits on its corners.

See EC zoo article for further reading.

get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location: Tuple) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

class panqec.codes.color_2d.Color666ToricCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

2D color code on periodic 6,6,6 lattice.

The overall shape of the lattice is roughly a rhombus.

Parameters:
  • L_x (int) – Number of unit cells in x direction.

  • L_y (Optional[int]) – Number of unit cells in y direction.

Notes

The 6,6,6 lattice is a tessallation of red hexagons (6), green hexagons (6) and blue hexagons (6). Qubits live on the vertices. For each colored shape, there are two stabilizer generators, one of all X over the qubits on its corners, and one of all Z over the qubits on its corners.

See EC zoo article for further reading.

get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location: Tuple) str

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

3D Color Codes

class panqec.codes.color_3d.Color3DCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

3D Color Code on periodic truncated octahedral lattice.

Parameters:
  • L_x (int) – Size in the x direction.

  • L_y (int) – Size in the y direction.

  • L_z (int) – Size in the z direction.

Notes

See Bombin and Martin-Delgado 2007 for more information.

get_logicals_x() List[Dict[Tuple, str]]

Get the 3 logical X operators.

get_logicals_z() List[Dict[Tuple, str]]

The 3 logical Z operators (errors on all squares of a given layer)

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location: Tuple, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes

Fracton Codes

class panqec.codes.fractons.XCubeCode(L_x: int, L_y: int | None = None, L_z: int | None = None)

X-Cube model of Vijay, Haah and Fu 2016 on periodic 3D cubic lattice.

Parameters:
  • L_x (int) – Size of lattice in x direction

  • L_y (int) – Size of lattice in y direction

  • L_z (int) – Size of lattice in z direction

Notes

The qubits live on edges of the cubic lattice with periodic boundaries. There are two types of stabilizer generators: cubes at each cell and Xs (cruciforms) at each vertex. A cube stabilizer generator has support over the 12 edges on the cube. Each vertex has 3 cruciform stabilizer generators (one for each direction).

(note in this implementation the cruciform generators are called faces in the XCubeCode.stabilizer_type() method)

See Vijay, Haah and Fu 2016 for the original introduction.

get_logicals_x() List[Dict[Tuple, str]]

Returns the list of logical X operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_logicals_z() List[Dict[Tuple, str]]

Returns the list of logical Z operators, where each operator is a dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in its support.

Returns:

logicals – List of dictionaries, where each dictionary assign a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the logical operator.

Return type:

List[Dict[Tuple, str]]

get_qubit_coordinates() List[Tuple]

Give the list of all the qubit coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.qubit_coordinates and self.qubit_index.

Returns:

qubit_coordinates – List of coordinates

Return type:

List[Tuple]

get_stabilizer(location) Dict[Tuple, str]

Returns a stabilizer, formatted as dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer.

For example, for a vertex stabilizer in the 2D toric code, we could have get_stabilizer((1,1)) -> {(1,0): ‘X’, (0, 1): ‘X’, (2, 1): ‘X’, (1, 2): ‘X’}

Parameters:

location (Tuple) – Location of the stabilizer in the coordinate system

Returns:

stabilizer – Dictionary that assigns a Pauli operator (‘X’, ‘Y’ or ‘Z’) to each qubit location in the support of the stabilizer

Return type:

Dict[Tuple, str]

get_stabilizer_coordinates() List[Tuple]

Create list of stabilizer coordinates, in a coordinate system that should contain both the qubits and the stabilizers. This function is used to set the attributes self.stabilizer_coordinates and self.stabilizer_index.

property label: str

Label uniquely identifying a code, including its lattice dimensions Example: ‘Toric 3D {Lx}x{Ly}x{Lz}’

qubit_axis(location)

Return the orientation of a qubit sitting at given location (as a string representing the axis ‘x’, ‘y’ or ‘z’). Useful when qubits have an orientation in space, for instance when they are edges, to help establish the visual representation of the code in the GUI, to simplify the construction of stabilizers, and to create Clifford deformations.

Parameters:

location (Tuple) – Location of the qubit in the coordinate system.

Returns:

axis – Either ‘x’, ‘y’ or ‘z’, depending on the orientation axis of the qubit.

Return type:

str

stabilizer_representation(location, rotated_picture=False, json_file=None) Dict

Returns a dictionary of visualization parameters for the input stabilizer, that can be used by the web visualizer.

It should contain 4 keys: - ‘type’: the type of stabilizer, e.g. ‘vertex’ - ‘location’: [x, y, z], - ‘object’: the type of object to use for visualization, e.g. ‘sphere’ - ‘params’: a dictionary of parameters for the chosen object

Parameters:
  • location (Tuple) – Coordinates of the stabilizer

  • rotated_picture (bool) – For codes that have a rotated picture, can be used to differentiate the two types visualizations

  • json_file (str) – File with the initial configuration for the code

Returns:

representation – Dictionary to send to the GUI

Return type:

Dict

stabilizer_type(location: Tuple) str

Returns the type of a stabilizer sitting at a given location. E.g. ‘vertex’ or ‘face’ in toric codes