We would like to add a QasmModule.draw() method that generates a circuit diagram from a parsed OpenQASM program (i.e. an openqasm3.ast.Program object). This method can either generate either a raw ASCII string or leverage external visualization tools like pylatex, but should not depend on any other quantum packages outside of the openqasm3.
Because of the large number of gates and operations supported by OpenQASM, we will restrict this first implementation to a smaller gate-set to make it a little more approachable. For this, you can use the following code to generate random qasm strings to use as the test data/files for the circuit drawer. Once the circuit drawer is reliably working for any circuits generated by this function, then we will consider this issue closed, and open a new issue that expands the scope.
pip install qbraid
pip install qiskit
pip install qiskit-qasm3-import --no-deps
import random
from pyqasm import load
from qbraid import random_circuit, transpile
qiskit_circuit = random_circuit("qiskit", measure=random.choice([True, False]))
qasm_str = transpile(qiskit_circuit, random.choice(["qasm2", "qasm3"]))
pyqasm_module = load(qasm_str)
pyqasm_module.draw()
We would like to add a
QasmModule.draw()method that generates a circuit diagram from a parsed OpenQASM program (i.e. anopenqasm3.ast.Programobject). This method can either generate either a raw ASCII string or leverage external visualization tools like pylatex, but should not depend on any other quantum packages outside of theopenqasm3.Because of the large number of gates and operations supported by OpenQASM, we will restrict this first implementation to a smaller gate-set to make it a little more approachable. For this, you can use the following code to generate random qasm strings to use as the test data/files for the circuit drawer. Once the circuit drawer is reliably working for any circuits generated by this function, then we will consider this issue closed, and open a new issue that expands the scope.