@@ -84,33 +84,41 @@ def __init__(
84
84
online_date = configuration .online_date ,
85
85
backend_version = configuration .backend_version ,
86
86
)
87
-
88
87
self ._configuration = configuration
89
88
self ._api_client = api_client
90
89
self ._properties = None
91
90
self ._qubit_properties = None
92
91
self ._defaults = None
93
-
92
+ self . _target = None
94
93
self ._max_circuits = configuration .max_experiments
95
94
96
- api_properties = self ._api_client .backend_properties (self .name )
97
- if api_properties :
98
- backend_properties = properties_from_server_data (api_properties )
99
- self ._properties = backend_properties
100
-
101
- api_defaults = self ._api_client .backend_pulse_defaults (self .name )
102
- if api_defaults :
103
- self ._defaults = defaults_from_server_data (api_defaults )
104
-
105
- self ._target = convert_to_target (
106
- configuration = configuration .to_dict (),
107
- properties = self ._properties .to_dict () if api_properties else None ,
108
- defaults = self ._defaults .to_dict () if api_defaults else None ,
109
- )
110
-
111
- if api_properties :
112
- self ._qubit_properties = qubit_properties_dict_from_properties (
113
- self ._properties .to_dict ()
95
+ def __getattr__ (self , name : str ) -> Any :
96
+ if not self ._properties :
97
+ api_properties = self ._api_client .backend_properties (self .name )
98
+ if api_properties :
99
+ backend_properties = properties_from_server_data (api_properties )
100
+ self ._properties = backend_properties
101
+ if not self ._qubit_properties :
102
+ self ._qubit_properties = qubit_properties_dict_from_properties (
103
+ self ._properties .to_dict ()
104
+ )
105
+ if not self ._defaults :
106
+ api_defaults = self ._api_client .backend_pulse_defaults (self .name )
107
+ if api_defaults :
108
+ self ._defaults = defaults_from_server_data (api_defaults )
109
+ if not self ._target :
110
+ self ._target = convert_to_target (
111
+ configuration = self ._configuration .to_dict (),
112
+ properties = self ._properties .to_dict () if api_properties else None ,
113
+ defaults = self ._defaults .to_dict () if api_defaults else None ,
114
+ )
115
+ try :
116
+ return super ().__getattribute__ (name )
117
+ except KeyError :
118
+ raise AttributeError (
119
+ "'{}' object has no attribute '{}'" .format (
120
+ self .__class__ .__name__ , name
121
+ )
114
122
)
115
123
116
124
@classmethod
@@ -164,7 +172,7 @@ def qubit_properties(
164
172
"""
165
173
if not self ._qubit_properties :
166
174
return None
167
- if isinstance (qubit , int ):
175
+ if isinstance (qubit , int ): # type: ignore[unreachable]
168
176
return self ._qubit_properties .get (qubit )
169
177
if isinstance (qubit , List ):
170
178
return [self ._qubit_properties .get (q ) for q in qubit ]
@@ -217,7 +225,7 @@ def properties(
217
225
218
226
if datetime or refresh or self ._properties is None :
219
227
api_properties = self ._api_client .backend_properties (
220
- self .name () , datetime = datetime
228
+ self .name , datetime = datetime
221
229
)
222
230
if not api_properties :
223
231
return None
@@ -241,7 +249,7 @@ def status(self) -> BackendStatus:
241
249
Raises:
242
250
IBMBackendApiProtocolError: If the status for the backend cannot be formatted properly.
243
251
"""
244
- api_status = self ._api_client .backend_status (self .name () )
252
+ api_status = self ._api_client .backend_status (self .name )
245
253
246
254
try :
247
255
return BackendStatus .from_dict (api_status )
@@ -266,7 +274,7 @@ def defaults(self, refresh: bool = False) -> Optional[PulseDefaults]:
266
274
The backend pulse defaults or ``None`` if the backend does not support pulse.
267
275
"""
268
276
if refresh or self ._defaults is None :
269
- api_defaults = self ._api_client .backend_pulse_defaults (self .name () )
277
+ api_defaults = self ._api_client .backend_pulse_defaults (self .name )
270
278
if api_defaults :
271
279
self ._defaults = defaults_from_server_data (api_defaults )
272
280
else :
@@ -292,7 +300,7 @@ def configuration(
292
300
return self ._configuration
293
301
294
302
def __repr__ (self ) -> str :
295
- return "<{}('{}')>" .format (self .__class__ .__name__ , self .name () )
303
+ return "<{}('{}')>" .format (self .__class__ .__name__ , self .name )
296
304
297
305
def run (self , * args : Any , ** kwargs : Any ) -> None :
298
306
"""Not supported method"""
@@ -335,7 +343,7 @@ def __init__(
335
343
"""
336
344
super ().__init__ (configuration , api_client )
337
345
self ._status = BackendStatus (
338
- backend_name = self .name () ,
346
+ backend_name = self .name ,
339
347
backend_version = self .configuration ().backend_version ,
340
348
operational = False ,
341
349
pending_jobs = 0 ,
0 commit comments