3
$\begingroup$

I'm using Qiskit in Visual Studio 2019. I want to draw quantum circuits, but it only shows their sizes with text instead of figures. The output on the interactive window is like this.

>>> from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
   ...: import numpy as np
   ...: %matplotlib inline

In [2]: qr = QuantumRegister(1)
   ...: cr = ClassicalRegister(1)
   ...: circuit = QuantumCircuit(qr, cr)
   ...: circuit.h(qr[0])
Out [2]: <qiskit.extensions.standard.h.HGate at 0x2c9b16b8e80>

In [3]: circuit.draw(output="mpl")
Out [3]: <Figure size 240.8x138.46 with 1 Axes>

Is there any way to draw circuits correctly, or is it simply that Qiskit doesn't work in Visual Studio?


<edited> the qiskit version

In [6]: print(qiskit.__version__)
0.8.1
$\endgroup$
  • $\begingroup$ For me it works in the separate terminal in visual studio (on wsl) not in the interactive window. Do you know the version? print(qiskit.__version__) $\endgroup$ – Bram Jun 6 at 11:56
2
$\begingroup$

If you are in the interactive window, it probably works similarly to Jupyter Notebooks. I would run %matplotlib inline, and then try calling circuit.draw(output='mpl') again.

You could also try running the line circuit.draw(output='mpl') twice, as that also will render the Figure in Jupyter Notebookes.

$\endgroup$
  • $\begingroup$ I don't understand what you mean. Is that running# import anything I need<br/> # define the circuit<br/> %matplotlib inline<br/> circuit.draw(output='mpl') and # import anything I need<br/> # define the circuit<br/> circuit.draw(output='mpl')<br/> circuit.draw(output='mpl')? Neither work for me. $\endgroup$ – Lemonade Jun 11 at 10:43
  • $\begingroup$ How do I start a new line btw? It looks awful without any. $\endgroup$ – Lemonade Jun 11 at 10:52
  • $\begingroup$ My answer is assuming that the interactive window in Visual Studios works similar to coding in Jupyter Notebooks. Example code of what I meant is: %matplotlib inline import qiskit from qiskit import QuantumCircuit qc = QuantumCircuit(5, 5) qc.draw(output='mpl') This is the most basic example without any gates, but it should still render the empty circuit Figure $\endgroup$ – Matthew Stypulkoski Jun 11 at 13:42
  • $\begingroup$ Also not sure about starting new lines. Each of those code blocks is a separate line though. $\endgroup$ – Matthew Stypulkoski Jun 11 at 13:46
  • $\begingroup$ Still not working. But I found I can draw figures in Jupyter Notebooks, so it might be better using Jupyter Notebooks. $\endgroup$ – Lemonade Jun 17 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.