From 5ba4deb65aab22e79da8c76e19befa3596766309 Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Tue, 24 Sep 2024 14:14:44 +0200 Subject: [PATCH] Remove references to "submission" on RemoteResults --- pulser-core/pulser/backend/remote.py | 78 +--------------------------- tests/test_pasqal.py | 47 ----------------- 2 files changed, 2 insertions(+), 123 deletions(-) diff --git a/pulser-core/pulser/backend/remote.py b/pulser-core/pulser/backend/remote.py index 6abed00e1..631225914 100644 --- a/pulser-core/pulser/backend/remote.py +++ b/pulser-core/pulser/backend/remote.py @@ -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 @@ -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() @@ -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 @@ -122,7 +75,6 @@ class RemoteResults(Results): all jobs are included. """ - @_deprecate_submission_id def __init__( self, batch_id: str, @@ -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.""" @@ -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) diff --git a/tests/test_pasqal.py b/tests/test_pasqal.py index 6382f5898..fa26be3e0 100644 --- a/tests/test_pasqal.py +++ b/tests/test_pasqal.py @@ -32,7 +32,6 @@ RemoteConnection, RemoteResults, RemoteResultsError, - SubmissionStatus, ) from pulser.devices import DigitalAnalogDevice from pulser.register.special_layouts import SquareLatticeLayout @@ -155,36 +154,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']") ): @@ -210,11 +179,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 @@ -494,19 +458,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 )