qiskit-tutorials
qiskit-tutorials copied to clipboard
Two images due to %matplotlib inline in a few tutorials
Problem - Each images is printed twice after executing draw('mpl') , in the tutorial for a few tutorials mainly - circuit basics, getting started with Qiskit, Device backend noise model simulations and Entanglement verification.
This is in continuation with issue #1199.
Possible solution - Solution is to remove %matplotlib inline, this has been discussed in the issue Qiskit/qiskit#1265.
@divshacker why don't you take care of the other two since we came across this issue together. And should we remove %matplotlib inline
from other tutorials too?? I actually went through all the tutorials and only 5 of them had this problem, some don't use mpl
images some do but these were the only ones with repetitive images. Let me know what you think
And the last commit was by mistake, how can I remove that??
Hello! I don't use %matplotlib inline
however I still have two circuits when I draw it by using mpl
method. Moreover, when I use plot_histogram
it also draws two histograms.
qiskit 0.29.0 qiskit-aer 0.8.2 qiskit-aqua 0.9.4 qiskit-ibmq-provider 0.16.0 qiskit-ignis 0.6.0 qiskit-terra 0.18.1
Python 3.9.2
Thank you for your help!
Hey @clasicus You are using IBM quantum lab or your local system to run ?
Hey @clasicus You are using IBM quantum lab or your local system to run ?
Good day! I use local jupyter-notebook. However, checked qiskit lab, for example, here: https://learn.qiskit.org/course/ch-labs/lab-1-quantum-circuits And it works well.
Hey @clasicus It works fine for me, would you mind showing code and output which is showing this error
Hey @clasicus It works fine for me, would you mind showing code and output which is showing this error
Of course, thank you.
For example:
from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram
qc = QuantumCircuit(2,2)
qc.h(0)
qc.cnot(0,1)
qc.measure([0,1],[0,1])
qc.draw('mpl')
qc.draw('latex')
backend = Aer.get_backend('qasm_simulator')
result = execute(qc, backend, shots = 100).result()
counts = result.get_counts()
plot_histogram(counts)
As you can see, when I use 'latex' method - it draws one picture but for 'mpl' methods twice. Also same situation with histogram.
Hello! I don't use
%matplotlib inline
however I still have two circuits when I draw it by usingmpl
method. Moreover, when I useplot_histogram
it also draws two histograms.qiskit 0.29.0 qiskit-aer 0.8.2 qiskit-aqua 0.9.4 qiskit-ibmq-provider 0.16.0 qiskit-ignis 0.6.0 qiskit-terra 0.18.1
Python 3.9.2
Thank you for your help!
Hey @clasicus Can you run this in local system and cross check if all the versions matches to above given table
import qiskit.tools.jupyter
%qiskit_version_table
Hey @clasicus Can you run this in local system and cross check if all the versions matches to above given table
No problem:
Well I can't reproduce two images you are getting by using your code and your version. Let's see what others have to say
Well I can't reproduce two images you are getting by using your code and your version. Let's see what others have to say
Okay, thank you very much!
UPD: I tried to run my previous code by one-shot. And recognized next.
If I use only this code:
from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram
qc = QuantumCircuit(2,2)
qc.h(0)
qc.cnot(0,1)
qc.measure([0,1],[0,1])
qc.draw('mpl')
qc.draw('latex')
I will have this result:
As we know, qiskit must print only the last picture, in this case 'latex' version. First, original 'mpl' picture is ignored and 'latex' is drawn. It's okay. But after it suddenly we see second 'mpl' draw.
Same situation be with histogram.
Eventually, I was playing a little bit with code and if we use next code:
from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram
qc = QuantumCircuit(2,2)
qc.h(0)
qc.cnot(0,1)
qc.measure([0,1],[0,1])
qc.draw('mpl')
qc.draw('latex')
backend = Aer.get_backend('qasm_simulator')
result = execute(qc, backend, shots = 100).result()
counts = result.get_counts()
plot_histogram(counts)
qc.draw('latex')
We see next:
By default, qiskit must ignore first 'latex', and 'mpl' and histogram. And must print only second 'latex'. But in real case we see, that qiskit ignores all previous original pictures and after second 'latex' suddenly draws one more 'mpl' and histogram.
Thanks for opening this! I'm not seeing it as an issue on the live Qiskit docs. Perhaps it was fixed along the way.