From c86e7fd1190d377aeb0c6ce45dea8935e108394d Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Mon, 10 Jul 2023 17:54:24 +0200 Subject: [PATCH 1/3] Restore backwards compatibility on the legacy serializer --- VERSION.txt | 2 +- pulser-core/pulser/json/coders.py | 12 ++++++++++++ tests/test_json.py | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 9beb74d49..288adf538 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.13.2 +0.13.3 diff --git a/pulser-core/pulser/json/coders.py b/pulser-core/pulser/json/coders.py index 46b8ba0e6..3d1a2dc04 100644 --- a/pulser-core/pulser/json/coders.py +++ b/pulser-core/pulser/json/coders.py @@ -101,6 +101,18 @@ def object_hook(self, obj: dict[str, Any]) -> Any: if not build: return cls + if "Device" in obj_name: + # Handle the removal of _channels for backwards compatibility + _channels = obj["__kwargs__"].pop("_channels", None) + channel_objs = obj["__kwargs__"].get("channel_objects", None) + channel_ids = obj["__kwargs__"].get("channel_ids", None) + if _channels and not (channel_ids or channel_objs): + _channels_dict = dict(_channels) + obj["__kwargs__"]["channel_ids"] = tuple(_channels_dict.keys()) + obj["__kwargs__"]["channel_objects"] = tuple( + _channels_dict.values() + ) + if "Sequence" in obj_name: seq = cls(*obj["__args__"], **obj["__kwargs__"]) for name, args, kwargs in obj["calls"]: diff --git a/tests/test_json.py b/tests/test_json.py index 3b8efdde1..9764c84e2 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -210,3 +210,26 @@ def test_sequence_module(): # Check that it also works s = json.dumps(obj_dict) Sequence.deserialize(s) + + +def test_deprecation(): + seq = Sequence(Register.square(1), MockDevice) + + seq_dict = json.loads(seq.serialize()) + dev_dict = seq_dict["__kwargs__"]["device"] + + assert "_channels" not in dev_dict["__kwargs__"] + dev_dict["__kwargs__"]["_channels"] = [] + + s = json.dumps(seq_dict) + new_seq = Sequence.deserialize(s) + assert new_seq.device == MockDevice + + ids = dev_dict["__kwargs__"].pop("channel_ids") + ch_objs = dev_dict["__kwargs__"].pop("channel_objects") + dev_dict["__kwargs__"]["_channels"] = tuple(zip(ids, ch_objs)) + + assert seq_dict["__kwargs__"]["device"] == dev_dict + s = json.dumps(seq_dict) + new_seq = Sequence.deserialize(s) + assert new_seq.device == MockDevice From 91b8d3a258925d0ec2f951a7ba3ffd07e1ab50cb Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Mon, 10 Jul 2023 18:00:52 +0200 Subject: [PATCH 2/3] Pin jsonschema --- pulser-core/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pulser-core/requirements.txt b/pulser-core/requirements.txt index e1b171398..019c2b781 100644 --- a/pulser-core/requirements.txt +++ b/pulser-core/requirements.txt @@ -1,4 +1,4 @@ -jsonschema +jsonschema < 4.18 matplotlib # Numpy 1.20 introduces type hints, 1.24.0 breaks matplotlib < 3.6.1 numpy >= 1.20, != 1.24.0 From ae5d587e1ba46b93bf75c592b67da277a9df3406 Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Mon, 10 Jul 2023 18:04:30 +0200 Subject: [PATCH 3/3] Pin pydantic --- pulser-pasqal/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/pulser-pasqal/requirements.txt b/pulser-pasqal/requirements.txt index a86e8f5a3..c94f4466d 100644 --- a/pulser-pasqal/requirements.txt +++ b/pulser-pasqal/requirements.txt @@ -1 +1,2 @@ pasqal-cloud ~= 0.2.3 +pydantic < 2.0 \ No newline at end of file