Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions qiskit_ibm_runtime/api/clients/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ def __init__(self, params: ClientParameters) -> None:
project=project,
)

def list_backends(self) -> List[Dict[str, Any]]:
"""Return backends available.
def backend_configuration(self, backend_name: str) -> Dict[str, Any]:
"""Return the configuration of the backend.

Args:
backend_name: The name of the backend.

Returns:
Backends available for this hub/group/project.
Backend configuration.
"""
return self.account_api.backends()
return self.account_api.backend(backend_name).configuration()

def backend_status(self, backend_name: str) -> Dict[str, Any]:
"""Return the status of the backend.
Expand Down
8 changes: 5 additions & 3 deletions qiskit_ibm_runtime/api/clients/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def user_urls(self) -> Dict[str, str]:
response = self.auth_api.user_info()
return response["urls"]

def user_hubs(self) -> List[Dict[str, str]]:
def user_hubs(self) -> List[Dict[str, Any]]:
"""Retrieve the hub/group/project sets available to the user.

The first entry in the list will be the default set, as indicated by
Expand All @@ -130,7 +130,6 @@ def user_hubs(self) -> List[Dict[str, str]]:
``hub``, ``group``, and ``project``, respectively.
"""
response = self.base_api.hubs()

hubs = [] # type: ignore[var-annotated]
for hub in response:
hub_name = hub["name"]
Expand All @@ -140,8 +139,11 @@ def user_hubs(self) -> List[Dict[str, str]]:
"hub": hub_name,
"group": group_name,
"project": project_name,
"backend_names": [
backend.get("name")
for backend in project["devices"].values()
],
}

# Move to the top if it is the default h/g/p.
if project.get("isDefault"):
hubs.insert(0, entry)
Expand Down
17 changes: 0 additions & 17 deletions qiskit_ibm_runtime/api/rest/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""Account REST adapter."""

import logging
from typing import Dict, Optional, Any, List

from .base import RestAdapterBase
from .backend import Backend
Expand All @@ -25,8 +24,6 @@
class Account(RestAdapterBase):
"""Rest adapter for hub/group/project related endpoints."""

URL_MAP = {"backends": "/devices/v/1"}

TEMPLATE_IBM_HUBS = "/Network/{hub}/Groups/{group}/Projects/{project}"
"""str: Template for creating an IBM Quantum URL with
hub/group/project information."""
Expand Down Expand Up @@ -59,17 +56,3 @@ def backend(self, backend_name: str) -> Backend:
The backend adapter.
"""
return Backend(self.session, backend_name, self.url_prefix)

# Client functions.

def backends(self, timeout: Optional[float] = None) -> List[Dict[str, Any]]:
"""Return a list of backends.

Args:
timeout: Number of seconds to wait for the request.

Returns:
JSON response.
"""
url = self.get_url("backends")
return self.session.get(url, timeout=timeout).json()
10 changes: 10 additions & 0 deletions qiskit_ibm_runtime/api/rest/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Backend(RestAdapterBase):
"""Rest adapter for backend related endpoints."""

URL_MAP = {
"configuration": "/fullConfiguration",
"properties": "/properties",
"pulse_defaults": "/defaults",
"status": "/queue/status",
Expand All @@ -45,6 +46,15 @@ def __init__(
self.backend_name = backend_name
super().__init__(session, "{}/devices/{}".format(url_prefix, backend_name))

def configuration(self) -> Dict[str, Any]:
"""Return backend configuration.

Returns:
JSON response of backend configuration.
"""
url = self.get_url("configuration")
return self.session.get(url).json()

def properties(self, datetime: Optional[datetime] = None) -> Dict[str, Any]:
"""Return backend properties.

Expand Down
10 changes: 7 additions & 3 deletions qiskit_ibm_runtime/hub_group_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import logging
from collections import OrderedDict
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

from qiskit_ibm_runtime import ( # pylint: disable=unused-import
ibm_backend,
Expand All @@ -35,6 +35,7 @@ def __init__(
self,
client_params: ClientParameters,
instance: str,
backend_names: List[str],
) -> None:
"""HubGroupProject constructor

Expand All @@ -43,6 +44,7 @@ def __init__(
instance: Hub/group/project.
"""
self._api_client = AccountClient(client_params)
self._backend_names = backend_names
# Initialize the internal list of backends.
self._backends: Dict[str, "ibm_backend.IBMBackend"] = {}
self._hub, self._group, self._project = from_instance_format(instance)
Expand Down Expand Up @@ -74,8 +76,10 @@ def _discover_remote_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
A dict of the remote backend instances, keyed by backend name.
"""
ret = OrderedDict()
configs_list = self._api_client.list_backends()
for raw_config in configs_list:
for backend_name in self._backend_names:
raw_config = self._api_client.backend_configuration(
backend_name=backend_name
)
config = configuration_from_server_data(
raw_config=raw_config, instance=self.name
)
Expand Down
6 changes: 4 additions & 2 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,13 @@ def _initialize_hgps(
proxies=self._account.proxies,
verify=self._account.verify,
)

backend_names = hub_info["backend_names"]
# Build the hgp.
try:
hgp = HubGroupProject(
client_params=hgp_params, instance=hgp_params.instance
client_params=hgp_params,
instance=hgp_params.instance,
backend_names=backend_names,
)
hgps[hgp.name] = hgp
except Exception: # pylint: disable=broad-except
Expand Down
16 changes: 9 additions & 7 deletions test/unit/mock/fake_account_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ def __init__(
config["backend_name"] = f"backend{idx}"
self._backends.append(FakeApiBackend(config, status))

def list_backends(self) -> List[Dict[str, Any]]:
"""Return backends available for this provider."""
# pylint: disable=unused-argument
return [back.configuration.copy() for back in self._backends]
def backend_configuration(self, backend_name: str) -> Dict[str, Any]:
"""Return the configuration of the backend."""
for backend in self._backends:
if backend.name == backend_name:
return backend.configuration.copy()
raise ValueError(f"Backend {backend_name} not found")

def backend_status(self, backend_name: str) -> Dict[str, Any]:
"""Return the status of the backend."""
for back in self._backends:
if back.name == backend_name:
return back.status.copy()
for backend in self._backends:
if backend.name == backend_name:
return backend.status.copy()
raise ValueError(f"Backend {backend_name} not found")

def backend_properties(
Expand Down
9 changes: 4 additions & 5 deletions test/unit/mock/fake_runtime_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,10 @@ def list_backends(self):
@cloud_only
def backend_configuration(self, backend_name: str) -> Dict[str, Any]:
"""Return the configuration of the IBM Cloud backend."""
configs = self._backend_client.list_backends()
for conf in configs:
if conf["backend_name"] == backend_name:
return conf
raise ValueError(f"Backend {backend_name} not found.")
config = self._backend_client.backend_configuration(backend_name)
if not config:
raise ValueError(f"Backend {backend_name} not found.")
return config

@cloud_only
def backend_status(self, backend_name: str) -> Dict[str, Any]:
Expand Down
18 changes: 11 additions & 7 deletions test/unit/mock/fake_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ def _initialize_hgps(
url="some_url",
instance=hgp_name,
)
hgp = HubGroupProject(client_params=hgp_params, instance=hgp_name)
unique_backend = self.DEFAULT_UNIQUE_BACKEND_PREFIX + str(idx)
fake_account_client = self._fake_account_client
if not fake_account_client:
backend_names = [self.DEFAULT_COMMON_BACKEND, unique_backend]
else:
backend_names = [
backend.name for backend in fake_account_client._backends
]
hgp = HubGroupProject(
client_params=hgp_params, instance=hgp_name, backend_names=backend_names
)
if not fake_account_client:
specs = [
{"configuration": {"backend_name": self.DEFAULT_COMMON_BACKEND}},
{
"configuration": {
"backend_name": self.DEFAULT_UNIQUE_BACKEND_PREFIX
+ str(idx)
}
},
{"configuration": {"backend_name": unique_backend}},
]
fake_account_client = BaseFakeAccountClient(specs=specs, hgp=hgp_name)
hgp._api_client = fake_account_client
Expand Down