Skip to Content
DocsUnitaryLab Simulator User ManualCircuit ToolsCircuit Analysis and Drawing

Circuit Analysis and Drawing

draw() is intended for presentation; analyze() returns structured statistics. Neither executes or modifies the circuit.

from unitarylab import Circuit qc = Circuit(2) qc.h(0) qc.cx(0, 1) qc.draw() qc.draw(filename="circuit.png", title="Bell State") qc.draw(output="text") qc.draw(output="latex")

output supports Matplotlib, plain text, and LaTeX (quantikz). In a notebook, plots are displayed inline; in a regular script, a separate window is opened.

draw(filename=None, title=None, compact=True, output="mpl", **kwargs)
OutputReturn value or behaviorUse
mplMatplotlib figure; can be saved with filenameNotebooks, reports, and image files
textMonospaced circuit diagramTerminals, logs, and code review
latexquantikz LaTeXPapers and typesetting systems

For large circuits, call decompose() to inspect block-gate internals or retain block gates for a compact overview. LaTeX output requires a toolchain that supports quantikz.

Register Labels and Index Subscripts

Matplotlib output renders quantum-register bit indices as subscripts, for example for the default register, or a subscript 0 after a custom register name such as data. Indices start at 0 within each register; the qubit mappings used by gate operations are unchanged.

from unitarylab import Circuit, Register register = Register("data_x", 2) labeled = Circuit(register) labeled.h(0) labeled.cx(0, 1) labeled.draw(filename="register_labels.svg", output="mpl")

Underscores, dollar signs, and other characters in custom names remain literal name text; only the appended bit index is a subscript. Do not add math-formatting markup to Register.name yourself. Long names may still be shortened to fit the label width. This fix applies to Matplotlib drawing and its image exports; it does not change the text or LaTeX drawer interfaces.

CircuitInfo

info = qc.analyze(show=False) info.show() info.show(sections=["overview", "coupling_map"]) info.show(sections="qubit_history", qubit=0)
MethodDescription
size() / depth()Gate count and greedy-layer depth
count_ops()Count operations by gate type
count_single_qubit_gates() and related methodsCount by number of acted-on qubits
count_parameterized_gates()Number of parameterized gates
get_qubit_usage()Operation counts per qubit
get_coupling_map()Two-qubit gate connectivity
get_qubit_history()Operation history for a selected qubit
get_instructions() / get_layers() / get_parameters()Instructions, layers, and parameters
get_summary() / to_dict()Structured analysis summary

Circuits without non-unitary operations such as measurement can also call get_matrix(). get_matrix(m=1) returns the upper-left sub-block.

analyze(sections=None, show=True, qubit=None) returns CircuitInfo. Set show=False to suppress printing while reading statistics programmatically. sections accepts a single name or a list.

Scale and limitations

  • Drawing and analysis describe circuit structure; they do not establish execution correctness.
  • depth() uses the analyzer’s layering rules and may differ from the schedule depth after hardware mapping.
  • get_matrix() constructs a matrix and is suitable only for small circuits without measurements.
  • When saving images, use a filename extension matching the output format and ensure the destination directory exists.
Last updated on