-
Notifications
You must be signed in to change notification settings - Fork 1.1k
StreamManager: retry with get result request on already exist errors #6345
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,6 @@ | |
] | ||
|
||
|
||
class ProgramAlreadyExistsError(Exception): | ||
def __init__(self, program_name: str): | ||
# Call the base class constructor with the parameters it needs | ||
super().__init__(f"'{program_name}' already exists") | ||
|
||
|
||
class StreamError(Exception): | ||
pass | ||
|
||
|
@@ -150,7 +144,6 @@ def submit( | |
A future for the job result, or the job if the job has failed. | ||
|
||
Raises: | ||
ProgramAlreadyExistsError: if the program already exists. | ||
StreamError: if there is a non-retryable error while executing the job. | ||
ValueError: if program name is not set. | ||
concurrent.futures.CancelledError: if the stream is stopped while a job is in flight. | ||
|
@@ -298,6 +291,7 @@ async def _manage_execution( | |
current_request, | ||
create_program_and_job_request, | ||
_to_create_job_request(create_program_and_job_request), | ||
_to_get_result_request(create_program_and_job_request), | ||
) | ||
continue | ||
else: # pragma: no cover | ||
|
@@ -319,7 +313,8 @@ def _get_retry_request_or_raise( | |
error: quantum.StreamError, | ||
current_request, | ||
create_program_and_job_request, | ||
create_job_request: quantum.QuantumRunStreamRequest, | ||
create_job_request, | ||
get_result_request: quantum.QuantumRunStreamRequest, | ||
): | ||
"""Decide whether the given stream error is retryable. | ||
|
||
|
@@ -330,19 +325,17 @@ def _get_retry_request_or_raise( | |
return create_program_and_job_request | ||
elif error.code == Code.PROGRAM_ALREADY_EXISTS: | ||
if 'create_quantum_program_and_job' in current_request: | ||
raise ProgramAlreadyExistsError( | ||
current_request.create_quantum_program_and_job.quantum_program.name | ||
) | ||
# If the program already exists and is created as part of the stream client, the job | ||
# should also exist because they are created at the same time. | ||
# If the job is missing, a `CreateQuantumJobRequest` will be issued after a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the program get created w/o the job if they're created together in a CreateProgramAndJobRequest? Does a closed stream kill the server-side handling? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarified a bit in the comment - it's for the unlikely case that the program is created outside |
||
# `GetQuantumResultRequest` is attempted. | ||
return get_result_request | ||
elif error.code == Code.JOB_DOES_NOT_EXIST: | ||
if 'get_quantum_result' in current_request: | ||
return create_job_request | ||
|
||
# Code.JOB_ALREADY_EXISTS should never happen. | ||
# The first stream request is always a CreateQuantumProgramAndJobRequest, which never fails | ||
# with this error because jobs are scoped within a program. | ||
# CreateQuantumJobRequests would fail with a PROGRAM_ALREADY_EXISTS if the job already | ||
# exists because program and job creation happen atomically for a | ||
# CreateQuantumProgramAndJobRequest. | ||
elif error.code == Code.JOB_ALREADY_EXISTS: | ||
if not 'get_quantum_result' in current_request: | ||
return get_result_request | ||
|
||
raise StreamError(error.message) | ||
|
||
|
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.
Can you keep the type hint here?
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.
It's still there, just moved down by 1 param
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.
that's not (typically) how type annotations work in python. They should be on each parameter