Skip to content

Commit

Permalink
Remove legacy JSON serialization methods for Sequence (#737)
Browse files Browse the repository at this point in the history
* Remove legacy JSON serialization methods for Sequence

* Fix warning in test
  • Loading branch information
HGSilveri authored Oct 7, 2024
1 parent dd68ac3 commit 3046a3d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 90 deletions.
71 changes: 0 additions & 71 deletions pulser-core/pulser/sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 0 additions & 18 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down

0 comments on commit 3046a3d

Please sign in to comment.