Template decoder

qsurface.decoders._template.write_config(config_dict, path)

Writes a configuration file to the path.

Parameters
  • config_dict (dict) – Dictionary of configuration parameters. Can be nested.

  • path (str) – Path to the file. Must include the desired extension.

qsurface.decoders._template.read_config(path, config_dict=None)

Reads an INI formatted configuration file and parses it to a nested dict

Each category in the INI file will be parsed as a separate nested dictionary. A default config_dict can be provided with default values for the parameters. Parameters under the “main” section will be parsed in the main dictionary. All data types will be converted by ast.literal_eval().

Parameters
  • path (str) – Path to the file. Must include the desired extension.

  • config_dict (dict, optional) – Nested dictionary of default parameters

Returns

Parsed dictionary.

Return type

dict

Examples

Let us look at the following example INI file.

[main]
param1 = hello

[section]
param2 = world
param3 = 0.1

This file will be parsed as follows

>>> read_config("config.ini")
{
    "param1": "hello",
    "section": {
        "param2": "world",
        "param3": 0.1
    }
}
qsurface.decoders._template.init_config(ini_file, write=False, **kwargs)

Reads the default and the user defined INI file.

First, the INI file stored in file directory is read and parsed. If there exists another INI file in the working directory, the attributes defined there are read, parsed and overwrites and default values.

Parameters

write (bool) – Writes the default configuration to the working direction of the user.

class qsurface.decoders._template.Sim(code, check_compatibility=False, **kwargs)

Decoder simulation class template.

Parameters
compatibility_measurements

Compatibility with perfect or faulty measurements.

Type

dict

compatibility_errors

Compatibility with the various error modules in Error types.

Type

dict

check_compatibility()

Checks compatibility of the decoder with the code class and loaded errors.

static get_neighbor(ancilla_qubit, key)

Returns the neighboring ancilla-qubit of ancilla_qubit in the direction of key.

Return type

Tuple[AncillaQubit, Edge]

get_neighbors(ancilla_qubit, loop=False, **kwargs)

Returns all neighboring ancillas, including other time instances.

Parameters

loop (bool) – Include neighbors in time that are not chronologically next to each other during decoding within the same instance.

correct_edge(ancilla_qubit, key, **kwargs)

Applies a correction.

The correction is applied to the data-qubit located at ancilla_qubit.parity_qubits[key]. More specifically, the correction is applied to the Edge object corresponding to the state_type of ancilla_qubit.

Return type

AncillaQubit

get_syndrome(find_pseudo=False)

Finds the syndrome of the code.

Parameters

find_pseudo (bool, optional) – If enabled, the lists of syndromes returned are not only AncillaQubit objects, but tuples of (ancilla, pseudo), where pseudo is the closest PseudoQubit in the boundary of the code.

Return type

Union[Tuple[List[AncillaQubit], List[AncillaQubit]], Tuple[List[Tuple[AncillaQubit, PseudoQubit]], List[Tuple[AncillaQubit, PseudoQubit]]]]

Returns

  • list – Plaquette operator syndromes.

  • list – Star operator syndromes.

abstract decode(*args, **kwargs)

Decodes the surface loaded at self.code after all ancilla-qubits have been measured.

class qsurface.decoders._template.Plot(*args, **kwargs)

Decoder plotting class template.

The plotting decoder class requires a surface code object that inherits from codes._template.plot.PerfectMeasurements. The template decoder provides the plot_matching_edge method that is called by correct_edge to visualize the matched edges on the lattice.

Parameters
  • args – Positional and keyword arguments are passed on to Sim.

  • kwargs – Positional and keyword arguments are passed on to Sim.

line_color_match

Plot properties for matched edges.

Type

dict

line_color_normal

Plot properties for normal edges.

Type

dict

matching_lines

Dictionary of edges that have been added to the matching.

Type

defaultdict(bool)

decode(*args, **kwargs)

Decodes the surface loaded at self.code after all ancilla-qubits have been measured.

correct_edge(qubit, key, **kwargs)

Applies a correction.

The correction is applied to the data-qubit located at ancilla_qubit.parity_qubits[key]. More specifically, the correction is applied to the Edge object corresponding to the state_type of ancilla_qubit.

plot_matching_edge(line=None)

Plots the matching edge.

Based on the colors defined in self.line_color_match, if a Line2D object is supplied, the color of the edge is changed. A future change back to its original color is immediately saved in figure.future_dict.

check_compatibility()

Checks compatibility of the decoder with the code class and loaded errors.

static get_neighbor(ancilla_qubit, key)

Returns the neighboring ancilla-qubit of ancilla_qubit in the direction of key.

Return type

Tuple[AncillaQubit, Edge]

get_neighbors(ancilla_qubit, loop=False, **kwargs)

Returns all neighboring ancillas, including other time instances.

Parameters

loop (bool) – Include neighbors in time that are not chronologically next to each other during decoding within the same instance.

get_syndrome(find_pseudo=False)

Finds the syndrome of the code.

Parameters

find_pseudo (bool, optional) – If enabled, the lists of syndromes returned are not only AncillaQubit objects, but tuples of (ancilla, pseudo), where pseudo is the closest PseudoQubit in the boundary of the code.

Return type

Union[Tuple[List[AncillaQubit], List[AncillaQubit]], Tuple[List[Tuple[AncillaQubit, PseudoQubit]], List[Tuple[AncillaQubit, PseudoQubit]]]]

Returns

  • list – Plaquette operator syndromes.

  • list – Star operator syndromes.