[docs]classQIProvider(BaseProvider):"""List QIBackends integrated with QiskitBackend interface."""def__init__(self)->None:self._qiskit_backends=self._construct_backends()asyncdef_fetch_qi_backend_types(self)->List[BackendType]:"""Fetch backend types from CJM using api client. (Implemented without paging only for demonstration purposes, should get a proper implementation) """asyncwithApiClient(config())asclient:page_reader=PageReader[PageBackendType,BackendType]()backend_types_api=BackendTypesApi(client)backend_types:List[BackendType]=awaitpage_reader.get_all(backend_types_api.read_backend_types_backend_types_get)returnbackend_typesdef_construct_backends(self)->List[QIBackend]:"""Construct QIBackend using fetched backendtypes and metadata."""qi_backend_types=run_async(self._fetch_qi_backend_types())qi_backends=[QIBackend(provider=self,backend_type=backend_type)forbackend_typeinqi_backend_types]returnqi_backends
[docs]defget_backend(self,name:Optional[str]=None,id:Optional[int]=None)->QIBackend:filter_arguments:dict[str,Any]={}ifnameisnotNone:filter_arguments["name"]=nameifidisnotNone:filter_arguments["id"]=idforbackendinself._qiskit_backends:ifall(getattr(backend,key)==valueforkey,valueinfilter_arguments.items()):returnbackendraiseValueError(f"Backend {name} not found")