-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QasmModule Circuit Drawer #122
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_wires
of typebool
which 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix merge conflicts
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 |
Summary of changes
Added circuit drawing functionality for QasmModule. Closes #61.