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

Fix from backend of V2 primitives to use existing AerSimulator #2173

Merged
merged 8 commits into from
Jul 8, 2024
4 changes: 3 additions & 1 deletion qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,9 @@ def from_backend(cls, backend, **options):
open_pulse=False,
memory=False,
max_shots=int(1e6),
coupling_map=list(backend.coupling_map.get_edges()),
coupling_map=(
None if backend.coupling_map is None else list(backend.coupling_map.get_edges())
),
max_experiments=backend.max_circuits,
description=description,
)
Expand Down
5 changes: 4 additions & 1 deletion qiskit_aer/primitives/estimator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def __init__(
def from_backend(cls, backend, **options):
"""make new sampler that uses external backend"""
estimator = cls(**options)
estimator._backend = AerSimulator.from_backend(backend)
if isinstance(backend, AerSimulator):
estimator._backend = backend
else:
estimator._backend = AerSimulator.from_backend(backend)
return estimator

@property
Expand Down
5 changes: 4 additions & 1 deletion qiskit_aer/primitives/sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def __init__(
def from_backend(cls, backend, **options):
"""make new sampler that uses external backend"""
sampler = cls(**options)
sampler._backend = AerSimulator.from_backend(backend)
if isinstance(backend, AerSimulator):
sampler._backend = backend
else:
sampler._backend = AerSimulator.from_backend(backend)
return sampler

@property
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix_from_backend-a885d43caf390873.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
`from_backend` function of V2 primitives are fixed to accept AerSimulator
objects as input so that user can define simulator objects outside of
primitives
Loading