Skip to content

Commit

Permalink
added utils.flatten_dict (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctuning-admin authored Nov 11, 2024
2 parents 584ccb6 + 08cdee6 commit 45972c7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 8 additions & 5 deletions cm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions cm/cmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions cm4abtf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TBD
1 change: 1 addition & 0 deletions cm4mlops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TBD
1 change: 1 addition & 0 deletions cmx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TBD

0 comments on commit 45972c7

Please sign in to comment.