Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore backwards compatibility on the legacy serializer #555

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.2
0.13.3
12 changes: 12 additions & 0 deletions pulser-core/pulser/json/coders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion pulser-core/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions pulser-pasqal/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pasqal-cloud ~= 0.2.3
pydantic < 2.0
23 changes: 23 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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