Closed cruzar closed 5 years ago
It is correct but it needs more space before the measurement.
It also happens without the measurement.
Hi @cruzpmmq
I am not sure what you think is incorrect. The number is the phase that is added if both qubits are in the 1 state. I agree that in the picture you uploaded it is too far away and looks like it is part of the measurement.
Hi @jaygambetta
I was expecting the usual boxed notation for controlled operations. Also, the following snippet implements the fourier transform on three qubits and the figure representation doesn't look so nice...
from qiskit import QuantumProgram
from qiskit.tools.visualization import circuit_drawer
from numpy import pi
qp = QuantumProgram()
qr = qp.create_quantum_register('qr', 3)
qc = qp.create_circuit('qc', [qr])
c_rk = lambda k, ctl, tgt: qc.cu1(2*pi/(2**k), ctl, tgt)
qc.h(qr[0])
c_rk(2, qr[1], qr[0])
c_rk(3, qr[2], qr[0])
qc.h(qr[1])
c_rk(2, qr[1], qr[2])
qc.h(qr[2])
circuit_drawer(qc)
@cruzpmmq the CU1 gate is symmetric. So this is the correct notation. A boxed notation would imply that control and target are different.
I agree the angles should be spaced out better. It is due to latex's column layout where the label of one column runs into the other column. I'll try to adjust it.
@ajavadia
Ok, I understand. I was just mentioning that because this operation is sometimes represented with a boxed notation (e.g. Fig.5.1 Nielsen & Chuang), and also because cu1() has ctl and tgt parameters. Thanks for looking into it.
By the way, on another subject: One very helpful feature to add to this drawing methods would be to include a parameter for the user to choose if the numbering on the qubits of the diagram goes 0,1,2,.. from top to bottom (as it is) or bottom-up. That would be very helpful.
You may consider to use matplotlib_circuit_drawer
.
from qiskit import QuantumProgram
from qiskit.tools.visualization import matplotlib_circuit_drawer as circuit_drawer
from numpy import pi
%matplotlib inline
%config InlineBackend.figure_format = "svg"
qp = QuantumProgram()
qr = qp.create_quantum_register('qr', 3)
qc = qp.create_circuit('qc', [qr])
c_rk = lambda k, ctl, tgt: qc.cu1(2*pi/(2**k), ctl, tgt)
qc.h(qr[0])
c_rk(2, qr[1], qr[0])
c_rk(3, qr[2], qr[0])
qc.h(qr[1])
c_rk(2, qr[1], qr[2])
qc.h(qr[2])
my_style = {"usepiformat":True}
circuit_drawer(qc, style=my_style)
It allows you to write the box-ed control. Please refer to the tutorial here: https://nbviewer.jupyter.org/github/Qiskit/qiskit-tutorial/blob/master/reference/tools/matplotlib_circuit_drawer.ipynb
from qiskit import QuantumProgram
from qiskit.tools.visualization import matplotlib_circuit_drawer as circuit_drawer
from numpy import pi
%matplotlib inline
%config InlineBackend.figure_format = "jpeg"
qp = QuantumProgram()
qr = qp.create_quantum_register('qr', 3)
qc = qp.create_circuit('qc', [qr])
c_rk = lambda k, ctl, tgt: qc.cu1(2*pi/(2**k), ctl, tgt)
qc.h(qr[0])
c_rk(2, qr[1], qr[0])
c_rk(3, qr[2], qr[0])
qc.h(qr[1])
c_rk(2, qr[1], qr[2])
qc.h(qr[2])
my_style = {"usepiformat":True, "latexdrawerstyle":False}
circuit_drawer(qc, style=my_style)
@diego-plan9 the latex drawer requires latex installation (several GBs) and the installation can be technically difficult for various environment. I suggest we close this issue by making the matplotlib drawer as the default drawer.
@diego-plan9 the latex drawer requires latex installation (several GBs) and the installation can be technically difficult for various environment. I suggest we close this issue by making the matplotlib drawer as the default drawer.
Hmm, currently if using circuit_drawer()
, the latex drawer is tried first, but falls back to the matplotlib one; and the user can chose which one to use by calling the function invidually (latex_circuit_drawer()
or matplotlib_circuit_drawer()
.
Which I think covers the case you mention, if I'm reading it right: if the user is not willing/not able to install latex and the dependencies (which indeed are huge), in practice the matplotlib will be used as "default" when calling circuit_drawer()
. Does this behaviour map into your request? If not, could you comment on https://github.com/Qiskit/qiskit-terra/issues/612, for general improvements about the circuit drawer as whole?
A summary about this issue:
There is an error in the spacing of cu1
gate in the LaTeX drawer (as explained in https://github.com/Qiskit/qiskit-terra/issues/693#issuecomment-408645734). @ajavadia "will try to adjust it" (I'm assigning @ajavadia, feel free to remove yourself). Also, @qruzar mentioned the reversebits
issue, which should be addressed by merged PR #762.
The only thing left to do for this issue is to increase spacing of parameters for better readability. I adjusted the title accordingly.
QISKit's visualization module is not properly drawing the cu1 gate. With the following code,
The obtained image is,
Which is clearly corrupt.
Informations