From 2968e944104b73fa7e6b454d6080df6d7ad974f3 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Thu, 9 Jan 2025 15:19:59 -0500 Subject: [PATCH 1/4] Handle maintenance message --- qiskit_ibm_runtime/qiskit_runtime_service.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/qiskit_ibm_runtime/qiskit_runtime_service.py b/qiskit_ibm_runtime/qiskit_runtime_service.py index b56b622c8..d73d46c93 100644 --- a/qiskit_ibm_runtime/qiskit_runtime_service.py +++ b/qiskit_ibm_runtime/qiskit_runtime_service.py @@ -12,7 +12,6 @@ """Qiskit runtime service.""" -import json import logging import traceback import warnings @@ -161,14 +160,8 @@ def __init__( self._client_params.url = auth_client.current_service_urls()["services"]["runtime"] self._client_params.token = auth_client.current_access_token() self._api_client = RuntimeClient(self._client_params) - try: - self._hgps = self._initialize_hgps(auth_client) - except json.decoder.JSONDecodeError: - raise IBMApiError( - "Unexpected response received from server. " - "Please check if the service is in maintenance mode " - "https://docs.quantum.ibm.com/announcements/service-alerts." - ) + self._hgps = self._initialize_hgps(auth_client) + self._backend_allowed_list = sorted( set(sum([hgp.backends for hgp in self._hgps.values()], [])) ) @@ -275,6 +268,10 @@ def _authenticate_ibm_quantum_account(self, client_params: ClientParameters) -> Authentication client. """ version_info = self._check_api_version(client_params) + + if "ERROR" in version_info and version_info["ERROR"]["name"] == "MAINTENANCE": # type: ignore + raise IBMApiError(version_info["ERROR"]["message"]) # type: ignore + # Check the URL is a valid authentication URL. if not version_info["new_api"] or "api-auth" not in version_info: raise IBMInputValueError( From 7991f297eb379f2093e1e05abe17ac324c5686fd Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 14 Jan 2025 10:13:12 -0500 Subject: [PATCH 2/4] Add release note --- release-notes/unreleased/2100.other.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 release-notes/unreleased/2100.other.rst diff --git a/release-notes/unreleased/2100.other.rst b/release-notes/unreleased/2100.other.rst new file mode 100644 index 000000000..6a3fbc55e --- /dev/null +++ b/release-notes/unreleased/2100.other.rst @@ -0,0 +1,2 @@ +When there is a maintenance outage, an approproate error message will be raised when trying +to initialize the ``QiskitRuntimeService``. \ No newline at end of file From f3472b8b03be687bb0a8e8927d891d8326650149 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Wed, 15 Jan 2025 10:18:17 -0500 Subject: [PATCH 3/4] Error on 521 status --- qiskit_ibm_runtime/api/session.py | 7 ++++++- qiskit_ibm_runtime/qiskit_runtime_service.py | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qiskit_ibm_runtime/api/session.py b/qiskit_ibm_runtime/api/session.py index 953ea4cf6..01db47346 100644 --- a/qiskit_ibm_runtime/api/session.py +++ b/qiskit_ibm_runtime/api/session.py @@ -38,7 +38,6 @@ 503, # Service Unavailable 504, # Gateway Timeout 520, # Cloudflare general error - 521, # Cloudflare web server is down 522, # Cloudflare connection timeout 524, # Cloudflare Timeout ) @@ -348,6 +347,12 @@ def request( # type: ignore[override] message += f". {ex.response.text}" if status_code == 401: raise IBMNotAuthorizedError(message) from ex + if status_code == 521: + raise RequestsApiError( + "Unexpected response received from server. Please check if the service " + "is in maintenance mode " + f"https://docs.quantum.ibm.com/announcements/service-alerts {message}" + ) raise RequestsApiError(message, status_code) from ex return response diff --git a/qiskit_ibm_runtime/qiskit_runtime_service.py b/qiskit_ibm_runtime/qiskit_runtime_service.py index d73d46c93..f0c7d6577 100644 --- a/qiskit_ibm_runtime/qiskit_runtime_service.py +++ b/qiskit_ibm_runtime/qiskit_runtime_service.py @@ -34,7 +34,7 @@ from .api.exceptions import RequestsApiError from .constants import QISKIT_IBM_RUNTIME_API_URL from .exceptions import IBMNotAuthorizedError, IBMInputValueError, IBMAccountError -from .exceptions import IBMRuntimeError, RuntimeProgramNotFound, RuntimeJobNotFound, IBMApiError +from .exceptions import IBMRuntimeError, RuntimeProgramNotFound, RuntimeJobNotFound from .hub_group_project import HubGroupProject # pylint: disable=cyclic-import from .utils.result_decoder import ResultDecoder from .runtime_job import RuntimeJob @@ -269,9 +269,6 @@ def _authenticate_ibm_quantum_account(self, client_params: ClientParameters) -> """ version_info = self._check_api_version(client_params) - if "ERROR" in version_info and version_info["ERROR"]["name"] == "MAINTENANCE": # type: ignore - raise IBMApiError(version_info["ERROR"]["message"]) # type: ignore - # Check the URL is a valid authentication URL. if not version_info["new_api"] or "api-auth" not in version_info: raise IBMInputValueError( From 5f041c1ae5f9172c512b81af3ac673d02b24f101 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Wed, 15 Jan 2025 11:51:19 -0500 Subject: [PATCH 4/4] Switch to 503 status --- qiskit_ibm_runtime/api/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/api/session.py b/qiskit_ibm_runtime/api/session.py index 01db47346..1a66908da 100644 --- a/qiskit_ibm_runtime/api/session.py +++ b/qiskit_ibm_runtime/api/session.py @@ -35,9 +35,9 @@ STATUS_FORCELIST = ( 500, # General server error 502, # Bad Gateway - 503, # Service Unavailable 504, # Gateway Timeout 520, # Cloudflare general error + 521, # Cloudflare web server is down 522, # Cloudflare connection timeout 524, # Cloudflare Timeout ) @@ -347,7 +347,7 @@ def request( # type: ignore[override] message += f". {ex.response.text}" if status_code == 401: raise IBMNotAuthorizedError(message) from ex - if status_code == 521: + if status_code == 503: # Planned maintenance outage raise RequestsApiError( "Unexpected response received from server. Please check if the service " "is in maintenance mode "