1
1
# -*- coding: utf-8 -*-
2
2
3
- # (C) Copyright 2024 IBM. All Rights Reserved.
3
+ # (C) Copyright 2024, 2025 IBM. All Rights Reserved.
4
4
#
5
5
# This code is licensed under the Apache License, Version 2.0. You may
6
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
29
29
import multiprocessing as mp
30
30
import threading
31
31
import importlib
32
+ from collections import OrderedDict
32
33
33
34
import numpy as np
34
35
import urllib3
40
41
BitArray ,
41
42
DataBin ,
42
43
)
43
- from qiskit .transpiler .target import target_to_backend_properties
44
-
45
- from qiskit_aer import AerSimulator
46
44
from qiskit_aer .primitives import SamplerV2 , EstimatorV2
47
45
48
46
from qiskit_ibm_runtime import RuntimeEncoder , RuntimeDecoder
@@ -164,15 +162,14 @@ class DAAService:
164
162
165
163
DEFAULT_SAMPLER_SHOTS : int = 1000
166
164
167
- DEFAULT_BACKEND = "aer"
168
-
169
- DEFAULT_AVALIABLE_BACKENDS = {
170
- DEFAULT_BACKEND : AerSimulator ,
171
- FakeBrisbane .backend_name : FakeBrisbane , # 127Q
172
- FakeCairoV2 .backend_name : FakeCairoV2 , # 27Q
173
- FakeLagosV2 .backend_name : FakeLagosV2 , # 7Q
174
- FakeTorino .backend_name : FakeTorino , # 133Q
175
- }
165
+ DEFAULT_AVALIABLE_BACKENDS = OrderedDict (
166
+ [
167
+ (FakeBrisbane .backend_name , FakeBrisbane ), # 127Q
168
+ (FakeCairoV2 .backend_name , FakeCairoV2 ), # 27Q
169
+ (FakeLagosV2 .backend_name , FakeLagosV2 ), # 7Q
170
+ (FakeTorino .backend_name , FakeTorino ), # 133Q
171
+ ]
172
+ )
176
173
177
174
def __init__ (
178
175
self ,
@@ -206,7 +203,7 @@ def __init__(
206
203
if backends is None :
207
204
self ._available_backends = DAAService .DEFAULT_AVALIABLE_BACKENDS
208
205
else :
209
- self ._available_backends = {}
206
+ self ._available_backends = OrderedDict ()
210
207
for backend in backends :
211
208
try :
212
209
backend_name , clazz = self .load_backend (
@@ -245,6 +242,13 @@ def __init__(
245
242
else :
246
243
self ._status_lock = threading .RLock ()
247
244
245
+ @property
246
+ def default_backend_name (self ):
247
+ """Returns the name of the first backend in self._available_backends as default.
248
+ This is used by pytest testcases only.
249
+ """
250
+ return list (self ._available_backends .keys ())[0 ]
251
+
248
252
def _assert_if_inactive (self ):
249
253
"""throw execption if service is closed"""
250
254
if not self ._active :
@@ -442,9 +446,7 @@ def get_backend_properties(self, backend_name: str) -> Dict:
442
446
}
443
447
444
448
# if backend != aer
445
- props = target_to_backend_properties (
446
- self ._get_backend (backend_name ).target
447
- ).to_dict ()
449
+ props = self ._get_backend (backend_name ).properties ().to_dict ()
448
450
config_dict = self .get_backend_configuration (backend_name )
449
451
for fill_key in ["backend_name" , "backend_version" ]:
450
452
if props .get (fill_key ) in {None , "" }:
@@ -454,17 +456,6 @@ def get_backend_properties(self, backend_name: str) -> Dict:
454
456
props ["last_update_date" ] = props ["qubits" ][0 ][0 ]["date" ]
455
457
return props
456
458
457
- def get_backend_pulse_defaults (self , backend_name : str ) -> Dict :
458
- backend = self ._get_backend (backend_name ) # check backend name is correct
459
- if (
460
- hasattr (backend , "defs_filename" )
461
- and backend .defs_filename is not None
462
- and hasattr (backend , "_load_json" )
463
- ):
464
- return backend ._load_json (backend .defs_filename )
465
- # return an empty JSON if not available
466
- return {}
467
-
468
459
def _get_storage (self , storage_type : str ) -> SharedStorage :
469
460
if storage_type in self ._storage_options :
470
461
return self ._storage_options [storage_type ]
@@ -700,7 +691,7 @@ def execute_samplerV2(self, job: Dict[str, str]) -> None:
700
691
701
692
storage = job ["storage" ]
702
693
backend_name = (
703
- job ["backend" ] if "backend" in job else DAAService . DEFAULT_BACKEND
694
+ job ["backend" ] if "backend" in job else self . default_backend_name
704
695
)
705
696
backend = self ._get_backend (backend_name )
706
697
@@ -772,10 +763,7 @@ def execute_samplerV2(self, job: Dict[str, str]) -> None:
772
763
)
773
764
)
774
765
775
- if backend_name == DAAService .DEFAULT_BACKEND :
776
- sampler = SamplerV2 (options = options )
777
- else :
778
- sampler = SamplerV2 .from_backend (backend , options = options )
766
+ sampler = SamplerV2 .from_backend (backend , options = options )
779
767
780
768
result = sampler .run (pubs , shots = shots ).result ()
781
769
usage_nanoseconds = 0
@@ -826,7 +814,7 @@ def execute_estimatorV2(self, job: Dict[str, str]) -> None:
826
814
827
815
storage = job ["storage" ]
828
816
backend_name = (
829
- job ["backend" ] if "backend" in job else DAAService . DEFAULT_BACKEND
817
+ job ["backend" ] if "backend" in job else self . default_backend_name
830
818
)
831
819
backend = self ._get_backend (backend_name )
832
820
@@ -880,10 +868,7 @@ def execute_estimatorV2(self, job: Dict[str, str]) -> None:
880
868
if isinstance (input_publike [0 ], str ):
881
869
input_publike [0 ] = qasm3 .loads (input_publike [0 ])
882
870
883
- if backend_name == DAAService .DEFAULT_BACKEND :
884
- estimator = EstimatorV2 (options = options )
885
- else :
886
- estimator = EstimatorV2 .from_backend (backend , options = options )
871
+ estimator = EstimatorV2 .from_backend (backend , options = options )
887
872
888
873
if "precision" in estimator_input :
889
874
result = estimator .run (
0 commit comments