Closed kevinsung closed 3 weeks ago
I think V2 primitives only accepts ISA circuits, so the circuits should be transpiled before passing to run()
function
(V1 primitive runs because it calls transpiler inside)
How do I obtain the appropriate transpiler target from the SamplerV2 instance?
circuit = transpile(circuit, AerSimulator(method='stabilizer'))
Do you think it is acceptable for users, or not?
It's less than ideal that the user has to initialize the AerSimulator object separately from the SamplerV2. This is not easy to discover.
I do not know how users use qiskit.primitives
with transpiler but I think we have to provide the similar way to use qiskit_aer.primitives
With qiskit.primitives
, it seems that no transpilation is required. It can even handle the EfficientSU2
gate directly (for qiskit_aer.primitives
I had to do circuit.decompose()
to decompose that gate.
For example, this works:
import numpy as np
from qiskit.circuit.library import EfficientSU2
from qiskit.primitives import StatevectorSampler
n_qubits = 8
circuit = EfficientSU2(n_qubits)
circuit.measure_all()
rng = np.random.default_rng(1234)
params = rng.choice(
[0, np.pi / 2, np.pi, 3 * np.pi / 2],
size=circuit.num_parameters,
)
samplerv2 = StatevectorSampler()
pub = (circuit, params, 10)
job = samplerv2.run([pub])
result = job.result()
To match this behavior, the primitives in Qiskit Aer should not require any transpilation. It should handle any gate that can be simulated.
Closing in favor of #2165
Informations
What is the current behavior?
stabilizer method fails with SamplerV2 even though it works with V1 Sampler.
Steps to reproduce the problem
What is the expected behavior?
Should work
Suggested solutions