Skip to main content
API Reference: qbraid.visualization

Draw Circuit Diagrams

qBraid’s circuit_drawer function takes in any type of supported quantum circuit and draws the corresponding visualization. Here’s an example using braket and cirq:
from qbraid import random_circuit
from qbraid.visualization import circuit_drawer

circuit = random_circuit("braket")
circuit_drawer(circuit)
# T  : |0| 1 |2|
#
# q0 : -C-C---S-
#       | |
# q1 : -Z-|-Z---
#         |
# q2 : -Z-X-----
#
# T  : |0| 1 |2|

circuit = random_circuit("cirq")
circuit_drawer(circuit)
# 0: ───────────×───Z───
#               │
# 1: ───iSwap───×───────
#       │
# 2: ───iSwap───Y───H───

Draw OpenQASM 3 circuits

The circuit_drawer function accepts a string of OpenQASM 3 code and returns a matplotlib figure of the circuit:
from qbraid.visualization import circuit_drawer

program = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
h q[0];
cx q[0], q[1];
"""

circuit_drawer(program)
Note: The above is the equivalent to calling pyqasm.draw(..., output="mpl")

Plot Experimental Results

Gather the measurement counts and plot the histogram data for any Result constructed from ResultData of type qbraid.runtime.GateModelResultData:
from qbraid.visualization import plot_histogram

counts = result.data.get_counts()
# {'00': 483, '01': 14, '10': 486, '11': 17}

plot_histogram(counts)