Skip to content
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

Add wait option to remote backends #598

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions pulser-core/pulser/backend/qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
class QPUBackend(RemoteBackend):
"""Backend for sequence execution on a QPU."""

def run(self, job_params: list[JobParams] | None = None) -> RemoteResults:
def run(
self, job_params: list[JobParams] | None = None, wait: bool = False
) -> RemoteResults:
"""Runs the sequence on the remote QPU and returns the result.

Args:
Expand All @@ -34,6 +36,10 @@ def run(self, job_params: list[JobParams] | None = None) -> RemoteResults:
is parametrized, the values for all the variables necessary
to build the sequence must be given in it's own mapping, for
each job, under the 'variables' field.
wait: Whether to wait until the results of the jobs become
available. If set to False, the call is non-blocking and the
obtained results' status can be checked using their `status`
property.

Returns:
The results, which can be accessed once all sequences have been
Expand All @@ -55,7 +61,7 @@ def run(self, job_params: list[JobParams] | None = None) -> RemoteResults:
f"device ({max_runs})" + suffix
)
results = self._connection.submit(
self._sequence, job_params=job_params
self._sequence, job_params=job_params, wait=wait
)
return cast(RemoteResults, results)

Expand Down
2 changes: 1 addition & 1 deletion pulser-core/pulser/backend/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class RemoteConnection(ABC):

@abstractmethod
def submit(
self, sequence: Sequence, **kwargs: Any
self, sequence: Sequence, wait: bool = False, **kwargs: Any
) -> RemoteResults | tuple[RemoteResults, ...]:
"""Submit a job for execution."""
pass
Expand Down
7 changes: 6 additions & 1 deletion pulser-pasqal/pulser_pasqal/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
)

def run(
self, job_params: list[JobParams] | None = None
self, job_params: list[JobParams] | None = None, wait: bool = False
) -> RemoteResults | tuple[RemoteResults, ...]:
"""Executes on the emulator backend through the Pasqal Cloud.

Expand All @@ -68,6 +68,10 @@ def run(
is parametrized, the values for all the variables necessary
to build the sequence must be given in it's own mapping, for
each job, under the 'variables' field.
wait: Whether to wait until the results of the jobs become
available. If set to False, the call is non-blocking and the
obtained results' status can be checked using their `status`
property.

Returns:
The results, which can be accessed once all sequences have been
Expand All @@ -87,6 +91,7 @@ def run(
job_params=job_params,
emulator=self.emulator,
config=self._config,
wait=wait,
)

def _validate_config(self, config: EmulatorConfig) -> None:
Expand Down
6 changes: 4 additions & 2 deletions pulser-pasqal/pulser_pasqal/pasqal_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def __init__(
**kwargs,
)

def submit(self, sequence: Sequence, **kwargs: Any) -> RemoteResults:
def submit(
self, sequence: Sequence, wait: bool = False, **kwargs: Any
) -> RemoteResults:
"""Submits the sequence for execution on a remote Pasqal backend."""
if not sequence.is_measured():
bases = sequence.get_addressed_bases()
Expand Down Expand Up @@ -141,7 +143,7 @@ def submit(self, sequence: Sequence, **kwargs: Any) -> RemoteResults:
jobs=job_params or [], # type: ignore[arg-type]
emulator=emulator,
configuration=configuration,
wait=False,
wait=wait,
)

return RemoteResults(batch.id, self)
Expand Down
2 changes: 1 addition & 1 deletion pulser-pasqal/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pasqal-cloud ~= 0.3.5
pasqal-cloud ~= 0.4.0
backoff ~= 2.2
2 changes: 1 addition & 1 deletion tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class _MockConnection(RemoteConnection):
def __init__(self):
self._status_calls = 0

def submit(self, sequence, **kwargs) -> RemoteResults:
def submit(self, sequence, wait: bool = False, **kwargsn) -> RemoteResults:
return RemoteResults("abcd", self)

def _fetch_result(self, submission_id: str) -> typing.Sequence[Result]:
Expand Down