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

Instance & channel_strategy validation #1233

Merged
merged 4 commits into from
Nov 28, 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
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