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
orcodes._template.sim.FaultyMeasurements
. The error of the module must be applied to each qubit separately using the abstract methodrandom_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
-
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
orcodes._template.plot.FaultyMeasurements
, which have a figure object attribute atcode.figure
. The error of the module must be applied to each qubit separately using the abstract methodrandom_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 byrandom_error
. For all errors that we wish to plot, we must add the names of the methods toself.error_methods
. The plot properties are stored under the same name inself.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 atself.code.figure.params
(seeload_params
). Thus the name for the error methods must be unique to any attribute inPlotParams
.Similarly, additional legend items can be added to the surface code plot
self.code.figure
. Each legend item is amatplotlib.lines.line2D
. The properties for each additional item in the legend is stored atself.legend_params
, and must also be unique to anyPlotParams
attribute. The legend titles for each item is stored inself.legend_titles
at the same keys. The additional legend items are added ininit_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 ininit_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
-
plot_params
¶ Qubit plot properties to apply for each of the error methods in
self.error_methods
. Properties are loaded to thePlotParams
object stored at theself.code.figure.params
attribute of the surface code plot (seeload_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 theself.code.figure.params
attribute of the surface code plot (seeload_params
), and used to initialize aLine2D
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
-
plot_error
(error_name)¶ Decorates the error method with plotting features.
The method
error_name
is decorated with plot property changes defined inself.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()