diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b12961..85f01b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,55 @@ Types of changes: ### Added - Added logic to `bump-version.yml` workflow that automatically updates `CITATION.cff` upon new release ([#147](https://github.com/qBraid/pyqasm/pull/147)) +- Added `pyqasm.draw()` function that draws quantum circuit ([#122](https://github.com/qBraid/pyqasm/pull/122)): + +```python +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') +``` + +![Screenshot 2025-03-17 at 2 23 14 PM](https://github.com/user-attachments/assets/9f7cdf35-997e-4858-8f79-016b449c68a4) + +\- Currently, only the `mpl` (matplotlib) output format is supported. + +\- Use `draw(..., idle_wires=False)` to draw circuit without empty qubit/classical bit registers. + +\- Save the visualization to a file by specifying `output='mpl'` and a `filename`: + ```python + draw(..., output='mpl', filename='/path/to/circuit.png') + ``` + +\- The draw method accepts either a `str` (QASM source) or a `QasmModule`. The following are equivalent: + +```python +from pyqasm import loads, draw +from pyqasm.printer import mpl_draw + +module = loads(qasm_str) + +draw(module, output='mpl') +draw(qasm_str, output='mpl') + +draw(module) +draw(qasm_str) +``` ### Improved / Modified