Conversation
ryanhill1
left a comment
There was a problem hiding this comment.
This progress looks good! A couple things:
- Gate angle formatting: For parameterized gates, the angle below the gate's name goes all the way out to the edges of the gate box, and for negative numbers, it bleeds over the sides. I think remove the parentheses around the angle and making the font size of the angle slightly smaller than the gate name could make it fit better, and allow the main focus to be on the gate name itself.
- Support for barriers: Add support for barriers. Currently being omitted from the diagram:
from pyqasm import loads
qasm3 = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
h q;
barrier q[0], q[1];
cnot q[0], q[1];
"""
module = loads(qasm3)
module.draw()- Measurement gate formatting:
- Measurement gates are currently being stacked on top of one another which makes it difficult to read. Would be better to space them out.
- The arrow pointing to the classical bit to measure currently goes over that bottom line.
- Let's make the arrow for the measure a little bit smaller
- The current color for the measurement gates is a bit dark. Maybe a slightly lighter grey?
Ours:
from pyqasm import loads
qasm3 = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
bit[2] b;
h q;
cnot q[0], q[1];
b = measure q;
"""
module = loads(qasm3)
module.draw()vs. qiskit:
from qbraid import transpile
qiskit_circuit = transpile(qasm3, "qiskit")
qiskit_circuit.draw(output='mpl')Note: I'm not saying to copy the way they've done it, but we can both it agree that theirs looks very clean. So we can perhaps take inspiration from the elements which make their diagrams visually appealing.
- Optional to exclude idle wires: Can you add an option
idle_wiresof typeboolwhich defaults toTrue, but ifFalse, excludes any qubits and clbits that don't have any operation on them? For example:
from pyqasm import loads
qasm3 = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
bit[2] b;
rx(-pi/2) q[0];
"""
module = loads(qasm3)
module.draw()module.draw(ide_wires=False)- Duplicate image from draw output: For some reason, when a call the
.draw()method within my VS code notebook, it is "drawing" it twice. See images below. Is the same thing happening for you? See below:
- Split lines for long diagrams: For circuit diagrams that are very long, we should at a certain point, split it onto two lines so that it is readable. Currently the font just gets smaller and smaller into oblivion
|
TODO: support QuantumPhaseStatement |
|
I think Also, what's causing all of the different CI build workflows to fail? |
|
Amazing work @arulandu ! Here are some minor comments -
import pyqasm
test = """
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
gate custom a, b {
h a;
z a;
z a;
y a;
x a;
rx(0.5) a;
}
for int i in [0:2] {
custom q;
}
"""
circ = pyqasm.loads(test)
circ.draw()
import pyqasm
test = """
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
gate custom a, b {
h a;
z a;
z a;
y a;
x a;
rx(-0.5) a;
}
custom q;
"""
circ = pyqasm.loads(test)
circ.unroll(external_gates = ["custom"])
circ.draw()
|
@arulandu I think same applies for the |
|
@arulandu you need to add Moreover, since we use |
|
@TheGupta2012 |
There was a problem hiding this comment.
@arulandu I added a couple basic tests to compare against images for you that should be sufficient for now.
I did find one bug though with how barriers are displayed when moments don't line up:
from pyqasm import draw
qasm3 = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
x q[0];
barrier q;
"""
draw(qasm3)When applied across all qubits, the barrier should form a single vertical line, not be broken across qubits.
I think this is because of how Possible solutionAdd something like from pyqasm import draw
qasm3 = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q1;
x q1[0];
barrier q1;
qubit[4] q2;
h q2[1];
barrier q2;
h q2;
"""
draw(qasm3)In above image , we will apply 2 barriers -
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |












Summary of changes
Added circuit drawing functionality for QasmModule. Closes #61.