3
$\begingroup$

I am trying to run below code in PyCharm:

from qiskit.circuit.library import MCXGate, HGate 
from qiskit import QuantumCircuit

circuit = QuantumCircuit(4)

circuit.append(HGate(), [0]) 
circuit.append(MCXGate(3), [0,1,2,3])

circuit.draw('mpl')

But I don't see any output circuit. The plot window flashes for a bit but it immediately closes itself. If I use inline figures then I can get the circuit diagram but I want the interactive version. Can someone please help me with this issue. I have always used PyCharm for my other projects so I don't really want to change to another IDE.

$\endgroup$

1 Answer 1

5
$\begingroup$

By default, qiskit draws the quantum circuit for inline visualization (because inline figures are typlically used with jupyter lab). To fix this issue, you need to explicitly use .show() method from matplotlib.pyplot if you are creating the figure from an IDE. So, your code will look something like this:

from qiskit.circuit.library import MCXGate, HGate
from qiskit import QuantumCircuit
import matplotlib.pyplot as plt

circuit = QuantumCircuit(4)

circuit.append(HGate(), [0])
circuit.append(MCXGate(3), [0,1,2,3])

circuit.draw('mpl')
plt.show()    # Add this line

Hope this helps!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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