Fix attributes dictionary handling in show_graphview.py
Context
aidge_core.Tensor objects found in nodes attributes dictionaries were not handled correctly during JSON description generation from the graph view, leading the script to fail.
Related issue: #264 (moved)
This MR addresses the issue by introducing an adapted serialization approach to aidge_core.Tensor objects. In addition, the json.dump function now uses the default=str option, which resolves most serialization issues encountered with custom types.
Modified files
-
aidge_core/show_graphview.py, fix in_retrieve_operator_attrs()function; -
aidge_core/unit_tests/test_show_graphview.py, adaption of unittest so it is coherent with new serialization approach.
Detailed major modifications
aidge_core/show_graphview.py
- In
_retrieve_operator_attrs()function:
- Added serialization for
aidge_core.Tensor; - Removed serialization relying on the node's attribute object name. It is no longer needed, since
default=stroption is enabled injson.dump()function, which is a more generic approach.
- In
_create_dict()function:
- Standardization: updated the serialization of Producers, which are also
aidge_core.Tensorobjects, to align with the newly proposed approach.
- In
_create_dict()and_write_dict_json()functions:
- Added the
default=stroption to the json.dump() function, which provides a fallback function for objects that aren’t natively serializable by JSON.
aidge_core/unit_tests/test_show_graphview.py
- Added a condition to test JSON description files that have been serialized using the new approach.
Edited by Iryna de Albuquerque Silva