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)

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

  • $\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 '20 at 20:40

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!


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.