view_program renders a routed TopologicalProgram (produced by
routing) as an interactive 3-D HTML page. The
page needs no server and opens directly in any browser, but it loads its 3-D library from a
CDN, so viewing it requires internet access.Here’s a small routed program (S, H, T, RZ, CX on two qubits) rendered by the viewer:
This viewer is fully interactive, so go ahead and play with it! Drag to orbit, scroll to zoom, right-drag to pan, and use the toggles at the top right to switch between the surface-code and logical views.
from classiq.error_correction.viewer import view_program# view_program returns the visualization as an HTML string:html = view_program(program)# Save it to a file yourself...with open("routed_program.html", "w") as f: f.write(html)# ...or let view_program save and display it for you:view_program(program, output_path="routed_program.html", show=True)
The show=True behaviour depends on where you run it:
In a Jupyter notebook, the viewer is embedded directly in the cell’s output, so you can
rotate and inspect it inline without leaving the notebook.
Outside a notebook, it opens output_path in your web browser — so output_path is
required when show=True (otherwise a ClassiqValueError is raised). To just get the HTML
without displaying it, omit show (or pass show=False) and use the returned string.
The lattice’s z-axis is time, measured in cycles. A cycle is one logical time step, one
z-layer of the lattice, and the noise model assumes each cycle spans exactly d rounds of
stabilizer measurement, where d is the code distance.For a tall program this can be a lot to render at once, so view_program accepts
start_cycle and end_cycle to show only a slice of the circuit along the z-axis. Cubes
outside [start_cycle, end_cycle) are hidden, and the window is shifted down so
start_cycle becomes the scene’s base.
# Show only cycles 10-30 (z-layers) of the routed program:view_program(program, output_path="routed_program.html", show=True, start_cycle=10, end_cycle=30)
start_cycle defaults to 0. end_cycle defaults to the program’s total cycle count
(program.stats.cycles), but when left unspecified it is capped to 100 cycles from
start_cycle so a very tall circuit stays manageable — pass end_cycle explicitly to
override.
The window must satisfy 0 <= start_cycle < end_cycle <= program.stats.cycles, and can
span at most 2500 cycles. A window outside these limits raises a ClassiqAPIError; narrow
the range with start_cycle/end_cycle.
Surface-code view (default) colours each cube and pipe by its X/Z boundary type. The
legend also marks Y cubes (S gates and the tips of T-gate arms), T cubes (the magic state
each T gate consumes), and H strips, the bands around a pipe where a Hadamard swaps the
boundary types.
Logical view colours each cube by the gate it belongs to; the legend lists the gate
types.
Camera presets:
View all frames the entire lattice.
View layout grid frames the 2-D qubit footprint from above (this is the default pose
when the viewer opens).
The info panel (top-left) reports the qubit count, layout, cycle count, node count, and
a per-gate breakdown.