0
$\begingroup$

I've started learning quantum computing using 'Learn quantum computation using qiskit', and I've stumbled upon what I think is a bug in the code in chapter 1.3: Representing Qubit States when I reached the part and run the code:

qc = QuantumCircuit(1) 
initial_state = [0,1]   
qc.initialize(initial_state, 0)
qc.draw()   

It returned 'Attribute Error' Saying that 'Initialize' object has no attribute 'label'

$\endgroup$
  • $\begingroup$ Have you been able to solve this? The above solution results in the following error: ``` QiskitError: 'Initialize parameter vector has 2 elements, therefore expects 1 qubits. However, 0 were provided. ``` $\endgroup$ – Dunsin Jul 7 at 20:40
2
$\begingroup$

This is a known bug in Qiskit (https://github.com/Qiskit/qiskit-terra/issues/4439).

As a workaround, you can create an initialize gate and add the missing label using:

from qiskit.extensions import Initialize

qc = QuantumCircuit(1)
initial_state = [0,1]

init_gate = Initialize(initial_state) # Create a new initialize gate
init_gate.label = "init"    # Add a label to avoid the bug

qc.append(init_gate, 0)     # Perform the gate on the 0th qubit
qc.draw()    # Draw the circuit (to complete your code block)

Hope this helps!

| improve this answer | |
$\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.