Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5k stars 2.32k forks source link

TypeError: ParameterExpression with unbound parameters ({ParameterVectorElement()}) cannot be cast to a float. #11142

Open NahidaNahida opened 10 months ago

NahidaNahida commented 10 months ago

Environment

What is happening?

When I tried to construct a parameterized quantum circuit with multiple-controlled quantum gates with RYGate(theta).control(num_ctrl_qubits=5, ctrl_state='01101'), [0,1,2,3,4,5]) in ubuntu OS, it turns to be a warning that TypeError: ParameterExpression with unbound parameters ({ParameterVectorElement(θ[0])}) cannot be cast to a float.. If I applied this controlled gate with fewer control qubits, the warning would not occur. By contrast, as I ran the codes in windows OS, nothing unexpected happened, in the case of the same version of qiskit.

I don't know what is wrong with that and I wonder whether ubuntu OS triggers this bug.

How can we reproduce the issue?

Run the below codes, especially in ubuntu

from qiskit.circuit import QuantumCircuit, ParameterVector
from qiskit.circuit.library import RYGate

theta_list = ParameterVector('θ', 6)                                   
circuit = QuantumCircuit(10)
for theta in theta_list:                              
    circuit.append(RYGate(theta).control(num_ctrl_qubits=5,
                                        ctrl_state='01101'), 
                                        [0,1,2,3,4,5])
circuit.draw('mpl')

What should happen?

The program crash should not happen like that in windows OS.

Any suggestions?

No response

Raghav-Bell commented 10 months ago

Please refer to issue #10697 .

zhiyaol commented 9 months ago

I'm experiencing this exact issue.

NahidaNahida commented 9 months ago

I'm experiencing this exact issue.

My temporary solution is to give up the parameterized circuit and directly bind parameters when applying the rotation gates.

SimoneGasperini commented 9 months ago

This is related to issue #10311.