From 639399976caf0789b13e03e7d52a8e152fa1116d Mon Sep 17 00:00:00 2001 From: Grigori Fursin Date: Sun, 20 Oct 2024 11:29:53 +0200 Subject: [PATCH 1/3] - Fix type of "unknown_keys" to list to be serializable: https://github.com/mlcommons/ck/issues/1335 --- cm/CHANGES.md | 4 ++++ cm/README.md | 2 +- cm/cmind/__init__.py | 2 +- cm/cmind/utils.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cm/CHANGES.md b/cm/CHANGES.md index 57b892232..1966eff3b 100644 --- a/cm/CHANGES.md +++ b/cm/CHANGES.md @@ -1,3 +1,7 @@ +## V3.2.5.1 + - Fix type of "unknown_keys" to list to be serializable + https://github.com/mlcommons/ck/issues/1335 + ## V3.2.5 - CMX: improved logging - CMX: improved error handling (show module path and line number) diff --git a/cm/README.md b/cm/README.md index 3536e3714..f5ae36387 100644 --- a/cm/README.md +++ b/cm/README.md @@ -15,7 +15,7 @@ across diverse models, data sets, software and hardware. CM is a part of [Collective Knowledge (CK)](https://github.com/mlcommons/ck) - an educational community project to learn how to run emerging workloads -in the most efficient and cost-effictive way across diverse +in the most efficient and cost-effective way across diverse and continuously changing systems. CM includes a collection of portable, extensible and technology-agnostic automation recipes diff --git a/cm/cmind/__init__.py b/cm/cmind/__init__.py index f7f78e1f5..1a6f3a7af 100644 --- a/cm/cmind/__init__.py +++ b/cm/cmind/__init__.py @@ -2,7 +2,7 @@ # # Written by Grigori Fursin -__version__ = "3.2.5" +__version__ = "3.2.5.1" from cmind.core import access from cmind.core import x diff --git a/cm/cmind/utils.py b/cm/cmind/utils.py index c8a964ed5..a631236d0 100644 --- a/cm/cmind/utils.py +++ b/cm/cmind/utils.py @@ -1936,7 +1936,7 @@ def test_input(i): r = {'return':0} if len(i)>0: - unknown_keys = i.keys() + unknown_keys = list(i.keys()) unknown_keys_str = ', '.join(unknown_keys) x = '' if len(unknown_keys) == 1 else 's' From 720c81c411cc72f98449adf36c4ed0bdcf2c1a3f Mon Sep 17 00:00:00 2001 From: Grigori Fursin Date: Mon, 21 Oct 2024 12:47:28 +0200 Subject: [PATCH 2/3] Process 'warning' in return: https://github.com/mlcommons/ck/issues/1336 --- cm/cmind/core.py | 69 ++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/cm/cmind/core.py b/cm/cmind/core.py index 8e3577ce1..25edc2b4b 100644 --- a/cm/cmind/core.py +++ b/cm/cmind/core.py @@ -136,7 +136,9 @@ def error(self, r): if self.debug: raise Exception(r['error']) - sys.stderr.write('\n'+self.cfg['error_prefix']+' '+r['error']+'!\n') + text = self.cfg['error_prefix'] + ' ' + r['error'] + '!\n' + + sys.stderr.write(f'\n{text}') return r @@ -159,39 +161,44 @@ def errorx(self, r): if self.debug: raise Exception(r['error']) - module_path = r.get('module_path', '') - lineno = r.get('lineno', '') + if 'warning' in r: + message = r.get('warning', '') + if message != '': + message = '\nCMX warning: ' + message.capitalize() + '!\n' + else: + module_path = r.get('module_path', '') + lineno = r.get('lineno', '') - message = '' + message = '' - if not self.logger == None or (module_path != '' and lineno != ''): - call_stack = self.state.get('call_stack', []) + if not self.logger == None or (module_path != '' and lineno != ''): + call_stack = self.state.get('call_stack', []) - if not self.logger == None: + if not self.logger == None: - self.log(f"x error call stack: {call_stack}", "debug") - self.log(f"x error: {r}", "debug") + self.log(f"x error call stack: {call_stack}", "debug") + self.log(f"x error: {r}", "debug") - sys.stderr.write('='*60 + '\n') + sys.stderr.write('^'*60 + '\n') - if not self.logger == None: - sys.stderr.write('CMX call stack:\n') + if not self.logger == None: + sys.stderr.write('CMX call stack:\n') - for cs in call_stack: - sys.stderr.write(f' * {cs}\n') + for cs in call_stack: + sys.stderr.write(f' * {cs}\n') + message += '\n' + else: message += '\n' - else: - message += '\n' - message += self.cfg['error_prefix2'] + message += self.cfg['error_prefix2'] - if module_path != '' and lineno !='': - message += f' in {module_path} ({lineno}):\n\n' - else: - message += ': ' + if module_path != '' and lineno !='': + message += f' in {module_path} ({lineno}):\n\n' + else: + message += ': ' - message += r['error'] + '\n' + message += r['error'] + '\n' sys.stderr.write(message) @@ -1097,7 +1104,7 @@ def _x(self, i, control): print ('') print ('Check https://github.com/mlcommons/ck/tree/master/cm/docs/cmx for more details.') - return {'return':0, 'warning':'no action specified'} + return {'return':1, 'warning':'', 'error':'help requested'} # Load info about all CM repositories (to enable search for automations and artifacts) if self.repos == None: @@ -1292,11 +1299,13 @@ def _x(self, i, control): # Check if common automation and --help if (use_common_automation or automation == '') and cm_help: - return print_action_help(self.common_automation, - self.common_automation, - 'common', - action, - original_action) + r = print_action_help(self.common_automation, + self.common_automation, + 'common', + action, + original_action) + + return {'return':1, 'warning':'', 'error':'help requested'} # If no automation was found we do not force common automation, check if should fail or continue if not use_common_automation and len(automation_lst)==0: @@ -1371,7 +1380,7 @@ def _x(self, i, control): for d in actions: print (' * cmx ' + d + ' ' + automation_meta.get('alias','') + ' -h') - return {'return':0, 'warning':'no automation action'} + return {'return':1, 'warning':'', 'error':'help requested'} if not hasattr(initialized_automation, action): @@ -1488,6 +1497,8 @@ def _x(self, i, control): print ('') print (delayed_help_api) + return {'return':1, 'warning':'', 'error':'help requested'} + return r From d8b19297fe6926d22254d239b8aa382264611d37 Mon Sep 17 00:00:00 2001 From: Grigori Fursin Date: Mon, 21 Oct 2024 12:49:25 +0200 Subject: [PATCH 3/3] v3.2.6 --- cm/CHANGES.md | 4 +++- cm/cmind/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cm/CHANGES.md b/cm/CHANGES.md index 1966eff3b..f36e8a8c6 100644 --- a/cm/CHANGES.md +++ b/cm/CHANGES.md @@ -1,6 +1,8 @@ -## V3.2.5.1 +## V3.2.6 - Fix type of "unknown_keys" to list to be serializable https://github.com/mlcommons/ck/issues/1335 + - Added support to print warning instead of error + (useful for help) ## V3.2.5 - CMX: improved logging diff --git a/cm/cmind/__init__.py b/cm/cmind/__init__.py index 1a6f3a7af..f207710af 100644 --- a/cm/cmind/__init__.py +++ b/cm/cmind/__init__.py @@ -2,7 +2,7 @@ # # Written by Grigori Fursin -__version__ = "3.2.5.1" +__version__ = "3.2.6" from cmind.core import access from cmind.core import x