2
$\begingroup$

I'm following the YouTube tutorials for Programming on Quantum Computers and I've completed everything until I reach circuit.draw() since I don't get $|0\rangle$ or 0 next to q or c. Here's my code:

from qiskit import *

qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)

%matplotlib inline

circuit.draw()

[
q0_0:
q0_1:
c0: 2/
]

and so when I attempt an H gate, I receive the error 'QuantumRegister' object is not callable:

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

TypeError: 'QuantumRegister' object is not callable
$\endgroup$
4
$\begingroup$

There is probably a change on the default arguments of draw() function. To reproduce the same visualization as on the youtube video, try:

circuit.draw(initial_state=True, 
             cregbundle=False)

and add a Hadamard gate like:

circuit.h(qr[0])
$\endgroup$
2
  • $\begingroup$ Awesome! Thanks a lot. Where can I see other changes as to avoid problems like this in the future? $\endgroup$ – Riad Dajani Oct 12 '20 at 13:15
  • 2
    $\begingroup$ Qiskit Documentation is the place. For example, qiskit.org/documentation/stubs/… $\endgroup$ – tsgeorgios Oct 12 '20 at 13:19
2
$\begingroup$

The following also work for me if it is interest to you:

from qiskit import *
%matplotlib inline

circuit = QuantumCircuit(2,2)
circuit.h(0)
circuit.draw()

enter image description here

$\endgroup$

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.