From 20082e93d644b5c258db0b5e82701b4956e5f36f Mon Sep 17 00:00:00 2001 From: Florian Deconinck Date: Thu, 5 Sep 2024 09:15:53 -0400 Subject: [PATCH] fix[cartesian]: Fix serialize default behavior when Pickled property was not saved (#1629) ## Description DaCe has a behavior of _not_ saving properties if they have a default (newish behavior) which leads our 2-step process of library node caching to fail. Since we have decided to rely on pickling to cache out the content of the LibraryNode we respond to this change in DaCe by making sure default values pass to the pickle deserializer are returned plain ## Requirements - [ ] All fixes and/or new features come with corresponding tests. - [ ] Important design decisions have been documented in the approriate ADR inside the [docs/development/ADRs/](docs/development/ADRs/Index.md) folder. --------- Co-authored-by: Florian Deconinck Co-authored-by: Roman Cattaneo --- src/gt4py/cartesian/gtc/dace/nodes.py | 14 +++++++++++--- .../multi_feature_tests/test_dace_parsing.py | 2 -- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gt4py/cartesian/gtc/dace/nodes.py b/src/gt4py/cartesian/gtc/dace/nodes.py index 42221d75c0..926265b2c7 100644 --- a/src/gt4py/cartesian/gtc/dace/nodes.py +++ b/src/gt4py/cartesian/gtc/dace/nodes.py @@ -50,9 +50,17 @@ def to_json(self, obj): @classmethod def from_json(cls, d, sdfg=None): - b64string = d["pickle"] - byte_repr = base64.b64decode(b64string) - return pickle.loads(byte_repr) + # DaCe won't serialize attr with default values by default + # which would lead the deserializer to push a default in the + # wrong format (non pickle). + # Best mitigation is to give back the object plain if it does + # not contain any pickling information + if isinstance(d, dict) and "pickle" in d.keys(): + b64string = d["pickle"] + byte_repr = base64.b64decode(b64string) + return pickle.loads(byte_repr) + + return d class PickledDataclassProperty(PickledProperty, dace.properties.DataclassProperty): diff --git a/tests/cartesian_tests/integration_tests/multi_feature_tests/test_dace_parsing.py b/tests/cartesian_tests/integration_tests/multi_feature_tests/test_dace_parsing.py index 7a793c0a70..9fafc27c85 100644 --- a/tests/cartesian_tests/integration_tests/multi_feature_tests/test_dace_parsing.py +++ b/tests/cartesian_tests/integration_tests/multi_feature_tests/test_dace_parsing.py @@ -46,8 +46,6 @@ def dace_env(): dace.config.Config.set("compiler", "cpu", "args", value="") dace.config.Config.set("compiler", "allow_view_arguments", value=True) dace.config.Config.set("default_build_folder", value=str(gt_cache_path)) - # Need to serialize `StencilComputation` library nodes because they contain OIR for `VerticalLoop` - dace.config.Config.set("testing", "serialize_all_fields", value=True) yield