From 70abcd5ceff309d8eb79e4af6c598fb9b65824c4 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 5 Feb 2024 16:08:36 -0800 Subject: [PATCH] TestClass._json_dict_() needs to be instance method Fixes serialization of ReadoutScanTask in data_collection.ipynb notebook. --- recirq/serialization_utils.py | 5 +++-- recirq/serialization_utils_test.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/recirq/serialization_utils.py b/recirq/serialization_utils.py index 8017d631..08ffba26 100644 --- a/recirq/serialization_utils.py +++ b/recirq/serialization_utils.py @@ -213,8 +213,9 @@ def wrap(cls): cls._json_namespace_ = classmethod(lambda obj: namespace) - cls._json_dict_ = classmethod(lambda obj: cirq.obj_to_dict_helper( - obj, [f.name for f in dataclasses.fields(cls)])) + cls._json_dict_ = lambda obj: cirq.obj_to_dict_helper( + obj, [f.name for f in dataclasses.fields(cls)] + ) if registry is not None: if namespace is not None: diff --git a/recirq/serialization_utils_test.py b/recirq/serialization_utils_test.py index b0868ee3..71a9676d 100644 --- a/recirq/serialization_utils_test.py +++ b/recirq/serialization_utils_test.py @@ -118,3 +118,6 @@ def test_str_and_repr(): def test_json_serializable_class(): assert TestTask._json_namespace_() == "recirq.test_task" + test_task = TestTask(dataset_id="duck") + json_text = cirq.to_json(test_task) + assert test_task == recirq.read_json(json_text=json_text)