Skip to content

Commit fb8732d

Browse files
kt474jyu00
andauthored
Instance & channel_strategy validation (#1233)
* compare cloud instance with channel strategy * fix unit tests * error wording --------- Co-authored-by: Jessie Yu <[email protected]>
1 parent 0902c98 commit fb8732d

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

qiskit_ibm_runtime/api/clients/runtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ def list_backends(
268268
"""
269269
return self._api.backends(hgp=hgp, channel_strategy=channel_strategy)["devices"]
270270

271-
def cloud_instance(self) -> bool:
271+
def is_qctrl_enabled(self) -> bool:
272272
"""Returns a boolean of whether or not the instance has q-ctrl enabled.
273273
274274
Returns:
275275
Boolean value.
276276
"""
277-
return self._api.cloud_instance()
277+
return self._api.is_qctrl_enabled()
278278

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

qiskit_ibm_runtime/api/rest/runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def backends(
230230
params["channel_strategy"] = channel_strategy
231231
return self.session.get(url, params=params, timeout=timeout).json()
232232

233-
def cloud_instance(self) -> bool:
233+
def is_qctrl_enabled(self) -> bool:
234234
"""Return boolean of whether or not the instance has q-ctrl enabled.
235235
236236
Returns:

qiskit_ibm_runtime/qiskit_runtime_service.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,21 @@ def _validate_channel_strategy(self) -> None:
317317
instance do not match.
318318
319319
"""
320+
qctrl_enabled = self._api_client.is_qctrl_enabled()
320321
if self._channel_strategy == "q-ctrl":
321-
qctrl_enabled = self._api_client.cloud_instance()
322322
if not qctrl_enabled:
323323
raise IBMNotAuthorizedError(
324-
"This account is not authorized to use ``q-ctrl`` as a channel strategy."
324+
"The instance passed in is not compatible with Q-CTRL channel strategy. "
325+
"Please switch to or create an instance with the Q-CTRL strategy enabled. "
326+
"See https://cloud.ibm.com/docs/quantum-computing?"
327+
"topic=quantum-computing-get-started for more information"
328+
)
329+
else:
330+
if qctrl_enabled:
331+
raise IBMNotAuthorizedError(
332+
"The instance passed in is only compatible with Q-CTRL performance "
333+
"management strategy. "
334+
"To use this instance, set channel_strategy='q-ctrl'."
325335
)
326336

327337
def _discover_cloud_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
If a cloud instance that is `q-ctrl` enabled is used while `q-ctrl` is not
5+
passed in as the `channel_strategy`, an error will be raised.

test/unit/mock/fake_runtime_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ def set_job_classes(self, classes):
285285
classes = [classes]
286286
self._job_classes = classes
287287

288+
def is_qctrl_enabled(self):
289+
"""Return whether or not channel_strategy q-ctrl is enabled."""
290+
return False
291+
288292
def set_final_status(self, final_status):
289293
"""Set job status to passed in final status instantly."""
290294
self._final_status = final_status

0 commit comments

Comments
 (0)