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

Handle maintenance message #2100

Merged
merged 6 commits into from
Jan 17, 2025
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
7 changes: 6 additions & 1 deletion qiskit_ibm_runtime/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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
Expand Down Expand Up @@ -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 == 503: # Planned maintenance outage
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
Expand Down
14 changes: 4 additions & 10 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

"""Qiskit runtime service."""

import json
import logging
import traceback
import warnings
Expand All @@ -35,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
Expand Down Expand Up @@ -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)

kt474 marked this conversation as resolved.
Show resolved Hide resolved
self._backend_allowed_list = sorted(
set(sum([hgp.backends for hgp in self._hgps.values()], []))
)
Expand Down Expand Up @@ -275,6 +268,7 @@ def _authenticate_ibm_quantum_account(self, client_params: ClientParameters) ->
Authentication client.
"""
version_info = self._check_api_version(client_params)

# Check the URL is a valid authentication URL.
if not version_info["new_api"] or "api-auth" not in version_info:
raise IBMInputValueError(
Expand Down
2 changes: 2 additions & 0 deletions release-notes/unreleased/2100.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When there is a maintenance outage, an approproate error message will be raised when trying
to initialize the ``QiskitRuntimeService``.
Loading