Skip to content

Commit

Permalink
Merge pull request #12 from openkim/devel
Browse files Browse the repository at this point in the history
Include script generated source file
  • Loading branch information
mjwen authored Jul 22, 2022
2 parents 4451ab8 + f13ba56 commit a5e0f3a
Show file tree
Hide file tree
Showing 63 changed files with 2,999 additions and 646 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python package
name: test

on: [push]

Expand All @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Install gcc
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
compiler: [clang, gcc]
steps:
- uses: actions/checkout@v2
Expand Down
29 changes: 2 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,7 @@ build/
dist/
ase_kim_calculator.egg-info/

kimpy/SpeciesName_attributes.cpp
kimpy/*Unit_bind.cpp
kimpy/KIM_DataType_bind.cpp
kimpy/KIM_Numbering_bind.cpp
kimpy/KIM_SpeciesName_bind.cpp
kimpy/KIM_LanguageName_bind.cpp
kimpy/KIM_ModelRoutineName_bind.cpp
kimpy/KIM_ComputeCallbackName_bind.cpp
kimpy/KIM_SupportStatus_bind.cpp
kimpy/KIM_LogVerbosity_bind.cpp
kimpy/KIM_Collection_bind.cpp
kimpy/KIM_CollectionItemType_bind.cpp

tests/species_name_attributes.py
tests/*_unit.py
tests/test_data_type.py
tests/test_numbering.py
tests/test_species_name.py
tests/test_language_name.py
tests/test_model_routine_name.py
tests/test_compute_callback_name.py
tests/test_support_status.py
tests/test_log_verbosity.py
tests/test_collection.py
tests/test_collection_item_type.py

# Precompiled Headers
# Pre-compiled Headers
*.gch
*.pch

Expand Down Expand Up @@ -70,3 +44,4 @@ kimpy.egg-info
kim.log
.cache
.pytest_cache/
.DS_Store
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,3 @@ clean:
python setup.py clean
clean_all:
rm -rf build/ dist/ kimpy.egg-info/ */*.so */*.pyc */__pycache__ \
kimpy/*Unit_bind.cpp \
kimpy/KIM_DataType_bind.cpp kimpy/KIM_Numbering_bind.cpp \
kimpy/KIM_SpeciesName_bind.cpp kimpy/KIM_LanguageName_bind.cpp \
kimpy/KIM_ComputeCallbackName_bind.cpp kimpy/KIM_LogVerbosity_bind.cpp \
kimpy/KIM_Collection_bind.cpp kimpy/KIM_CollectionItemType_bind.cpp \
tests/*_unit.py \
tests/test_data_type.py tests/test_numbering.py tests/test_species_name.py \
tests/test_language_name.py tests/test_compute_callback_name.py \
tests/test_log_verbosity.py tests/test_support_status.py \
tests/test_collection.py tests/test_collection_item_type.py \
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,3 @@ Contributors:\
      Mingjian Wen\
      Yaser Afshar
## Contact
      Mingjian Wen (wenxx151@umn.edu)
80 changes: 42 additions & 38 deletions api_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import OrderedDict
import sys

sys.path.insert(0, abspath('kimpy'))
sys.path.insert(0, abspath("kimpy"))

from err import KimPyError

Expand All @@ -21,24 +21,28 @@ def read_compatible_table():
compatible with
"""
this_dir = dirname(abspath(__file__))
file_path = join(this_dir, 'api_compatibility.txt')
file_path = join(this_dir, "api_compatibility.txt")

if not isfile(file_path):
msg = "{} is not an existing regular file.".format(file_path)
raise KimPyError(msg)

compatible_table = OrderedDict()
with open(file_path, 'r') as fin:
with open(file_path, "r") as fin:
for line in fin:
line = line.strip()
if not line or line[0] == '#':
if not line or line[0] == "#":
continue

kimpy_version, kim_api_target_version, kim_api_backward_version = line.split()
(
kimpy_version,
kim_api_target_version,
kim_api_backward_version,
) = line.split()

compatible_table[kimpy_version] = {
'target': kim_api_target_version,
'backward': kim_api_backward_version,
"target": kim_api_target_version,
"backward": kim_api_backward_version,
}

return compatible_table
Expand All @@ -53,28 +57,28 @@ def compare_version(x, y):
'=' if x equal y
'>' is x larger than y
"""
x_major, x_minor, x_patch = [int(i) for i in x.split('.')]
y_major, y_minor, y_patch = [int(i) for i in y.split('.')]
x_major, x_minor, x_patch = [int(i) for i in x.split(".")]
y_major, y_minor, y_patch = [int(i) for i in y.split(".")]

if x_major > y_major:
return '>'
return ">"

if x_major < y_major:
return '<'
return "<"

if x_minor > y_minor:
return '>'
return ">"

if x_minor < y_minor:
return '<'
return "<"

if x_patch > y_patch:
return '>'
return ">"

if x_patch < y_patch:
return '<'
return "<"

return '='
return "="


def suggest_kimpy(kim_api_version, compatible_table):
Expand All @@ -99,10 +103,10 @@ def suggest_kimpy(kim_api_version, compatible_table):

# search backward
for key, value in compatible_table.items():
if value['target'] == kim_api_version:
if value["target"] == kim_api_version:
target = key

if value['backward'] == kim_api_version:
if value["backward"] == kim_api_version:
backward = key

if backward:
Expand All @@ -129,53 +133,53 @@ def check_kim_api_compatibility(kimpy_version, kim_api_version):

# last key in OrderedDict
latest_kimpy = next(reversed(compatible_table))
latest_target = compatible_table[latest_kimpy]['target']
latest_target = compatible_table[latest_kimpy]["target"]

cmp = compare_version(latest_target, kim_api_version)
cmp_1 = True
if cmp == '<':
if cmp == "<":
cmp_1 = False
else:
oldest_target = '2.0.0'
oldest_target = "2.0.0"
cmp = compare_version(oldest_target, kim_api_version)
if cmp == '>':
if cmp == ">":
cmp_1 = False

# check whether the current kimpy is compatible with the api
target = compatible_table[kimpy_version]['target']
backward = compatible_table[kimpy_version]['backward']
target = compatible_table[kimpy_version]["target"]
backward = compatible_table[kimpy_version]["backward"]

cmp = compare_version(target, kim_api_version)
cmp_2 = True
if cmp == '<':
if cmp == "<":
cmp_2 = False
else:
cmp = compare_version(backward, kim_api_version)
if cmp == '>':
if cmp == ">":
cmp_2 = False

if not cmp_1 or not cmp_2:
msg0 = "\n\n\n{}\n".format("=" * 80)

msg1 = 'KIM-API version = "{}" is detected, '.format(kim_api_version)
msg1 += 'which is incompatible with the current\n kimpy version = '
msg1 += "which is incompatible with the current\n kimpy version = "
msg1 += '"{}".\n\nTry one of these options:\n\n'.format(kimpy_version)

msg2 = ' (1) Update KIM-API.\n The current kimpy is '
msg2 += 'compatible with KIM-API versions:\n '
msg2 = " (1) Update KIM-API.\n The current kimpy is "
msg2 += "compatible with KIM-API versions:\n "
msg2 += ' ["{}" - "{}"] (inclusive).\n'.format(backward, target)

if not cmp_1:
msg3 = ' (2) Use the latest kimpy.\n If you are using the '
msg3 += 'latest kimpy, which is not compatible '
msg3 += 'with this\n KIM-API version '
msg3 = " (2) Use the latest kimpy.\n If you are using the "
msg3 += "latest kimpy, which is not compatible "
msg3 += "with this\n KIM-API version "
msg3 += '"{}" yet. Please contact\n '.format(kim_api_version)
msg3 += 'Mingjian Wen (wenxx151@umn.edu) or\n '
msg3 += 'raise an issue on github so we update the kimpy.\n'
msg3 += "Mingjian Wen (wenxx151@umn.edu) or\n "
msg3 += "raise an issue on github so we update the kimpy.\n"
else:
compatible_kimpy = suggest_kimpy(kim_api_version, compatible_table)
msg3 = ' (2) Switch kimpy version.\n The detected KIM-API '
msg3 += 'is compatible with kimpy version '
msg3 = " (2) Switch kimpy version.\n The detected KIM-API "
msg3 += "is compatible with kimpy version "
msg3 += '"{}".\n'.format(compatible_kimpy)

msg = msg0 + msg1 + msg2 + msg3
Expand All @@ -185,6 +189,6 @@ def check_kim_api_compatibility(kimpy_version, kim_api_version):
return msg


if __name__ == '__main__':
kim_api_compatibility = check_kim_api_compatibility('0.2.3', '2.0.1')
if __name__ == "__main__":
kim_api_compatibility = check_kim_api_compatibility("0.2.3", "2.0.1")
print(kim_api_compatibility)
42 changes: 21 additions & 21 deletions examples/example_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def dirs_for_collection(collection, collections):
msg = 'Calling "collections.cache_list_of_directory_names" failed.'
raise kimpy.KimPyError(msg)

print('{}:{}:'.format(str(collection), str(it)))
print("{}:{}:".format(str(collection), str(it)))

for i in range(extent):
try:
name = collections.get_directory_name(i)
except RuntimeError:
msg = 'Calling "collections.get_directory_name" for index = '
msg += '{} failed.'.format(i)
msg += "{} failed.".format(i)
raise kimpy.KimPyError(msg)

print(' ', name)
print(" ", name)


def names_for_collection(collection, collections):
Expand All @@ -43,18 +43,18 @@ def names_for_collection(collection, collections):
msg += 'cache_list_of_item_names_by_collection_and_type" failed.'
raise kimpy.KimPyError(msg)

print('{}:{}:'.format(str(collection), str(it)))
print("{}:{}:".format(str(collection), str(it)))

for i in range(extent):
try:
name = collections.get_item_name_by_collection_and_type(i)
except RuntimeError:
msg = 'Calling "collections.'
msg += 'get_item_name_by_collection_and_type" for index = '
msg += '{} failed.'.format(i)
msg += "{} failed.".format(i)
raise kimpy.KimPyError(msg)

print(' ', name)
print(" ", name)


def example_main():
Expand All @@ -67,8 +67,8 @@ def example_main():

project, semver = collections.get_project_name_and_sem_ver()

print('Project: {}'.format(project))
print('semVer: {}'.format(semver))
print("Project: {}".format(project))
print("semVer: {}".format(semver))

for it in (
kimpy.collection_item_type.modelDriver,
Expand All @@ -81,16 +81,16 @@ def example_main():
msg = 'Calling "collections.get_environment_variable_name" failed.'
raise kimpy.KimPyError(msg)

print('{} env name:{}'.format(str(it), name))
print("{} env name:{}".format(str(it), name))

name, value = collections.get_configuration_file_environment_variable()

print('config file env name: {}'.format(name))
print('config file env value: {}'.format(value))
print("config file env name: {}".format(name))
print("config file env value: {}".format(value))

filename = collections.get_configuration_file_name()

print('config file name: {}'.format(filename))
print("config file name: {}".format(filename))

for kc in (
kimpy.collection.system,
Expand Down Expand Up @@ -120,29 +120,29 @@ def example_main():
msg += 'cache_list_of_item_names_by_type" failed.'
raise kimpy.KimPyError(msg)

print('{}:'.format(str(it)))
print("{}:".format(str(it)))

for i in range(extent):
try:
name = collections.get_item_name_by_type(i)
except RuntimeError:
msg = 'Calling "collections.get_item_name_by_type" '
msg += 'for index = {} failed.'.format(i)
msg += "for index = {} failed.".format(i)
raise kimpy.KimPyError(msg)

print(' {}'.format(name))
print(" {}".format(name))

try:
filename, collection = collections.get_item_library_file_name_and_collection(
kimpy.collection_item_type.simulatorModel,
'Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu',
"Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
)
except RuntimeError:
msg = 'Calling "collections.'
msg += 'get_item_library_file_name_and_collection" failed.'
raise kimpy.KimPyError(msg)

msg = 'Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu '
msg = "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu "
msg += 'has library name "{}" and is part of the '.format(filename)
msg += '"{}" collection'.format(str(collection))
print(msg)
Expand All @@ -168,15 +168,15 @@ def example_main():
) = collections.get_item_metadata_file(i)
except RuntimeError:
msg = 'Calling "collections.get_item_metadata_file" '
msg += 'for index = {} failed.'.format(i)
msg += "for index = {} failed.".format(i)
raise kimpy.KimPyError(msg)

msg = 'Metadata file {} ({}) '.format(i, file_name)
msg += 'is of length {}'.format(file_length)
msg = "Metadata file {} ({}) ".format(i, file_name)
msg += "is of length {}".format(file_length)

print(msg)
print(file_str)


if __name__ == '__main__':
if __name__ == "__main__":
example_main()
Loading

0 comments on commit a5e0f3a

Please sign in to comment.