Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assign_parameters method is not working for controlled-U gate #9763

Closed
SimoneGasperini opened this issue Mar 9, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@SimoneGasperini
Copy link
Contributor

SimoneGasperini commented Mar 9, 2023

Environment

  • Qiskit Terra version: 0.23.1
  • Python version: 3.10.8

What is happening?

The QuantumCircuit.assign_parameters() method does not work properly with the parametric controlled-U gate. The values passed to be assigned to the parameters seem just to be ignored (in both cases with inplace=False or inplace=True).

How can we reproduce the issue?

from qiskit.circuit import QuantumCircuit, Parameter

chi = Parameter('$\\chi$')
theta = Parameter('$\\theta$')
phi = Parameter('$\\phi$')
lam = Parameter('$\\lambda$')
gamma = Parameter('$\\gamma$')

qc = QuantumCircuit(2)
qc.rx(chi, 1)
qc.cu(theta, phi, lam, gamma, 0, 1)

values = [4.68, 5.13, 1.06, 3.81, 3.83]
qc.assign_parameters(values, inplace=True)

qc.draw('mpl')

output

What should happen?

Each parameter of the controlled-U gate should be correctly bounded to the corresponding value passed to assign_parameters(), as it happens for any other parametric gate (Rx in the example above).

@SimoneGasperini SimoneGasperini added the bug Something isn't working label Mar 9, 2023
@SimoneGasperini SimoneGasperini changed the title The assign_parameters method is not working for controlled-U gate assign_parameters method is not working for controlled-U gate Mar 9, 2023
@jakelishman
Copy link
Member

Thanks for the report - this is a known issue (#7326), so I'll just close this as duplicate. There's a potential fix available (#9118) that I need to review properly.

The root cause is mostly that CUGate is a badly behaved subclass of ControlledGate, and really, it's not even really the controlled version of UGate (because it's got an extra parameter).

@jakelishman
Copy link
Member

Duplicate of #7326

@jakelishman jakelishman marked this as a duplicate of #7326 Mar 9, 2023
@jakelishman jakelishman closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2023
@SimoneGasperini
Copy link
Contributor Author

Yes, there is the extra gamma parameter serving as global phase.
Thank you and sorry for the duplicate, I didn't see that there was already an open issue on this.

@jakelishman
Copy link
Member

No worries - it's really our fault that the issue's been open for so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants