From 3046a3ddc316c7e305e35587bf17d6b53f6af1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Silv=C3=A9rio?= <29920212+HGSilveri@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:30:35 +0200 Subject: [PATCH] Remove legacy JSON serialization methods for Sequence (#737) * Remove legacy JSON serialization methods for Sequence * Fix warning in test --- pulser-core/pulser/sequence/sequence.py | 71 ------------------------- tests/test_json.py | 18 ------- tests/test_simulation.py | 2 +- 3 files changed, 1 insertion(+), 90 deletions(-) diff --git a/pulser-core/pulser/sequence/sequence.py b/pulser-core/pulser/sequence/sequence.py index 127d3821..d33eae2a 100644 --- a/pulser-core/pulser/sequence/sequence.py +++ b/pulser-core/pulser/sequence/sequence.py @@ -1625,39 +1625,6 @@ def build( return seq - def serialize(self, **kwargs: Any) -> str: - """Serializes the Sequence into a JSON formatted string. - - Other Parameters: - kwargs: Valid keyword-arguments for ``json.dumps()``, except for - ``cls``. - - Returns: - The sequence encoded in a JSON formatted string. - - Warning: - This method has been deprecated and is scheduled for removal - in Pulser v1.0.0. For sequence serialization and deserialization, - use ``Sequence.to_abstract_repr()`` and - ``Sequence.from_abstract_repr()`` instead. - - See Also: - ``json.dumps``: Built-in function for serialization to a JSON - formatted string. - """ - with warnings.catch_warnings(): - warnings.simplefilter("always") - warnings.warn( - DeprecationWarning( - "`Sequence.serialize()` and `Sequence.deserialize()` have " - "been deprecated and will be removed in Pulser v1.0.0. " - "Use `Sequence.to_abstract_repr()` and " - "`Sequence.from_abstract_repr()` instead." - ) - ) - - return self._serialize(**kwargs) - def _serialize(self, **kwargs: Any) -> str: """Serializes the Sequence into a JSON formatted string. @@ -1728,44 +1695,6 @@ def to_abstract_repr( ) from e raise e # pragma: no cover - @staticmethod - def deserialize(obj: str, **kwargs: Any) -> Sequence: - """Deserializes a JSON formatted string. - - Args: - obj: The JSON formatted string to deserialize, coming from - the serialization of a ``Sequence`` through - ``Sequence.serialize()``. - - Other Parameters: - kwargs: Valid keyword-arguments for ``json.loads()``, except for - ``cls`` and ``object_hook``. - - Returns: - The deserialized Sequence object. - - Warning: - This method has been deprecated and is scheduled for removal - in Pulser v1.0.0. For sequence serialization and deserialization, - use ``Sequence.to_abstract_repr()`` and - ``Sequence.from_abstract_repr()`` instead. - - See Also: - ``json.loads``: Built-in function for deserialization from a JSON - formatted string. - """ - with warnings.catch_warnings(): - warnings.simplefilter("always") - warnings.warn( - DeprecationWarning( - "`Sequence.serialize()` and `Sequence.deserialize()` have " - "been deprecated and will be removed in Pulser v1.0.0. " - "Use `Sequence.to_abstract_repr()` and " - "`Sequence.from_abstract_repr()` instead." - ) - ) - return Sequence._deserialize(obj, **kwargs) - @staticmethod def _deserialize(obj: str, **kwargs: Any) -> Sequence: """Deserializes a JSON formatted string. diff --git a/tests/test_json.py b/tests/test_json.py index 5db5ee9a..b211c06d 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -17,7 +17,6 @@ import numpy as np import pytest -import pulser from pulser import Register, Register3D, Sequence from pulser.devices import DigitalAnalogDevice, MockDevice from pulser.json.coders import PulserDecoder, PulserEncoder @@ -279,20 +278,3 @@ def test_deprecated_device_args(): s = json.dumps(seq_dict) new_seq = Sequence._deserialize(s) assert new_seq.device == MockDevice - - -def test_deprecation_warning(): - msg = re.escape( - "`Sequence.serialize()` and `Sequence.deserialize()` have " - "been deprecated and will be removed in Pulser v1.0.0. " - "Use `Sequence.to_abstract_repr()` and " - "`Sequence.from_abstract_repr()` instead." - ) - seq = Sequence(Register.square(1), MockDevice) - with pytest.warns(DeprecationWarning, match=msg): - s = seq.serialize() - - with pytest.warns(DeprecationWarning, match=msg): - Sequence.deserialize(s) - - assert pulser.__version__ < "1.0", "Remove legacy serializer methods" diff --git a/tests/test_simulation.py b/tests/test_simulation.py index c9318afe..5921e55a 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -1535,7 +1535,7 @@ def test_effective_size_disjoint(channel_type): ) -def test_simulation_with_modulation(mod_device, reg): +def test_simulation_with_modulation(mod_device, reg, patch_plt_show): seq = Sequence(reg, mod_device) seq.declare_channel("ch0", "rydberg_global") seq.config_slm_mask({"control1"})