> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qbraid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Circuit Drawer

To use the circuit drawer tool, install the `visualization` extra:

```shell theme={null}
pip install 'pyqasm[visualization]'
```

Draw a quantum circuit directly from any OpenQASM string:

```python theme={null}
from pyqasm import draw

qasm = """
OPENQASM 3.0;
include "stdgates.inc";

qubit[3] q;
bit[3] b;

h q[0];
z q[1];
rz(pi/1.1) q[0];
cx q[0], q[1];
swap q[0], q[1];
ccx q[0], q[1], q[2];
b = measure q;
"""

draw(qasm, output='mpl')
```

<div style={{ display: "flex", justifyContent: "left", alignItems: "left" }}>
  <img src="https://mintcdn.com/qbraidco/rzZT9djB25T3PqZG/pyqasm/_static/pyqasm_circuit.png?fit=max&auto=format&n=rzZT9djB25T3PqZG&q=85&s=076323158bea87d3fba8b1f25a4d3f9a" width="150%" data-path="pyqasm/_static/pyqasm_circuit.png" />
</div>

<Note>Currently, only the `mpl` (matplotlib) output format is supported.</Note>

## Input Formats

All draw methods accepts either a `str` (QASM source) or a [pyqasm.QasmModule](https://sdk.qbraid.com/pyqasm/stubs/pyqasm.QasmModule.html#pyqasm.QasmModule) object. The following are equivalent:

```python theme={null}
from pyqasm import loads, draw
from pyqasm.printer import mpl_draw

module = loads(qasm_str)

draw(module, output='mpl')
draw(qasm_str, output='mpl')

mpl_draw(module)
mpl_draw(qasm_str)
```

## Exclude Idle Wires

Use the `idle_wires=False` option to exclude idle qubits (i.e. wires with no circuit elements) in the output circuit diagram:

```python theme={null}
from pyqasm import draw

qasm = """
OPENQASM 3.0;
include "stdgates.inc";

qubit[3] q;
bit[2] b;

h q[0];
h q[1];
cx q[0], q[1];
b[0] = measure q[0];
b[1] = measure q[1];
"""

draw(qasm, idle_wires=False, output='mpl')
```

<div style={{ display: "flex", justifyContent: "left", alignItems: "left" }}>
  <img src="https://mintcdn.com/qbraidco/rzZT9djB25T3PqZG/pyqasm/_static/pyqasm_idle_wires_false.png?fit=max&auto=format&n=rzZT9djB25T3PqZG&q=85&s=adb38eabec5b8e7ba273db8dc28138b7" width="150%" data-path="pyqasm/_static/pyqasm_idle_wires_false.png" />
</div>

## Save Diagram

Save the circuit diagram to a file by specifying `output='mpl'` and a `filename`:

```python theme={null}
draw(qasm, output='mpl', filename='/path/to/circuit.png')
```
