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 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
34 changes: 28 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,33 @@

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.
"""

while True:
if self._task_result_ir.task_status is QuEraTaskStatusCode.Unsubmitted:
raise ValueError("Task ID not found.")

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L257 - L259 were not covered by tests

if self._task_result_ir.task_status in [

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L268 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)
return self

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L270 - L273 were not covered by tests

time.sleep(poll_interval)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L275 was not covered by tests

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