Skip to content

Commit 9fe6be7

Browse files
doichanjhhorii
andauthored
Fix from backend of V2 primitives to use existing AerSimulator (#2173)
* Fix from_backend of V2 primitives to use existing AerSimulator * add reno, fix format * delete print for debug --------- Co-authored-by: Hiroshi Horii <[email protected]>
1 parent ad1209b commit 9fe6be7

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

qiskit_aer/backends/aer_simulator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,9 @@ def from_backend(cls, backend, **options):
855855
open_pulse=False,
856856
memory=False,
857857
max_shots=int(1e6),
858-
coupling_map=list(backend.coupling_map.get_edges()),
858+
coupling_map=(
859+
None if backend.coupling_map is None else list(backend.coupling_map.get_edges())
860+
),
859861
max_experiments=backend.max_circuits,
860862
description=description,
861863
)

qiskit_aer/primitives/estimator_v2.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ def __init__(
7676
def from_backend(cls, backend, **options):
7777
"""make new sampler that uses external backend"""
7878
estimator = cls(**options)
79-
estimator._backend = AerSimulator.from_backend(backend)
79+
if isinstance(backend, AerSimulator):
80+
estimator._backend = backend
81+
else:
82+
estimator._backend = AerSimulator.from_backend(backend)
8083
return estimator
8184

8285
@property

qiskit_aer/primitives/sampler_v2.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ def __init__(
9797
def from_backend(cls, backend, **options):
9898
"""make new sampler that uses external backend"""
9999
sampler = cls(**options)
100-
sampler._backend = AerSimulator.from_backend(backend)
100+
if isinstance(backend, AerSimulator):
101+
sampler._backend = backend
102+
else:
103+
sampler._backend = AerSimulator.from_backend(backend)
101104
return sampler
102105

103106
@property
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
`from_backend` function of V2 primitives are fixed to accept AerSimulator
5+
objects as input so that user can define simulator objects outside of
6+
primitives

0 commit comments

Comments
 (0)