-
Notifications
You must be signed in to change notification settings - Fork 154
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
Allow users to indicate they are done submitting jobs to a session #1123
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6ba330a
add session details method
kt474 7dd590e
add reno
kt474 1c709b8
support iqp urls
kt474 6424ec4
update details mehotd, add status()
kt474 c2ed968
update status() to use enum
kt474 ee14666
testing accepting_jobs flag
kt474 02d5c46
Merge branch 'main' into session-accepting-jobs
kt474 f1121ba
testing accepting_jobs flag
kt474 4115177
clean up branch
kt474 1529d35
update close() & cancel()
kt474 71b6eae
close session on exit
kt474 d8a984c
add reno
kt474 1b15474
update unit tests
kt474 6b8c99d
testing integration tests in ci
kt474 89c38fa
undo previous commit
kt474 d3eda08
update docs & docstrings
kt474 fd55b3c
revert commit
kt474 857e501
fix spelling
kt474 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 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 .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 cancel(self) -> None: | ||
"""Cancel all jobs in the session.""" | ||
url = self.get_url("close") | ||
self.session.delete(url) | ||
|
||
def close(self) -> None: | ||
"""Set accepting_jobs flag to false, so no more jobs can be submitted.""" | ||
payload = {"accepting_jobs": False} | ||
url = self.get_url("self") | ||
self.session.patch(url, json=payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
releasenotes/notes/sessions-accepting-jobs-d77e3bba150a20f5.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
upgrade: | ||
- | | ||
:meth:`qiskit_ibm_runtime.Session.close` has been updated to mark a ``Session`` as no longer | ||
accepting new jobs. The session won't accept more jobs but it will continue to run any | ||
queued jobs until they are done or the max time expires. This will also happen | ||
automatically when the session context manager is exited. When a session that is not accepting | ||
jobs has run out of jobs to run, it's immediately closed, freeing up the backend to run more jobs rather | ||
than wait for the interactive timeout. | ||
|
||
The old close method behaviour has been moved to a new method, | ||
:meth:`qiskit_ibm_runtime.Session.cancel`, where all jobs within a session are | ||
cancelled and terminated. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beckykd should docs updates be in a separate PR? I'll probably need help with the wording on a lot of these - it will also be a bit tricky since once this is released, older versions of
qiskit-ibm-runtime
will behave differently