From 6ba330a8124330a43bcc05ba3bea6829d5098a97 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Sat, 30 Sep 2023 17:30:25 -0400 Subject: [PATCH 01/18] add session details method --- qiskit_ibm_runtime/api/clients/runtime.py | 11 +++++ qiskit_ibm_runtime/api/rest/runtime.py | 2 +- .../api/rest/runtime_session.py | 45 +++++++++++++++++++ qiskit_ibm_runtime/session.py | 8 +++- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 qiskit_ibm_runtime/api/rest/runtime_session.py diff --git a/qiskit_ibm_runtime/api/clients/runtime.py b/qiskit_ibm_runtime/api/clients/runtime.py index 4b3fa51c4..23761e10b 100644 --- a/qiskit_ibm_runtime/api/clients/runtime.py +++ b/qiskit_ibm_runtime/api/clients/runtime.py @@ -345,6 +345,17 @@ def close_session(self, session_id: str) -> None: """ self._api.runtime_session(session_id=session_id).close() + def session_details(self, session_id: str) -> Dict[str, Any]: + """Get session details. + + Args: + session_id: Session ID. + + Returns: + Session details. + """ + return self._api.runtime_session(session_id=session_id).details() + def list_backends( self, hgp: Optional[str] = None, channel_strategy: Optional[str] = None ) -> List[str]: diff --git a/qiskit_ibm_runtime/api/rest/runtime.py b/qiskit_ibm_runtime/api/rest/runtime.py index a21c7a3e9..e9e683c65 100644 --- a/qiskit_ibm_runtime/api/rest/runtime.py +++ b/qiskit_ibm_runtime/api/rest/runtime.py @@ -19,9 +19,9 @@ from qiskit_ibm_provider.api.rest.base import RestAdapterBase from qiskit_ibm_provider.api.rest.program_job import ProgramJob -from qiskit_ibm_provider.api.rest.runtime_session import RuntimeSession from qiskit_ibm_provider.utils import local_to_utc +from .runtime_session import RuntimeSession from .program import Program from ...utils import RuntimeEncoder from .cloud_backend import CloudBackend diff --git a/qiskit_ibm_runtime/api/rest/runtime_session.py b/qiskit_ibm_runtime/api/rest/runtime_session.py new file mode 100644 index 000000000..efa33feee --- /dev/null +++ b/qiskit_ibm_runtime/api/rest/runtime_session.py @@ -0,0 +1,45 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Runtime Session REST adapter.""" + +from typing import Dict, Any +from qiskit_ibm_provider.api.rest.base import RestAdapterBase +from ..session import RetrySession + + +class RuntimeSession(RestAdapterBase): + """Rest adapter for session related endpoints.""" + + URL_MAP = { + "self": "", + "close": "/close", + } + + def __init__(self, session: RetrySession, session_id: str, url_prefix: str = "") -> None: + """Job constructor. + + Args: + session: RetrySession to be used in the adapter. + session_id: Job ID of the first job in a runtime session. + url_prefix: Prefix to use in the URL. + """ + super().__init__(session, "{}/sessions/{}".format(url_prefix, session_id)) + + def close(self) -> None: + """Close this session.""" + url = self.get_url("close") + self.session.delete(url) + + def details(self) -> Dict[str, Any]: + """Return the details of this session.""" + return self.session.get(self.get_url("self")).json() diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 13f3a2bd9..52a62b731 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -12,7 +12,7 @@ """Qiskit Runtime flexible session.""" -from typing import Dict, Optional, Type, Union, Callable +from typing import Dict, Optional, Type, Union, Callable, Any from types import TracebackType from functools import wraps from contextvars import ContextVar @@ -193,6 +193,12 @@ def backend(self) -> Optional[str]: """ return self._backend + def details(self) -> Optional[Dict[str, Any]]: + """Return session details.""" + if self._session_id: + return self._service._api_client.session_details(self._session_id) + return None + @property def session_id(self) -> str: """Return the session ID. From 7dd590e238b2791da8b61333467c603e4ccf75c3 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Sat, 30 Sep 2023 18:12:08 -0400 Subject: [PATCH 02/18] add reno --- qiskit_ibm_runtime/api/rest/runtime_session.py | 6 +++++- .../notes/expose-session-details-c4a44316d30dad33.yaml | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml diff --git a/qiskit_ibm_runtime/api/rest/runtime_session.py b/qiskit_ibm_runtime/api/rest/runtime_session.py index efa33feee..4367a4767 100644 --- a/qiskit_ibm_runtime/api/rest/runtime_session.py +++ b/qiskit_ibm_runtime/api/rest/runtime_session.py @@ -42,4 +42,8 @@ def close(self) -> None: def details(self) -> Dict[str, Any]: """Return the details of this session.""" - return self.session.get(self.get_url("self")).json() + try: + return self.session.get(self.get_url("self")).json() + # return None if API is not supported + except: # pylint: disable=bare-except + return None diff --git a/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml b/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml new file mode 100644 index 000000000..3e3af7cec --- /dev/null +++ b/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Added a new method, :meth:`~qiskit_ibm_runtime.Session.details` that returns information + about a session, including: maximum session time, active time remaining, the current state, + and whether or not the session is accepting jobs. + From 1c709b838a68ac8a619d92166a70faa1b4cab928 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Sun, 1 Oct 2023 12:49:00 -0400 Subject: [PATCH 03/18] support iqp urls --- qiskit_ibm_runtime/api/rest/base.py | 57 +++++++++++++++++++ .../api/rest/runtime_session.py | 8 ++- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 qiskit_ibm_runtime/api/rest/base.py diff --git a/qiskit_ibm_runtime/api/rest/base.py b/qiskit_ibm_runtime/api/rest/base.py new file mode 100644 index 000000000..04e8ab0e6 --- /dev/null +++ b/qiskit_ibm_runtime/api/rest/base.py @@ -0,0 +1,57 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2021. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Base REST adapter.""" + +from ..session import RetrySession + + +class RestAdapterBase: + """Base class for REST adapters.""" + + URL_MAP = {} # type: ignore[var-annotated] + """Mapping between the internal name of an endpoint and the actual URL.""" + + _HEADER_JSON_CONTENT = {"Content-Type": "application/json"} + + def __init__(self, session: RetrySession, prefix_url: str = "") -> None: + """RestAdapterBase constructor. + + Args: + session: Session to be used in the adapter. + prefix_url: String to be prepend to all URLs. + """ + self.session = session + self.prefix_url = prefix_url + + def get_url(self, identifier: str) -> str: + """Return the resolved URL for the specified identifier. + + Args: + identifier: Internal identifier of the endpoint. + + Returns: + The resolved URL of the endpoint (relative to the session base URL). + """ + return "{}{}".format(self.prefix_url, self.URL_MAP[identifier]) + + def get_prefixed_url(self, prefix: str, identifier: str) -> str: + """Return an adjusted URL for the specified identifier. + + Args: + prefix: string to be prepended to the URL. + identifier: Internal identifier of the endpoint. + + Returns: + The resolved facade URL of the endpoint. + """ + return "{}{}{}".format(prefix, self.prefix_url, self.URL_MAP[identifier]) diff --git a/qiskit_ibm_runtime/api/rest/runtime_session.py b/qiskit_ibm_runtime/api/rest/runtime_session.py index 4367a4767..0bad8066e 100644 --- a/qiskit_ibm_runtime/api/rest/runtime_session.py +++ b/qiskit_ibm_runtime/api/rest/runtime_session.py @@ -13,7 +13,7 @@ """Runtime Session REST adapter.""" from typing import Dict, Any -from qiskit_ibm_provider.api.rest.base import RestAdapterBase +from .base import RestAdapterBase from ..session import RetrySession @@ -43,7 +43,11 @@ def close(self) -> None: def details(self) -> Dict[str, Any]: """Return the details of this session.""" try: - return self.session.get(self.get_url("self")).json() + if "cloud" in self.session.base_url: + return self.session.get(self.get_url("self")).json() + else: + # TODO: remove this once "v2" is removed from the url path + return self.session.get(self.get_prefixed_url("/v2", "self")).json() # return None if API is not supported except: # pylint: disable=bare-except return None From 6424ec4346e238604240ad6913bf56089d5e3e27 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 2 Oct 2023 15:20:33 -0400 Subject: [PATCH 04/18] update details mehotd, add status() --- qiskit_ibm_runtime/session.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 52a62b731..a3332015f 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -193,10 +193,40 @@ def backend(self) -> Optional[str]: """ return self._backend + def status(self) -> Optional[str]: + """Return current session status.""" + # TODO Check/match statuses with IQP, return enum + details = self.details() + if details: + return ( + f"Current status: {details['state']}, accepting jobs: {details['accepting_jobs']}" + ) + return None + def details(self) -> Optional[Dict[str, Any]]: """Return session details.""" if self._session_id: - return self._service._api_client.session_details(self._session_id) + response = self._service._api_client.session_details(self._session_id) + if response: + return { + "id": response.get("id"), + "backend_name": response.get("backend_name") or response.get("backend"), + "interactive_timeout": response.get("interactive_ttl") + or response.get("interactiveSessionTTL"), + "max_time": response.get("max_ttl") or response.get("maxSessionTTL"), + "active_ttl": response.get("active_ttl") or response.get("activeTTL"), + "state": response.get("state"), + "accepting_jobs": response.get("accepting_jobs") + or response.get("acceptingJobs"), + # Note the following fields are only returned in the quantum channel + "root_job": response.get("rootJob"), + "root_job_started": response.get("rootJobStarted"), + "last_job": response.get("lastJob"), + "last_job_started": response.get("lastJobStarted"), + "last_job_completed": response.get("lastJobCompleted"), + "activated_at": response.get("activatedAt"), + "closed_at": response.get("closedAt"), + } return None @property From c2ed9681d76f7eff1b6156cdeb0322f7e8059dbd Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 2 Oct 2023 17:40:47 -0400 Subject: [PATCH 05/18] update status() to use enum --- qiskit_ibm_runtime/session.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index a3332015f..eaee25186 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -16,6 +16,7 @@ from types import TracebackType from functools import wraps from contextvars import ContextVar +from enum import Enum from qiskit_ibm_provider.utils.converters import hms_to_seconds @@ -38,6 +39,17 @@ def _wrapper(self, *args, **kwargs): # type: ignore return _wrapper +class SessionStatus(Enum): + """Session status.""" + + OPEN = "Session is open, no jobs have been dequeued." + ACTIVE = "Session is active, jobs are being dequeued." + INACTIVE = ( + "Session is inactive, the interactive_timeout expired before more jobs were available." + ) + CLOSED = "Session is closed, the max_time expired or the session was explicitly closed." + + class Session: """Class for creating a flexible Qiskit Runtime session. @@ -195,12 +207,13 @@ def backend(self) -> Optional[str]: def status(self) -> Optional[str]: """Return current session status.""" - # TODO Check/match statuses with IQP, return enum details = self.details() if details: - return ( - f"Current status: {details['state']}, accepting jobs: {details['accepting_jobs']}" + status = ( + f"{SessionStatus[details['state'].upper()].value} " + f"Session is {'not' if not details['accepting_jobs'] else ''}accepting jobs." ) + return status return None def details(self) -> Optional[Dict[str, Any]]: @@ -214,7 +227,7 @@ def details(self) -> Optional[Dict[str, Any]]: "interactive_timeout": response.get("interactive_ttl") or response.get("interactiveSessionTTL"), "max_time": response.get("max_ttl") or response.get("maxSessionTTL"), - "active_ttl": response.get("active_ttl") or response.get("activeTTL"), + "active_time": response.get("active_ttl") or response.get("activeTTL"), "state": response.get("state"), "accepting_jobs": response.get("accepting_jobs") or response.get("acceptingJobs"), From 896d1ec8c9b9b3f268be3eb4b960d3b8e6d106ce Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 3 Oct 2023 15:19:10 -0400 Subject: [PATCH 06/18] revert previous change, wait for impl details --- qiskit_ibm_runtime/session.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index eaee25186..8795eef24 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -16,7 +16,6 @@ from types import TracebackType from functools import wraps from contextvars import ContextVar -from enum import Enum from qiskit_ibm_provider.utils.converters import hms_to_seconds @@ -39,17 +38,6 @@ def _wrapper(self, *args, **kwargs): # type: ignore return _wrapper -class SessionStatus(Enum): - """Session status.""" - - OPEN = "Session is open, no jobs have been dequeued." - ACTIVE = "Session is active, jobs are being dequeued." - INACTIVE = ( - "Session is inactive, the interactive_timeout expired before more jobs were available." - ) - CLOSED = "Session is closed, the max_time expired or the session was explicitly closed." - - class Session: """Class for creating a flexible Qiskit Runtime session. @@ -207,14 +195,8 @@ def backend(self) -> Optional[str]: def status(self) -> Optional[str]: """Return current session status.""" - details = self.details() - if details: - status = ( - f"{SessionStatus[details['state'].upper()].value} " - f"Session is {'not' if not details['accepting_jobs'] else ''}accepting jobs." - ) - return status - return None + # TODO implement this when API changes are done + pass def details(self) -> Optional[Dict[str, Any]]: """Return session details.""" @@ -227,18 +209,19 @@ def details(self) -> Optional[Dict[str, Any]]: "interactive_timeout": response.get("interactive_ttl") or response.get("interactiveSessionTTL"), "max_time": response.get("max_ttl") or response.get("maxSessionTTL"), - "active_time": response.get("active_ttl") or response.get("activeTTL"), + "active_ttl": response.get("active_ttl") or response.get("activeTTL"), "state": response.get("state"), "accepting_jobs": response.get("accepting_jobs") or response.get("acceptingJobs"), - # Note the following fields are only returned in the quantum channel "root_job": response.get("rootJob"), "root_job_started": response.get("rootJobStarted"), "last_job": response.get("lastJob"), - "last_job_started": response.get("lastJobStarted"), - "last_job_completed": response.get("lastJobCompleted"), - "activated_at": response.get("activatedAt"), - "closed_at": response.get("closedAt"), + "last_job_started": response.get("lastJobStarted") + or response.get("last_job_started"), + "last_job_completed": response.get("lastJobCompleted") + or response.get("last_job_completed"), + "activated_at": response.get("activatedAt") or response.get("started_at"), + "closed_at": response.get("closedAt") or response.get("closed_at"), } return None From 3341493b136d8e14a7d8239a33fe7f34de00b553 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 9 Oct 2023 15:40:21 -0400 Subject: [PATCH 07/18] update fields returned --- .../api/rest/runtime_session.py | 6 +---- qiskit_ibm_runtime/session.py | 25 +++++++------------ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/qiskit_ibm_runtime/api/rest/runtime_session.py b/qiskit_ibm_runtime/api/rest/runtime_session.py index 0bad8066e..f4e3ec7ce 100644 --- a/qiskit_ibm_runtime/api/rest/runtime_session.py +++ b/qiskit_ibm_runtime/api/rest/runtime_session.py @@ -43,11 +43,7 @@ def close(self) -> None: def details(self) -> Dict[str, Any]: """Return the details of this session.""" try: - if "cloud" in self.session.base_url: - return self.session.get(self.get_url("self")).json() - else: - # TODO: remove this once "v2" is removed from the url path - return self.session.get(self.get_prefixed_url("/v2", "self")).json() + return self.session.get(self.get_url("self")).json() # return None if API is not supported except: # pylint: disable=bare-except return None diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 841ff69ad..1e1a90329 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -205,23 +205,16 @@ def details(self) -> Optional[Dict[str, Any]]: if response: return { "id": response.get("id"), - "backend_name": response.get("backend_name") or response.get("backend"), - "interactive_timeout": response.get("interactive_ttl") - or response.get("interactiveSessionTTL"), - "max_time": response.get("max_ttl") or response.get("maxSessionTTL"), - "active_ttl": response.get("active_ttl") or response.get("activeTTL"), + "backend_name": response.get("backend_name"), + "interactive_timeout": response.get("interactive_ttl"), + "max_time": response.get("max_ttl"), + "active_ttl": response.get("active_ttl"), "state": response.get("state"), - "accepting_jobs": response.get("accepting_jobs") - or response.get("acceptingJobs"), - "root_job": response.get("rootJob"), - "root_job_started": response.get("rootJobStarted"), - "last_job": response.get("lastJob"), - "last_job_started": response.get("lastJobStarted") - or response.get("last_job_started"), - "last_job_completed": response.get("lastJobCompleted") - or response.get("last_job_completed"), - "activated_at": response.get("activatedAt") or response.get("started_at"), - "closed_at": response.get("closedAt") or response.get("closed_at"), + "accepting_jobs": response.get("accepting_jobs"), + "last_job_started": response.get("last_job_started"), + "last_job_completed": response.get("last_job_completed"), + "started_at": response.get("started_at"), + "closed_at": response.get("closed_at"), } return None From fbe960bb68ed72884c710325398ceca7858043e3 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 9 Oct 2023 19:55:37 -0400 Subject: [PATCH 08/18] update status method --- qiskit_ibm_runtime/session.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 1e1a90329..4a9102717 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -195,8 +195,19 @@ def backend(self) -> Optional[str]: def status(self) -> Optional[str]: """Return current session status.""" - # TODO implement this when API changes are done - pass + details = self.details() + if details: + state = details["state"] + accepting_jobs = details["accepting_jobs"] + if state == "open": + return "Pending" + if state == "active" and accepting_jobs: + return "In progress, accepting new jobs" + if state == "active" and not accepting_jobs: + return "In progress, not accepting new jobs" + return state.capitalize() + + return None def details(self) -> Optional[Dict[str, Any]]: """Return session details.""" @@ -208,7 +219,7 @@ def details(self) -> Optional[Dict[str, Any]]: "backend_name": response.get("backend_name"), "interactive_timeout": response.get("interactive_ttl"), "max_time": response.get("max_ttl"), - "active_ttl": response.get("active_ttl"), + "active_timeout": response.get("active_ttl"), "state": response.get("state"), "accepting_jobs": response.get("accepting_jobs"), "last_job_started": response.get("last_job_started"), From d114e15ba68f1e8949faaaf553db87edf5096b86 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 9 Oct 2023 20:00:59 -0400 Subject: [PATCH 09/18] update docstring & reno --- qiskit_ibm_runtime/session.py | 12 ++++++++++-- .../expose-session-details-c4a44316d30dad33.yaml | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 4a9102717..485fa636e 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -194,7 +194,11 @@ def backend(self) -> Optional[str]: return self._backend def status(self) -> Optional[str]: - """Return current session status.""" + """Return current session status. + + Returns: + A string describing the current status of the session. + """ details = self.details() if details: state = details["state"] @@ -210,7 +214,11 @@ def status(self) -> Optional[str]: return None def details(self) -> Optional[Dict[str, Any]]: - """Return session details.""" + """Return session details. + + Returns: + A dictionary with information about the session. + """ if self._session_id: response = self._service._api_client.session_details(self._session_id) if response: diff --git a/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml b/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml index 3e3af7cec..6e525c509 100644 --- a/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml +++ b/releasenotes/notes/expose-session-details-c4a44316d30dad33.yaml @@ -5,3 +5,6 @@ features: about a session, including: maximum session time, active time remaining, the current state, and whether or not the session is accepting jobs. + Also added :meth:`~qiskit_ibm_runtime.Session.status`, which returns the current status of + the session. + From 5cbdd16519cae64278adf5e5249f789891362495 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 15:28:32 -0400 Subject: [PATCH 10/18] update docstrings for both methods --- qiskit_ibm_runtime/session.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 485fa636e..a713a31a6 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -197,13 +197,19 @@ def status(self) -> Optional[str]: """Return current session status. Returns: - A string describing the current status of the session. + The current status of the session, including: + Pending: Session is created but no jobs have been dequeued, or + the ``interactive_timeout`` expired before more jobs were available + In progress, accepting new jobs: session is active and accepting new jobs + In progress, not accepting new jobs: session is active and not accepting new jobs + Closed: ``max_time`` expired or session was explicitly closed + None: status details are not available """ details = self.details() if details: state = details["state"] accepting_jobs = details["accepting_jobs"] - if state == "open": + if state in ["open", "inactive"]: return "Pending" if state == "active" and accepting_jobs: return "In progress, accepting new jobs" @@ -217,7 +223,21 @@ def details(self) -> Optional[Dict[str, Any]]: """Return session details. Returns: - A dictionary with information about the session. + A dictionary with session details, including: + id: id of the session + backned_name: backend used for the session + interactive_timeout: The max time (in seconds) between jobs that + is allowed to occur to keep the session active + max_time: Max allowed time for the session to run in seconds, subject to plan limits + active_timeout: The remaining time (in seconds) for the session to + be in the active state whilst jobs are running + state: State of the session - open, active, inactive, or closed + accepting_jobs: Whether or not the session is accepting jobs + last_job_started: Timestamp of when the last job in the session started + last_job_completed: Timestamp of when the last job in the session completed + started_at: Timestamp of when the session was started + closed_at: Timestamp of when the session was closed + """ if self._session_id: response = self._service._api_client.session_details(self._session_id) From 7d0b75c111cffa43eaea9225b8e892b2df567409 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 15:42:43 -0400 Subject: [PATCH 11/18] fix docs build --- qiskit_ibm_runtime/session.py | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index a713a31a6..a91a3fbfd 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -198,12 +198,12 @@ def status(self) -> Optional[str]: Returns: The current status of the session, including: - Pending: Session is created but no jobs have been dequeued, or - the ``interactive_timeout`` expired before more jobs were available - In progress, accepting new jobs: session is active and accepting new jobs - In progress, not accepting new jobs: session is active and not accepting new jobs - Closed: ``max_time`` expired or session was explicitly closed - None: status details are not available + Pending: Session is created but no jobs have been dequeued, or + the interactive_timeout expired before more jobs were available + In progress, accepting new jobs: session is active and accepting new jobs + In progress, not accepting new jobs: session is active and not accepting new jobs + Closed: max_time expired or session was explicitly closed + None: status details are not available """ details = self.details() if details: @@ -224,19 +224,19 @@ def details(self) -> Optional[Dict[str, Any]]: Returns: A dictionary with session details, including: - id: id of the session - backned_name: backend used for the session - interactive_timeout: The max time (in seconds) between jobs that - is allowed to occur to keep the session active - max_time: Max allowed time for the session to run in seconds, subject to plan limits - active_timeout: The remaining time (in seconds) for the session to - be in the active state whilst jobs are running - state: State of the session - open, active, inactive, or closed - accepting_jobs: Whether or not the session is accepting jobs - last_job_started: Timestamp of when the last job in the session started - last_job_completed: Timestamp of when the last job in the session completed - started_at: Timestamp of when the session was started - closed_at: Timestamp of when the session was closed + id: id of the session + backned_name: backend used for the session + interactive_timeout: The max time (in seconds) between jobs that + is allowed to occur to keep the session active + max_time: Max allowed time for the session to run in seconds, subject to plan limits + active_timeout: The remaining time (in seconds) for the session to + be in the active state whilst jobs are running + state: State of the session - open, active, inactive, or closed + accepting_jobs: Whether or not the session is accepting jobs + last_job_started: Timestamp of when the last job in the session started + last_job_completed: Timestamp of when the last job in the session completed + started_at: Timestamp of when the session was started + closed_at: Timestamp of when the session was closed """ if self._session_id: From 2dff60e4fe15a6cf88bac7ad88d83badb080711c Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 16:26:42 -0400 Subject: [PATCH 12/18] address comments --- qiskit_ibm_runtime/session.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index a91a3fbfd..c0e0787dd 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -198,8 +198,8 @@ def status(self) -> Optional[str]: Returns: The current status of the session, including: - Pending: Session is created but no jobs have been dequeued, or - the interactive_timeout expired before more jobs were available + Pending: Session is created but not active. It will become active when + the next job of this session is dequeued. In progress, accepting new jobs: session is active and accepting new jobs In progress, not accepting new jobs: session is active and not accepting new jobs Closed: max_time expired or session was explicitly closed @@ -226,11 +226,10 @@ def details(self) -> Optional[Dict[str, Any]]: A dictionary with session details, including: id: id of the session backned_name: backend used for the session - interactive_timeout: The max time (in seconds) between jobs that - is allowed to occur to keep the session active - max_time: Max allowed time for the session to run in seconds, subject to plan limits - active_timeout: The remaining time (in seconds) for the session to - be in the active state whilst jobs are running + interactive_timeout: The maximum idle time (in seconds) between jobs that + is allowed to occur before the session is deactivated. + max_time: Maximum allowed time (in seconds) for the session, subject to plan limits + active_timeout: The maximum time (in seconds) a session can stay active. state: State of the session - open, active, inactive, or closed accepting_jobs: Whether or not the session is accepting jobs last_job_started: Timestamp of when the last job in the session started From 64ca88de4a8671282469e035590366b42afb8798 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 16:35:56 -0400 Subject: [PATCH 13/18] fix docs build --- qiskit_ibm_runtime/session.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index c0e0787dd..5a24aa51d 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -200,10 +200,10 @@ def status(self) -> Optional[str]: The current status of the session, including: Pending: Session is created but not active. It will become active when the next job of this session is dequeued. - In progress, accepting new jobs: session is active and accepting new jobs - In progress, not accepting new jobs: session is active and not accepting new jobs - Closed: max_time expired or session was explicitly closed - None: status details are not available + In progress, accepting new jobs: session is active and accepting new jobs. + In progress, not accepting new jobs: session is active and not accepting new jobs. + Closed: max_time expired or session was explicitly closed. + None: status details are not available. """ details = self.details() if details: @@ -224,18 +224,18 @@ def details(self) -> Optional[Dict[str, Any]]: Returns: A dictionary with session details, including: - id: id of the session - backned_name: backend used for the session + id: id of the session. + backned_name: backend used for the session. interactive_timeout: The maximum idle time (in seconds) between jobs that is allowed to occur before the session is deactivated. - max_time: Maximum allowed time (in seconds) for the session, subject to plan limits + max_time: Maximum allowed time (in seconds) for the session, subject to plan limits. active_timeout: The maximum time (in seconds) a session can stay active. - state: State of the session - open, active, inactive, or closed - accepting_jobs: Whether or not the session is accepting jobs - last_job_started: Timestamp of when the last job in the session started - last_job_completed: Timestamp of when the last job in the session completed - started_at: Timestamp of when the session was started - closed_at: Timestamp of when the session was closed + state: State of the session - open, active, inactive, or closed. + accepting_jobs: Whether or not the session is accepting jobs. + last_job_started: Timestamp of when the last job in the session started. + last_job_completed: Timestamp of when the last job in the session completed. + started_at: Timestamp of when the session was started. + closed_at: Timestamp of when the session was closed. """ if self._session_id: From 9080ce6883d4875104ce29ed5ae4421fbcd4a2dc Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 16:49:04 -0400 Subject: [PATCH 14/18] fix typo --- qiskit_ibm_runtime/session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 5a24aa51d..4523ec14c 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -225,7 +225,7 @@ def details(self) -> Optional[Dict[str, Any]]: Returns: A dictionary with session details, including: id: id of the session. - backned_name: backend used for the session. + backend_name: backend used for the session. interactive_timeout: The maximum idle time (in seconds) between jobs that is allowed to occur before the session is deactivated. max_time: Maximum allowed time (in seconds) for the session, subject to plan limits. @@ -236,7 +236,6 @@ def details(self) -> Optional[Dict[str, Any]]: last_job_completed: Timestamp of when the last job in the session completed. started_at: Timestamp of when the session was started. closed_at: Timestamp of when the session was closed. - """ if self._session_id: response = self._service._api_client.session_details(self._session_id) From 2a228dabc754b5627d01442f5cbc45e991dc2439 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 16:57:51 -0400 Subject: [PATCH 15/18] docs build again --- qiskit_ibm_runtime/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 4523ec14c..ca0b941a7 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -197,7 +197,7 @@ def status(self) -> Optional[str]: """Return current session status. Returns: - The current status of the session, including: + The current status of the session, including the following. Pending: Session is created but not active. It will become active when the next job of this session is dequeued. In progress, accepting new jobs: session is active and accepting new jobs. @@ -223,7 +223,7 @@ def details(self) -> Optional[Dict[str, Any]]: """Return session details. Returns: - A dictionary with session details, including: + A dictionary with the following sessions details. id: id of the session. backend_name: backend used for the session. interactive_timeout: The maximum idle time (in seconds) between jobs that From 2f31c3abb88295b0cc4898dc5a65f3901e87dea1 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 17:03:19 -0400 Subject: [PATCH 16/18] fix indent --- qiskit_ibm_runtime/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index ca0b941a7..ed81ce8d3 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -227,7 +227,7 @@ def details(self) -> Optional[Dict[str, Any]]: id: id of the session. backend_name: backend used for the session. interactive_timeout: The maximum idle time (in seconds) between jobs that - is allowed to occur before the session is deactivated. + is allowed to occur before the session is deactivated. max_time: Maximum allowed time (in seconds) for the session, subject to plan limits. active_timeout: The maximum time (in seconds) a session can stay active. state: State of the session - open, active, inactive, or closed. From eca68c195dc1c7efaec5765ebe05c6e662912e8c Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 17:10:17 -0400 Subject: [PATCH 17/18] fix indent again --- qiskit_ibm_runtime/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index ed81ce8d3..8cbd04ab6 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -198,8 +198,8 @@ def status(self) -> Optional[str]: Returns: The current status of the session, including the following. - Pending: Session is created but not active. It will become active when - the next job of this session is dequeued. + Pending: Session is created but not active. + It will become active when the next job of this session is dequeued. In progress, accepting new jobs: session is active and accepting new jobs. In progress, not accepting new jobs: session is active and not accepting new jobs. Closed: max_time expired or session was explicitly closed. From da8ebaf8aa5722b05d90a26af8bdda4b3736b647 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 10 Oct 2023 17:22:48 -0400 Subject: [PATCH 18/18] fix indent 3rd time --- qiskit_ibm_runtime/session.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 8cbd04ab6..348ec707e 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -197,9 +197,9 @@ def status(self) -> Optional[str]: """Return current session status. Returns: - The current status of the session, including the following. + The current status of the session, including: Pending: Session is created but not active. - It will become active when the next job of this session is dequeued. + It will become active when the next job of this session is dequeued. In progress, accepting new jobs: session is active and accepting new jobs. In progress, not accepting new jobs: session is active and not accepting new jobs. Closed: max_time expired or session was explicitly closed. @@ -223,7 +223,7 @@ def details(self) -> Optional[Dict[str, Any]]: """Return session details. Returns: - A dictionary with the following sessions details. + A dictionary with the sessions details, including: id: id of the session. backend_name: backend used for the session. interactive_timeout: The maximum idle time (in seconds) between jobs that