2.3. Visualize stabilizers and circuits
Loom provides a visualization tool to help you understand the stabilizers and circuits
for your quantum error correction code. The tool can be accessed via the
visualizer package.
import loom.visualizer as vis
2.3.1. StabilizerPlot Visualizer
The StabilizerPlot class is designed to
visualize stabilizers and logical operators by plotting them on a grid of qubits. This
allows users to easily analyze the structure of their quantum error correction code.
After importing the visualizer package, you can create a
StabilizerPlot instance using a
Lattice object. The Lattice will
form the grid on which data qubits will be plotted and can be visualized using the
add_dqubit_traces() method.
from loom.eka import Lattice
# Create a StabilizerPlot instance using a square lattice and add data qubit traces
stab_plot = vis.StabilizerPlot(lattice := Lattice.square_2d((3, 2)))
stab_plot.add_dqubit_traces()
# Show the plot
stab_plot.show()
Block can then be plotted on top of the grid using the
plot_blocks() method. A
Block is a collection of stabilizers and logical operators that
represent a part of your quantum error correction code.
from loom.eka import Block, Stabilizer, PauliOperator
# Plot the stabilizers for a given Block
stab_plot.plot_blocks(
block := Block(
stabilizers=(Stabilizer("ZZ", ((0, 0, 0), (1, 0, 0))),),
logical_x_operators=(PauliOperator("XX", ((0, 0, 0), (1, 0, 0))),),
logical_z_operators=(PauliOperator("Z", ((0, 0, 0),)),),
unique_label="q1",
)
)
# Show the plot
stab_plot.show()
For more details on how to use the
StabilizerPlot class, refer to the
Visualizer Stabilizer Plot tutorial.
2.3.2. Circuit Visualizer
Alternatively, you can also visualize your Circuit using the
plot_circuit_tree() method. This method
displays the circuit into a nested tree, allowing users to easily analyze the structure
of their error correcting circuits.
from loom.eka import Eka
from loom.eka.operations import ResetAllDataQubits
from loom.interpreter import interpret_eka
my_eka = Eka(
lattice=lattice,
blocks=[block],
operations=[ResetAllDataQubits("q1", state="0")],
)
interpreted = interpret_eka(my_eka)
vis.plot_circuit_tree(interpreted.final_circuit)
For more details on how to use the
plot_circuit_tree() method, refer to the
Visualizer Circuit tutorial.