1

I'm learning how to use qiskit and I'm using the jupyter notebook, but everytime I try to visualize the circuit with the attribute draw I get this error:

import qiskit
from qiskit import *
from qiskit import IBMQ
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)
%matplotlib inline
circuit.draw(output='mpl')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-bd220039ee1c> in <module>
----> 1 circuit.draw(output='mpl')

AttributeError: module 'qiskit.circuit' has no attribute 'draw'

I also try applying a Hadamard gate and I get:

circuit.h(qr(0))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-59-c8b4318b743b> in <module>
----> 1 circuit.h(qr(0))

AttributeError: module 'qiskit.circuit' has no attribute 'h'
SAR_90
  • 45
  • 3
  • This code seems to work for me, if as @luciano suggested it's an import problem, maybe try `from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit` instead of the imports you have now? – Frank Nov 06 '20 at 09:25
  • 1
    Also, instead of `circuit.h(qr(0))`, you will need square brackets to return the qubit, i.e. `circuit.h(qr[0])` – Frank Nov 06 '20 at 09:26

1 Answers1

0

It seems that there is a name conflict. It is taking the circuit in from qiskit import circuit instead of circuit = ....

You just probably need to restat your notebook kernel.

luciano
  • 205
  • 2
  • 10
  • Can you run just the example you posted in a fresh notebook? As @Frank, I'm unable to reproduce the problem – luciano Nov 06 '20 at 12:10