Skip to content
New issue

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

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

Already on GitHub? # to your account

Sampler (both V1 and V2) does not apply controlled parameterized rotations #2323

Open
AlbertJP opened this issue Mar 3, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@AlbertJP
Copy link

AlbertJP commented Mar 3, 2025

Informations

  • Qiskit Aer version: 0.16.2
  • Python version: 3.12.3
  • Operating system: Ubuntu in WSL on Windows 11

What is the current behavior?

Controlled parameterized gates (like CRYGate) seem to be ignored when running the Sampler (V1 or V2).

Steps to reproduce the problem

from qiskit.circuit import QuantumCircuit, Parameter
import numpy as np
from qiskit_aer.primitives import Sampler
from qiskit_aer.primitives import SamplerV2

sampler = Sampler()
sampler_v2 = SamplerV2()

a = Parameter("a")
qc = QuantumCircuit(2)
qc.x(0)
qc.cry(a, 0, 1)
qc.x(0)

# Parameter list
params = [np.pi / 4]

qc_measured = qc.measure_all(inplace=False)

dist = sampler.run(qc_measured, params).result().quasi_dists
print("Dist V1", dist)

dist_v2 = sampler_v2.run([(qc_measured, params)]).result()[0].data.meas.get_counts()
print("Dist V2", dist_v2)

qc_bound = qc_measured.assign_parameters(params)

dist = sampler.run(qc_bound).result().quasi_dists
print("Dist V1", dist)

dist_v2 = sampler_v2.run([(qc_bound)]).result()[0].data.meas.get_counts()
print("Dist V2", dist_v2)

Result:

Dist V1 [{0: 1.0}]
Dist V2 {'00': 1024}
Dist V1 [{2: 0.14453125, 0: 0.85546875}]
Dist V2 {'00': 886, '10': 138}

What is the expected behavior?

Both circuits, the one with assigned parameters and the one without assigned parameters, should return similar values.

Suggested solutions

As shown in the example, this can be circumvented by assigning parameters before running the Sampler.

@AlbertJP AlbertJP added the bug Something isn't working label Mar 3, 2025
@AlbertJP
Copy link
Author

AlbertJP commented Mar 3, 2025

It looks like the cause is on

if instruction.operation.is_parameterized():

instruction.operation.is_parameterized() returns false for controlled rotations (see also Qiskit/qiskit#12624 (comment)).

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

No branches or pull requests

1 participant