loom.visualizer.stabilizer_visualizer
Copyright (c) Entropica Labs Pte Ltd 2025.
Use, distribution and reproduction of this program in its source or compiled form is prohibited without the express written consent of Entropica Labs Pte Ltd.
- class loom.visualizer.stabilizer_visualizer.StabilizerPlot(*args, **kwargs)[source]
Bases:
objectClass for plotting stabilizers, pauli strings, and individual qubits of a Eka.
- Parameters:
lattice (Lattice) – Lattice for which the plot should be created.
stabilizers (list[Stabilizer] | None) – List of stabilizers which should be plotted
width (int | None) – Width of the plotly figure. Default is 800.
height (int | None) – Height of the plotly figure. Default is 600.
rescale_coords (bool | None) – In case the image is drawn with a canvas for stabilizers containing different pauli operators, this parameter has to be set to True. Default is False. When True, the mixed-type stabilizers are drawn pixel by pixel for a canvas of the given width and height. The coordinates of the data qubits are rescaled to fit the image.
padding_relative (float | None) – In case the image is drawn with a canvas for stabilizers containing different pauli operators, this parameter specifies the padding around the drawings, relative to the width of the image.
xmin (float | None) – Minimum x-coordinate of the data qubit locations. Only needed if rescale_coords is True. Since objects might be added to the figure later, the x and y ranges have to be defined already at the beginning.
xmax (float | None) – Maximum x-coordinate of the data qubit locations. Only needed if rescale_coords is True. Since objects might be added to the figure later, the x and y ranges have to be defined already at the beginning.
ymin (float | None) – Minimum y-coordinate of the data qubit locations. Only needed if rescale_coords is True. Since objects might be added to the figure later, the x and y ranges have to be defined already at the beginning.
ymax (float | None) – Maximum y-coordinate of the data qubit locations. Only needed if rescale_coords is True. Since objects might be added to the figure later, the x and y ranges have to be defined already at the beginning.
title (str | None) – Title of the figure.
opacity_stabs (float | None) – Opacity for the stabilizer colors. Range: 0 to 1 with 0 being completely transparent and 1 being completely opaque.
show_grid (bool | None) – If set to False (default), the x and y axes are not shown, the zero line is hidden, and the grid is not displayed.
fill_colors (dict[str, str] | None) – Dict for the fill colors of X, Y, and Z stabilizers.
line_colors (dict[str, str] | None) – Dict for the line colors of X, Y, and Z stabilizers.
dqb_plot_indices (bool | None) – If set to True (default), the data qubit indices are plotted inside the markers.
dqb_marker_size (int | list[int] | None) – Marker size for the data qubits. Either a single integer is provided which is used for all data qubits, or a list of integers is provided which specifies the marker size for each data qubit individually.
dqb_marker_color (str | list[str] | None) – Color for the data qubit markers. Either a single color is provided which is used for all data qubits, or a list of colors is provided which specifies the marker color for each data qubit individually.
- add_dqubit_traces(dqb_show=None, **kwargs)[source]
Add data qubit markers to the figure.
- Parameters:
dqb_show (list[bool] | None) – List of booleans, indicating whether the i-th data qubit should be shown or not. If None, all data qubits are shown.
- Return type:
None
- add_stabilizers(stabilizers, **kwargs)[source]
Adds stabilizers to the plot.
- Parameters:
stabilizers (list[Stabilizer]) – Stabilizers which should be plotted.
- Return type:
None
-
dqb_marker_color:
str|list[str] |None= '#ec6f6d'
-
dqb_marker_size:
int|list[int] |None= 25
-
dqb_plot_indices:
bool|None= True
-
fill_colors:
dict[str,str] |None= FieldInfo(annotation=Union[dict[str, str], NoneType], required=False, default_factory=<lambda>)
- get_dqubit_traces(dqb_show=None, labels=None, marker_mode=None, marker_style=None, legendgroup=None, marker_opacity=1)[source]
Generate the plotly traces for the data qubit markers.
- Parameters:
dqb_show (list[bool] | None) – List of booleans, indicating whether the i-th data qubit should be shown or not. If None, all data qubits are shown.
labels (list[str] | None) – Labels which should be displayed inside the data qubit markers or on hover.
marker_mode (str | None) – Mode in which the markers are displayed, e.g. markers or markers+text
marker_style (dict | None) – Define the style of the markers such as size, color, shape, etc.
legendgroup (str | None) – Legend group to which the data qubit markers belong.
marker_opacity (float | None) – Opacity of the data qubit markers.
- Returns:
List of scatter plot traces for the data qubit markers.
- Return type:
list[go.Scatter]
- get_pauli_string_traces(operation, dqb_marker_size=25, connecting_line=True, log_op_fill_colors=None, log_op_line_colors=None, legend_name='', legendgroup='data_qubits_log_op', shift=(0, 0))[source]
Generate the plotly traces for visualizing a Pauli string.
- Parameters:
operation (PauliOperator) – Pauli string which should be plotted
dqb_marker_size (int | None) – Marker size for the data qubits contained in the Pauli string
connecting_line (bool | None) – If True, the data qubits in the Pauli string will be connected by a line
log_op_fill_colors (dict[str, str] | None) – Dict containing the colors for the X, Y, and Z markers of the logical operators. If None is provided, the same colors are taken as for the stabilizers.
log_op_line_colors (dict[str, str] | None) – Dict containing the border colors for the X, Y, and Z markers of the logical operators. If None is provided, the same colors are taken as for the stabilizers.
legend_name (str | None) – Name of this Pauli string which should appear in the legend.
legendgroup (str, optional) – Legend group to which the markers belong
shift (tuple[float, float]) – 2D vector by which the data qubit markers should be shifted, relative to the original position of the data qubits.
- Returns:
List of scatter plot traces for the data qubit markers contained in the pauli string as well as (if specified) a connecting line between them.
- Return type:
list[go.Scatter]
- get_qb_coord(qb)[source]
Get the coordinates of a data qubit. The coordinates of data qubit (x, y, a) are calculated by the formula x * l[0] + y * l[1] + a * b[a], where l is the list of lattice vectors and b is the list of basis vectors. We put all these terms into a list and sum them up in the very end.
- Return type:
tuple[float,...]
- get_stabilizer_traces(stabilizers, fill_colors=None, fill='toself', opacity_stabs=None, showlegend=True, legendgroup=None)[source]
Generate the plotly traces for the stabilizers.
- Parameters:
stabilizers (list[Stabilizer]) – Stabilizers which should be plotted.
fill_colors (dict[str, str] | None) – Colors for the fill of the stabilizers. If None is provided, the default colors from the class are taken.
fill (str) – Defines how the area of the stabilizers is filled. Default is ‘toself’ which fills the area of the polygon. Another option is ‘none’ (no fill) for having only the border line but no filling.
opacity_stabs (float | None) – Opacity for the stabilizer colors. If If None is provided, the default opacity from the class is taken.
showlegend (bool, optional) – If True (the default), the stabilizers are shown in the legend.
legendgroup (str | None) – Legend group to which the stabilizers belong.
- Returns:
List of scatter plot traces for the stabilizers.
- Return type:
list[go.Scatter]
-
height:
int|None= 600
-
line_colors:
dict[str,str] |None= FieldInfo(annotation=Union[dict[str, str], NoneType], required=False, default_factory=<lambda>)
-
opacity_stabs:
float|None= 0.8
-
padding_relative:
float|None= 0.05
- plot_blocks(blocks, plot_logical_operators=True, plot_pauli_charges=False, log_ops_shift=0.03)[source]
Plot all the stabilizers of a Block or multiple Block objects.
- Parameters:
blocks (Block | list[Block]) – A block or a list of blocks to be plotted
plot_logical_operators (bool) – Whether the logical operators should be plotted, defaults to True
plot_pauli_charges (bool) – Whether the pauli charges should be plotted, defaults to False
log_ops_shift (float = 0.03) – Amount by which the logical X operator is shifted to the bottom left and the logical Z operator to the top right. This is done such that one can see both boxes at the qubit(s) on which both operators act. Defaults to 0.03.
- Return type:
None
- plot_pauli_charges(block, legendgroup=None)[source]
Plot the Pauli charges of the data qubits of the given block.
- Parameters:
block (Block) – Block for which the pauli charges should be plotted
legendgroup (str | None) – Legend group to which the markers belong
- Return type:
None
- plot_pauli_string(operation, **kwargs)[source]
Add a Pauli string plotting to the figure.
- Parameters:
operation (PauliOperator) – Pauli string which should be plotted
- Return type:
None
-
rescale_coords:
bool|None= False
-
show_grid:
bool|None= False
-
stabilizers:
list[Stabilizer] |None= None
-
title:
str|None= None
-
width:
int|None= 800
-
xmax:
float|None= None
-
xmin:
float|None= None
-
ymax:
float|None= None
-
ymin:
float|None= None