qiskit-tutorials icon indicating copy to clipboard operation
qiskit-tutorials copied to clipboard

Two images due to %matplotlib inline in a few tutorials

Open singhmeet11 opened this issue 3 years ago • 11 comments

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.

singhmeet11 avatar Jun 13 '21 23:06 singhmeet11

@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

singhmeet11 avatar Jun 13 '21 23:06 singhmeet11

And the last commit was by mistake, how can I remove that??

singhmeet11 avatar Jun 13 '21 23:06 singhmeet11

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!

clasicus avatar Aug 10 '21 05:08 clasicus

Hey @clasicus You are using IBM quantum lab or your local system to run ?

divshacker avatar Aug 10 '21 05:08 divshacker

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.

clasicus avatar Aug 10 '21 05:08 clasicus

Hey @clasicus It works fine for me, would you mind showing code and output which is showing this error

divshacker avatar Aug 10 '21 05:08 divshacker

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)

Screenshot_2021-08-10 phi-simulation - Jupyter Notebook Screenshot_2021-08-10 phi-simulation - Jupyter Notebook(1)

As you can see, when I use 'latex' method - it draws one picture but for 'mpl' methods twice. Also same situation with histogram.

clasicus avatar Aug 10 '21 06:08 clasicus

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 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

divshacker avatar Aug 10 '21 07:08 divshacker

Hey @clasicus Can you run this in local system and cross check if all the versions matches to above given table

No problem: Screenshot_2021-08-10 check-qiskit - Jupyter Notebook

clasicus avatar Aug 10 '21 07:08 clasicus

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

divshacker avatar Aug 10 '21 07:08 divshacker

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: Screenshot_2021-08-10 check-qiskit - Jupyter Notebook(1) 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: Screenshot_2021-08-10 check-qiskit - Jupyter Notebook(2)

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.

clasicus avatar Aug 10 '21 07:08 clasicus

Thanks for opening this! I'm not seeing it as an issue on the live Qiskit docs. Perhaps it was fixed along the way.

Eric-Arellano avatar Aug 21 '23 15:08 Eric-Arellano