Skip to content

Add pull method to ExclusiveRemoteTask #1027

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

Merged
merged 3 commits into from
May 2, 2025
Merged
Changes from 1 commit
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
35 changes: 29 additions & 6 deletions src/bloqade/analog/task/exclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import abc
import uuid
import re
import time

from beartype.typing import Dict
from dataclasses import dataclass, field
Expand Down Expand Up @@ -245,12 +246,34 @@

return self

def pull(self):
# Please avoid using this method, it's blocking and the waiting time is hours long
# Throw an error saying this is not supported
raise NotImplementedError(
"Pulling is not supported. Please use fetch() instead."
)

def pull(self,poll_interval:float=20):
"""
Blocking pull to get the task result.
poll_interval is the time interval to poll the task status.
Please ensure that it is relatively large, otherwise
the server could get overloaded with queries.
"""
if self._task_result_ir.task_status is QuEraTaskStatusCode.Unsubmitted:
raise ValueError("Task ID not found.")

Check warning on line 258 in src/bloqade/analog/task/exclusive.py

View check run for this annotation

Codecov / codecov/patch

src/bloqade/analog/task/exclusive.py#L257-L258

Added lines #L257 - L258 were not covered by tests

if self._task_result_ir.task_status in [

Check warning on line 260 in src/bloqade/analog/task/exclusive.py

View check run for this annotation

Codecov / codecov/patch

src/bloqade/analog/task/exclusive.py#L260

Added line #L260 was not covered by tests
QuEraTaskStatusCode.Completed,
QuEraTaskStatusCode.Partial,
QuEraTaskStatusCode.Failed,
QuEraTaskStatusCode.Unaccepted,
QuEraTaskStatusCode.Cancelled,
]:
return self

Check warning on line 267 in src/bloqade/analog/task/exclusive.py

View check run for this annotation

Codecov / codecov/patch

src/bloqade/analog/task/exclusive.py#L267

Added line #L267 was not covered by tests

status = self.status()
if status in [QuEraTaskStatusCode.Completed, QuEraTaskStatusCode.Partial]:
self._task_result_ir = self._http_handler.fetch_results(self._task_id)

Check warning on line 271 in src/bloqade/analog/task/exclusive.py

View check run for this annotation

Codecov / codecov/patch

src/bloqade/analog/task/exclusive.py#L269-L271

Added lines #L269 - L271 were not covered by tests
else:
time.sleep(poll_interval)
self.pull(poll_interval)

Check warning on line 274 in src/bloqade/analog/task/exclusive.py

View check run for this annotation

Codecov / codecov/patch

src/bloqade/analog/task/exclusive.py#L273-L274

Added lines #L273 - L274 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this with a loop do not use recursion for with an unknown depth of the call stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I was wondering about this. I thought it would be okay because of the slow poll time


return self

Check warning on line 276 in src/bloqade/analog/task/exclusive.py

View check run for this annotation

Codecov / codecov/patch

src/bloqade/analog/task/exclusive.py#L276

Added line #L276 was not covered by tests

def cancel(self):
# This is not supported
Expand Down
Loading