Skip to content

Commit

Permalink
Instance & channel_strategy validation (#1233)
Browse files Browse the repository at this point in the history
* compare cloud instance with channel strategy

* fix unit tests

* error wording

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
  • Loading branch information
kt474 and jyu00 authored Nov 28, 2023
1 parent 0902c98 commit fb8732d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions qiskit_ibm_runtime/api/clients/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ def list_backends(
"""
return self._api.backends(hgp=hgp, channel_strategy=channel_strategy)["devices"]

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

def backend_configuration(self, backend_name: str) -> Dict[str, Any]:
"""Return the configuration of the IBM backend.
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/api/rest/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def backends(
params["channel_strategy"] = channel_strategy
return self.session.get(url, params=params, timeout=timeout).json()

def cloud_instance(self) -> bool:
def is_qctrl_enabled(self) -> bool:
"""Return boolean of whether or not the instance has q-ctrl enabled.
Returns:
Expand Down
14 changes: 12 additions & 2 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,21 @@ def _validate_channel_strategy(self) -> None:
instance do not match.
"""
qctrl_enabled = self._api_client.is_qctrl_enabled()
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."
"The instance passed in is not compatible with Q-CTRL channel strategy. "
"Please switch to or create an instance with the Q-CTRL strategy enabled. "
"See https://cloud.ibm.com/docs/quantum-computing?"
"topic=quantum-computing-get-started for more information"
)
else:
if qctrl_enabled:
raise IBMNotAuthorizedError(
"The instance passed in is only compatible with Q-CTRL performance "
"management strategy. "
"To use this instance, set channel_strategy='q-ctrl'."
)

def _discover_cloud_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
If a cloud instance that is `q-ctrl` enabled is used while `q-ctrl` is not
passed in as the `channel_strategy`, an error will be raised.
4 changes: 4 additions & 0 deletions test/unit/mock/fake_runtime_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def set_job_classes(self, classes):
classes = [classes]
self._job_classes = classes

def is_qctrl_enabled(self):
"""Return whether or not channel_strategy q-ctrl is enabled."""
return False

def set_final_status(self, final_status):
"""Set job status to passed in final status instantly."""
self._final_status = final_status
Expand Down

0 comments on commit fb8732d

Please sign in to comment.