Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only return channel strategy supported backends #1095

Merged
merged 4 commits into from
Sep 21, 2023
Merged
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
10 changes: 8 additions & 2 deletions qiskit_ibm_runtime/api/clients/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,19 @@ def close_session(self, session_id: str) -> None:
"""
self._api.runtime_session(session_id=session_id).close()

def list_backends(self, hgp: Optional[str] = None) -> List[str]:
def list_backends(
self, hgp: Optional[str] = None, channel_strategy: Optional[str] = None
) -> List[str]:
"""Return IBM backends available for this service instance.

Args:
hgp: Filter by hub/group/project.
channel_strategy: Filter by channel strategy.

Returns:
IBM backends available for this service instance.
"""
return self._api.backends(hgp=hgp)["devices"]
return self._api.backends(hgp=hgp, channel_strategy=channel_strategy)["devices"]

def backend_configuration(self, backend_name: str) -> Dict[str, Any]:
"""Return the configuration of the IBM backend.
Expand Down
14 changes: 11 additions & 3 deletions qiskit_ibm_runtime/api/rest/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,25 @@ def backend(self, backend_name: str) -> CloudBackend:
return CloudBackend(self.session, backend_name)

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

Args:
hgp: The service instance to use, only for ``ibm_quantum`` channel, in h/g/p format.
timeout: Number of seconds to wait for the request.
channel_strategy: Error mitigation strategy.

Returns:
JSON response.
"""
url = self.get_url("backends")
params = {}
if hgp:
return self.session.get(url, params={"provider": hgp}).json()
return self.session.get(url, timeout=timeout).json()
params["provider"] = hgp
if channel_strategy:
params["channel_strategy"] = channel_strategy
return self.session.get(url, params=params, timeout=timeout).json()
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _discover_cloud_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
A dict of the remote backend instances, keyed by backend name.
"""
ret = OrderedDict() # type: ignore[var-annotated]
backends_list = self._api_client.list_backends()
backends_list = self._api_client.list_backends(channel_strategy=self._channel_strategy)
for backend_name in backends_list:
raw_config = self._api_client.backend_configuration(backend_name=backend_name)
config = configuration_from_server_data(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
If using a ``channel_strategy``, only backends that support that ``channel_strategy``
will be accessible to the user.

5 changes: 4 additions & 1 deletion test/unit/mock/fake_runtime_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ def _get_job(self, job_id: str, exclude_params: bool = None) -> Any:
raise RequestsApiError("Job not found", status_code=404)
return self._jobs[job_id]

def list_backends(self, hgp: Optional[str] = None) -> List[str]:
# pylint: disable=unused-argument
def list_backends(
self, hgp: Optional[str] = None, channel_strategy: Optional[str] = None
) -> List[str]:
"""Return IBM backends available for this service instance."""
return [back.name for back in self._backends if back.has_access(hgp)]

Expand Down
Loading