Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM v2.2.0 release #1227

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## V2.1.2.1
## V2.2.0
- fixed detection of a CM artifact using 'cm info .' when inside virtual env entries.
- added "cmind.utils.debug_here" function to attach remote Python debugger
and tested with Visual Studio Code.
- added test to avoid checking out CM repo that was not pulled
- added utils.safe_load_json to return empty dict if file doesn't exist
- added utils.compare_versions to check min version requirements for automations and entries
- removed outdated convert_path (https://github.com/mlcommons/ck/issues/1219)
- added utils.check_if_true_yes_on (https://github.com/mlcommons/ck/issues/1216)
- check "min_cm_version" in CM automations and CM scripts (use _cm.yaml or _cm.json)

## V2.1.2
- added support for deps on other CM repos
Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.2.1"
__version__ = "2.2.0"

from cmind.core import access
from cmind.core import error
Expand Down
10 changes: 10 additions & 0 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,16 @@ def access(self, i, out = None):

i['parsed_artifact'] = r['cm_object']

# Check min CM version requirement
min_cm_version = automation_meta.get('min_cm_version','').strip()
if min_cm_version != '':
from cmind import __version__ as current_cm_version
comparison = utils.compare_versions(current_cm_version, min_cm_version)
if comparison < 0:
return {'return':1, 'error':'CM automation requires CM version >= {} while current CM version is {} - please update using "pip install cmind -U"'.format(min_cm_version, current_cm_version)}



# Call automation action
action_addr=getattr(initialized_automation, action)

Expand Down
107 changes: 105 additions & 2 deletions cm/cmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ def save_json_or_yaml(file_name, meta, sort_keys=False, encoding = 'utf8'):

return {'return':ERROR_UNKNOWN_FILE_EXTENSION, 'error':'unknown file extension'}

###########################################################################
def safe_load_json(path, file_name='', encoding='utf8'):
"""
Load JSON file if exists, otherwise return empty dict

Args:
(CM input dict):

file_name (str): file name
(encoding) (str): file encoding ('utf8' by default)

Returns:
(CM return dict):

* return (int): return code == 0 if no error and >0 if error
* (error) (str): error string if return>0

* meta (dict): meta from the file

"""

path_to_file = os.path.join(path, file_name) if file_name == '' or path != file_name else path

meta = {}

r = load_json(path_to_file, check_if_exists=True, encoding=encoding)
if r['return'] == 0:
meta = r['meta']

return {'return':0, 'meta': meta}

###########################################################################
def load_json(file_name, check_if_exists = False, encoding='utf8'):
"""
Expand Down Expand Up @@ -173,8 +204,7 @@ def load_json(file_name, check_if_exists = False, encoding='utf8'):
except Exception as e:
return {'return':4, 'error': format(e)}

return {'return':0,
'meta': meta}
return {'return':0, 'meta': meta}

###########################################################################
def save_json(file_name, meta={}, indent=2, sort_keys=True, encoding = 'utf8'):
Expand Down Expand Up @@ -1679,3 +1709,76 @@ def breakpoint(self):

# Go up outside this function to continue debugging (F11 in VS)
return debugpy

##############################################################################
def compare_versions(version1, version2):
"""
Compare versions

Args:

version1 (str): version 1
version2 (str): version 2

Returns:
comparison (int): 1 - version 1 > version 2
0 - version 1 == version 2
-1 - version 1 < version 2
"""

l_version1 = version1.split('.')
l_version2 = version2.split('.')

# 3.9.6 vs 3.9
# 3.9 vs 3.9.6

i_version1 = [int(v) if v.isdigit() else v for v in l_version1]
i_version2 = [int(v) if v.isdigit() else v for v in l_version2]

comparison = 0

for index in range(max(len(i_version1), len(i_version2))):
v1 = i_version1[index] if index < len(i_version1) else 0
v2 = i_version2[index] if index < len(i_version2) else 0

if v1 > v2:
comparison = 1
break
elif v1 < v2:
comparison = -1
break

return comparison

##############################################################################
def check_if_true_yes_on(env, key):
"""
Universal check if str(env.get(key, '')).lower() in ['true', 'yes', 'on']:

Args:

env (dict): dictionary
key (str): key

Returns:
True if str(env.get(key, '')).lower() in ['true', 'yes', 'on']:
"""

return str(env.get(key, '')).lower() in ['true', 'yes', 'on']

##############################################################################
def check_if_none_false_no_off(env, key):
"""
Universal check if str(env.get(key, '')).lower() in ['false', 'no', 'off']:

Args:

env (dict): dictionary
key (str): key

Returns:
True if str(env.get(key, '')).lower() in ['false', 'no', 'off']:
"""

return str(env.get(key, '')).lower() in ['none', 'false', 'no', 'off']

1 change: 0 additions & 1 deletion cm/docs/KB/ML.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/KB/MLOps.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/README.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/architecture.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/conventions.md

This file was deleted.

55 changes: 0 additions & 55 deletions cm/docs/enhancements.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/example-modular-image-classification.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/installation.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/motivation.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/specification.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/tutorial-concept.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/tutorial-modular-mlperf.md

This file was deleted.

1 change: 0 additions & 1 deletion cm/docs/tutorial-scripts.md

This file was deleted.

2 changes: 1 addition & 1 deletion cm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import re

from setuptools import find_packages, setup, convert_path
from setuptools import find_packages, setup

try:
from setuptools.command.install import install
Expand Down
Loading