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

Add channel strategy instance validation #1193

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions qiskit_ibm_runtime/api/clients/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ def list_backends(
"""
return self._api.backends(hgp=hgp, channel_strategy=channel_strategy)["devices"]

def cloud_instance(self) -> bool:
"""Returns a boolean of whether or not the instance has q-ctrl enabled.

Returns:
Boolean value.
"""
return self._api.cloud_instance()

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

Expand Down
10 changes: 10 additions & 0 deletions qiskit_ibm_runtime/api/rest/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Runtime(RestAdapterBase):
"programs": "/programs",
"jobs": "/jobs",
"backends": "/backends",
"cloud_instance": "/instance",
}

def program(self, program_id: str) -> "Program":
Expand Down Expand Up @@ -293,3 +294,12 @@ def backends(
if channel_strategy:
params["channel_strategy"] = channel_strategy
return self.session.get(url, params=params, timeout=timeout).json()

def cloud_instance(self) -> bool:
"""Return boolean of whether or not the instance has q-ctrl enabled.

Returns:
Boolean value.
"""
url = self.get_url("cloud_instance")
return self.session.get(url).json().get("qctrl_enabled")
13 changes: 13 additions & 0 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def __init__(
# TODO: We can make the backend discovery lazy
self._backends = self._discover_cloud_backends()
QiskitRuntimeService.global_service = self
self._validate_channel_strategy()
return
else:
auth_client = self._authenticate_ibm_quantum_account(self._client_params)
Expand Down Expand Up @@ -308,6 +309,18 @@ def _discover_account(

return account

def _validate_channel_strategy(self) -> None:
"""Raise an error if the passed in channel_strategy and
instance do not match.

"""
if self._channel_strategy == "q-ctrl":
qctrl_enabled = self._api_client.cloud_instance()
if not qctrl_enabled:
raise IBMNotAuthorizedError(
"This account is not authorized to use ``q-ctrl`` as a channel strategy."
)

def _discover_cloud_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
"""Return the remote backends available for this service instance.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
An error will be raised during initialization if ``q-ctrl`` is passsed in as the ``channel_strategy`` and
the account instance does not have ``q-ctrl`` enabled.
kt474 marked this conversation as resolved.
Show resolved Hide resolved
Loading