Skip to content

Commit

Permalink
Remove references to "submission" on RemoteResults (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri authored Oct 8, 2024
1 parent a47f0a9 commit 0f8d435
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 123 deletions.
78 changes: 2 additions & 76 deletions pulser-core/pulser/backend/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
from __future__ import annotations

import typing
import warnings
from abc import ABC, abstractmethod
from collections.abc import Callable
from enum import Enum, auto
from functools import wraps
from types import TracebackType
from typing import Any, Mapping, Type, TypedDict, TypeVar, cast
from typing import Any, Mapping, Type, TypedDict, cast

from pulser.backend.abc import Backend
from pulser.devices import Device
Expand All @@ -37,23 +34,8 @@ class JobParams(TypedDict, total=False):
variables: dict[str, Any]


class SubmissionStatus(Enum):
"""Status of a remote submission."""

PENDING = auto()
RUNNING = auto()
DONE = auto()
CANCELED = auto()
TIMED_OUT = auto()
ERROR = auto()
PAUSED = auto()


class BatchStatus(Enum):
"""Status of a batch.
Same as SubmissionStatus, needed because we renamed Submission -> Batch.
"""
"""Status of a batch."""

PENDING = auto()
RUNNING = auto()
Expand Down Expand Up @@ -81,38 +63,9 @@ class RemoteResultsError(Exception):
pass


F = TypeVar("F", bound=Callable)


def _deprecate_submission_id(func: F) -> F:
@wraps(func)
def wrapper(self: RemoteResults, *args: Any, **kwargs: Any) -> Any:
if "submission_id" in kwargs:
# 'batch_id' is the first positional arg so if len(args) > 0,
# then it is being given
if "batch_id" in kwargs or args:
raise ValueError(
"'submission_id' and 'batch_id' cannot be simultaneously"
" specified. Please provide only the 'batch_id'."
)
warnings.warn(
"'submission_id' has been deprecated and replaced by "
"'batch_id'.",
category=DeprecationWarning,
stacklevel=3,
)
kwargs["batch_id"] = kwargs.pop("submission_id")
return func(self, *args, **kwargs)

return cast(F, wrapper)


class RemoteResults(Results):
"""A collection of results obtained through a remote connection.
Warns:
DeprecationWarning: If 'submission_id' is given instead of 'batch_id'.
Args:
batch_id: The ID that identifies the batch linked to the results.
connection: The remote connection over which to get the batch's
Expand All @@ -122,7 +75,6 @@ class RemoteResults(Results):
all jobs are included.
"""

@_deprecate_submission_id
def __init__(
self,
batch_id: str,
Expand All @@ -147,17 +99,6 @@ def results(self) -> tuple[Result, ...]:
"""The actual results, obtained after execution is done."""
return self._results

@property
def _submission_id(self) -> str:
"""The same as the batch ID, kept for backwards compatibility."""
warnings.warn(
"'RemoteResults._submission_id' has been deprecated, please use"
"'RemoteResults.batch_id' instead.",
category=DeprecationWarning,
stacklevel=2,
)
return self._batch_id

@property
def batch_id(self) -> str:
"""The ID of the batch containing these results."""
Expand All @@ -170,21 +111,6 @@ def job_ids(self) -> list[str]:
return self._connection._get_job_ids(self._batch_id)
return self._job_ids

def get_status(self) -> SubmissionStatus:
"""Gets the status of the remote submission.
Warning:
This method has been deprecated, please use
`RemoteResults.get_batch_status()` instead.
"""
warnings.warn(
"'RemoteResults.get_status()' has been deprecated, please use"
"'RemoteResults.get_batch_status()' instead.",
category=DeprecationWarning,
stacklevel=2,
)
return SubmissionStatus[self.get_batch_status().name]

def get_batch_status(self) -> BatchStatus:
"""Gets the status of the batch linked to these results."""
return self._connection._get_batch_status(self._batch_id)
Expand Down
47 changes: 0 additions & 47 deletions tests/test_pasqal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
RemoteConnection,
RemoteResults,
RemoteResultsError,
SubmissionStatus,
)
from pulser.devices import DigitalAnalogDevice
from pulser.register.special_layouts import SquareLatticeLayout
Expand Down Expand Up @@ -150,36 +149,6 @@ def fixt(mock_batch):

@pytest.mark.parametrize("with_job_id", [False, True])
def test_remote_results(fixt, mock_batch, with_job_id):
with pytest.raises(
ValueError,
match="'submission_id' and 'batch_id' cannot be simultaneously",
):
RemoteResults(
mock_batch.id,
submission_id=mock_batch.id,
connection=fixt.pasqal_cloud,
)

with pytest.raises(
ValueError,
match="'submission_id' and 'batch_id' cannot be simultaneously",
):
RemoteResults(
batch_id=mock_batch.id,
submission_id=mock_batch.id,
connection=fixt.pasqal_cloud,
)

with pytest.warns(
DeprecationWarning,
match="'submission_id' has been deprecated and replaced by 'batch_id'",
):
res_ = RemoteResults(
submission_id=mock_batch.id,
connection=fixt.pasqal_cloud,
)
assert res_.batch_id == mock_batch.id

with pytest.raises(
RuntimeError, match=re.escape("does not contain jobs ['badjobid']")
):
Expand All @@ -205,11 +174,6 @@ def test_remote_results(fixt, mock_batch, with_job_id):
id=remote_results.batch_id
)

with pytest.warns(
DeprecationWarning,
match=re.escape("'RemoteResults.get_status()' has been deprecated,"),
):
assert remote_results.get_status() == SubmissionStatus.DONE
fixt.mock_cloud_sdk.get_batch.reset_mock()

assert remote_results.get_batch_status() == BatchStatus.DONE
Expand Down Expand Up @@ -489,19 +453,8 @@ def test_submit(fixt, parametrized, emulator, mimic_qpu, seq, mock_batch):
)

assert isinstance(remote_results, RemoteResults)
with pytest.warns(
DeprecationWarning,
match=re.escape("'RemoteResults.get_status()' has been deprecated,"),
):
assert remote_results.get_status() == SubmissionStatus.DONE
assert remote_results.get_batch_status() == BatchStatus.DONE

with pytest.warns(
DeprecationWarning,
match=re.escape("'RemoteResults._submission_id' has been deprecated,"),
):
assert remote_results._submission_id == remote_results.batch_id

fixt.mock_cloud_sdk.get_batch.assert_called_with(
id=remote_results.batch_id
)
Expand Down

0 comments on commit 0f8d435

Please sign in to comment.