Skip to content

Commit

Permalink
fix[cartesian]: Fix serialize default behavior when Pickled property …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
Co-authored-by: Roman Cattaneo <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent 07f37fb commit 20082e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/gt4py/cartesian/gtc/dace/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 20082e9

Please sign in to comment.