Skip to content

quantum_info.Operator constructor raises an unexpected unbound parameter error #10002

@SimoneGasperini

Description

@SimoneGasperini

Environment

  • Qiskit Terra version: 0.23.1
  • Python version: 3.10.8

What is happening?

The quantum_info.Operator constructor fails because of an unbound parameter while all the free parameters of the circuit seem to be properly bound.

How can we reproduce the issue?

from qiskit import QuantumCircuit
from qiskit.circuit import ParameterVector
from qiskit.circuit.library import RGate

pqc = QuantumCircuit(2)
xs = ParameterVector(name='x', length=2)
gate = RGate(*xs).control(num_ctrl_qubits=1)
pqc.append(gate, [0, 1])

pqc.draw('mpl')

Capture

from qiskit.quantum_info import Operator

qc = pqc.assign_parameters([2.34, 0.98])
op = Operator(qc)

TypeError: ParameterExpression with unbound parameters ({ParameterVectorElement(x[0])}) cannot be cast to a float.

What should happen?

The code above should work correctly. For other very similar parameterized quantum circuit (see the pqc instance defined below), it runs as expected without any problem.

pqc = QuantumCircuit(3)
xs = ParameterVector(name='x', length=2)
gate = RGate(*xs).control(num_ctrl_qubits=2)
pqc.append(gate, [0, 1, 2])

Any suggestions?

I actually have no idea about why this is happening but it looks like a problem only related to controlled-gates with more than one parameter (e.g. CRGate, CUGate).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions