From 6fc9cd105d4f5e27fc04e5108d17fbafae302168 Mon Sep 17 00:00:00 2001 From: Grigori Fursin Date: Mon, 11 Nov 2024 16:07:08 +0100 Subject: [PATCH] added utils.flatten_dict --- cm/CHANGES.md | 3 +++ cm/README.md | 13 ++++++++----- cm/cmind/__init__.py | 2 +- cm/cmind/utils.py | 21 +++++++++++++++++++++ cm4abtf/README.md | 1 + cm4mlops/README.md | 1 + cmx/README.md | 1 + 7 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 cm4abtf/README.md create mode 100644 cm4mlops/README.md create mode 100644 cmx/README.md diff --git a/cm/CHANGES.md b/cm/CHANGES.md index cc7033df7e..e526859e56 100644 --- a/cm/CHANGES.md +++ b/cm/CHANGES.md @@ -1,3 +1,6 @@ +## V3.4.1.1 + - added utils.flatten_dict + ## V3.4.1 - reduced Python min version in pyproject.toml to 3.7 for backwards compatibility diff --git a/cm/README.md b/cm/README.md index 17f73e8bf3..e9b96edd06 100644 --- a/cm/README.md +++ b/cm/README.md @@ -78,8 +78,11 @@ You can learn more about the motivation behind these projects from the following ### Acknowledgments -The Collective Mind automation framework (CM) was created by [Grigori Fursin](https://cKnowledge.org/gfursin), -sponsored by cKnowledge.org and cTuning.org, and donated to MLCommons to benefit everyone. -This open-source technology (CM, CM4MLOps, CM4MLPerf, CM4ABTF, CM4Research, etc) -is being developed as a community effort thanks to all our fantastic -[volunteers, collaborators and contributors](https://github.com/mlcommons/ck/blob/master/CONTRIBUTING.md)! +The Collective Mind (CM) automation framework was originally +developed by [Grigori Fursin](https://cKnowledge.org/gfursin), +as a part of the [Collective Knowledge educational initiative](https://cKnowledge.org), +sponsored by [cTuning.org](https://cTuning.org) and [cKnowledge.org](https://cKnowledge.org), +and contributed to MLCommons for the benefit of all. +This open-source technology, including CM4MLOps/CM4MLPerf, CM4ABTF, CM4Research, and more, +is a collaborative community-driven project made possible by our +[amazing volunteers, collaborators, and contributors](https://github.com/mlcommons/ck/blob/master/CONTRIBUTING.md)! diff --git a/cm/cmind/__init__.py b/cm/cmind/__init__.py index 9e1019433d..6fa7e4068d 100644 --- a/cm/cmind/__init__.py +++ b/cm/cmind/__init__.py @@ -2,7 +2,7 @@ # # Written by Grigori Fursin -__version__ = "3.4.1" +__version__ = "3.4.1.1" from cmind.core import access from cmind.core import x diff --git a/cm/cmind/utils.py b/cm/cmind/utils.py index 858e2ed50c..e352fbc906 100644 --- a/cm/cmind/utils.py +++ b/cm/cmind/utils.py @@ -2026,3 +2026,24 @@ def load_module(cmind, task_path, sub_module_name): return cmind.prepare_error(1, f"Can\'t load Python module code {sub_module_path}:\n\n{e}") return {'return':0, 'sub_module_obj': sub_module_obj, 'sub_module_path': sub_module_path} + +############################################################################## +def flatten_dict(d, fd = {}, prefix = ''): + """ + Flatten dict ({"x":{"y":"z"}} -> x.y=z) + """ + + + for k in d: + v = d[k] + + if type(v) == list and len(v) == 1 and type(v[0]) == dict: + v = v[0] + + if type(v) == dict: + new_prefix = prefix + k + '.' + flatten_dict(v, fd, new_prefix) + else: + fd[prefix + k] = str(v) + + return diff --git a/cm4abtf/README.md b/cm4abtf/README.md new file mode 100644 index 0000000000..a0990367ef --- /dev/null +++ b/cm4abtf/README.md @@ -0,0 +1 @@ +TBD diff --git a/cm4mlops/README.md b/cm4mlops/README.md new file mode 100644 index 0000000000..a0990367ef --- /dev/null +++ b/cm4mlops/README.md @@ -0,0 +1 @@ +TBD diff --git a/cmx/README.md b/cmx/README.md new file mode 100644 index 0000000000..a0990367ef --- /dev/null +++ b/cmx/README.md @@ -0,0 +1 @@ +TBD