Template error

class qsurface.errors._template.Sim(code=None, **kwargs)

Template simulation class for errors.

The template simulation error class can be used as a parent class for error modules for surface code classes that inherit from codes._template.sim.PerfectMeasurements or codes._template.sim.FaultyMeasurements. The error of the module must be applied to each qubit separately using the abstract method random_error.

Parameters

code (codes._template.sim.PerfectMeasurements) – Simulation surface code class.

default_error_rates

The error rates that are applied at default.

Type

dict of float

abstract random_error(qubit, **kwargs)

Applies the current error type to the qubit.

Parameters

qubit (DataQubit) – Qubit on which the error is (conditionally) applied.

Return type

None

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

Template plot class for errors.

The template plotting error class can be used as a parent class for error modules for surface code classes that inherit from codes._template.plot.PerfectMeasurements or codes._template.plot.FaultyMeasurements, which have a figure object attribute at code.figure. The error of the module must be applied to each qubit separately using the abstract method random_error.

To change properties of the qubit (a matplotlib.patches.Circle object) if an error has been appied to visualize the error. The template plot error class features an easy way to define the plot properties of an error. First of all, each error must be defined in an error method that applies the error to the qubit. The template can contain multiple error methods, all of which must be called by random_error. For all errors that we wish to plot, we must add the names of the methods to self.error_methods. The plot properties are stored under the same name in self.plot_params.

class CustomPlotError(Plot):

    error_methods = ["example_method"]
    plot_params = {
        "example_method": {"edgecolor": "color_edge", "facecolor": (0,0,0,0)}
    }

    def random_error(self, qubit):
        if random.random < 0.5:
            self.error_method(qubit)

    def example_method(self, qubit):
        # apply error
        pass

Note that the properties can either be literal or refer to some attribute of the PlotParams object stored at self.code.figure.params (see load_params). Thus the name for the error methods must be unique to any attribute in PlotParams.

Similarly, additional legend items can be added to the surface code plot self.code.figure. Each legend item is a matplotlib.lines.line2D. The properties for each additional item in the legend is stored at self.legend_params, and must also be unique to any PlotParams attribute. The legend titles for each item is stored in self.legend_titles at the same keys. The additional legend items are added in init_legend.

class CustomPlotError(Plot):

    error_methods = ["example_method"]
    plot_params = {
        "example_method": {"edgecolor": "color_edge", "facecolor": (0,0,0,0)}
    }
    legend_params = {
        "example_item": {
            "marker": "o",
            "color": "color_edge",
            "mfc": (1, 0, 0),
            "mec": "g",
        },
    }
    legend_titles = {
        "example_item": "Example error"
    }

    def random_error(self, qubit):
        if random.random < 0.5:
            self.error_method(qubit)

    def example_method(self, qubit):
        # apply error
        pass

Finally, error methods can be also be added to the GUI of the surface code plot. For this, each error method must a static method that is not dependant on the error class. Each error method to be added in the GUI must be included in self.gui_methods. The GUI elements are included in init_plot.

class CustomPlotError(Plot):

    error_methods = ["example_method"]
    gui_methods = ["example_method"]
    plot_params = {
        "example_method": {"edgecolor": "color_edge", "facecolor": (0,0,0,0)}
    }
    legend_params = {
        "example_item": {
            "marker": "o",
            "color": "color_edge",
            "mfc": (1, 0, 0),
            "mec": "g",
        },
    }
    legend_titles = {
        "example_item": "Example error"
    }

    def random_error(self, qubit):
        if random.random < 0.5:
            self.error_method(qubit)

    @staticmethod
    def example_method(qubit):
        # apply error
        pass
Parameters

code (PerfectMeasurements) – Plotting surface code class.

error_methods

List of names of the error methods that changes the qubit surface code plot according to properties defined in self.plot_params.

Type

list

plot_params

Qubit plot properties to apply for each of the error methods in self.error_methods. Properties are loaded to the PlotParams object stored at the self.code.figure.params attribute of the surface code plot (see load_params).

Type

{method_name: properties}

legend_params {method_name

Legend items to add to the surface code plot. Properties are loaded to the PlotParams object stored at the self.code.figure.params attribute of the surface code plot (see load_params), and used to initialize a Line2D legend item.

Type

Line2D properties}

legend_titles

Titles to display for the legend items in self.legend_params.

Type

{method_name: legend_title}

gui_permanent

If enabled, the application of an error method on a qubit cannot be reversed within the same simulation instance.

Type

bool

gui_methods

List of names of the static error methods include in the surface plot GUI.

Type

list

plot_error(error_name)

Decorates the error method with plotting features.

The method error_name is decorated with plot property changes defined in self.plot_params. For each of the properties to change, the original property value of the artist is stored and requested as a change at the end of the simulation instance.

See also

None(), None()