Initiated the regression test setup
This commit is contained in:
10
tools/regression-tests/config.yaml
Normal file
10
tools/regression-tests/config.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
lmp_binary: ""
|
||||
nprocs: "4"
|
||||
args: "-sc none -cite none"
|
||||
mpiexec: "mpirun"
|
||||
mpiexec_numproc_flag: "-n"
|
||||
accelerator_supported:
|
||||
- omp
|
||||
|
||||
|
||||
191072
tools/regression-tests/data.rhodo
Normal file
191072
tools/regression-tests/data.rhodo
Normal file
File diff suppressed because it is too large
Load Diff
31
tools/regression-tests/in.lj
Normal file
31
tools/regression-tests/in.lj
Normal file
@ -0,0 +1,31 @@
|
||||
# 3d Lennard-Jones melt
|
||||
|
||||
variable x index 1
|
||||
variable y index 1
|
||||
variable z index 1
|
||||
|
||||
variable xx equal 20*$x
|
||||
variable yy equal 20*$y
|
||||
variable zz equal 20*$z
|
||||
|
||||
units lj
|
||||
atom_style atomic
|
||||
|
||||
lattice fcc 0.8442
|
||||
region box block 0 ${xx} 0 ${yy} 0 ${zz}
|
||||
create_box 1 box
|
||||
create_atoms 1 box
|
||||
mass 1 1.0
|
||||
|
||||
velocity all create 1.44 87287 loop geom
|
||||
|
||||
pair_style lj/cut 2.5
|
||||
pair_coeff 1 1 1.0 1.0 2.5
|
||||
|
||||
neighbor 0.3 bin
|
||||
neigh_modify delay 0 every 20 check no
|
||||
|
||||
fix 1 all nve
|
||||
#REG:ADD thermo 10
|
||||
#REG:ADD thermo_style yaml
|
||||
run 100
|
||||
31
tools/regression-tests/in.lj.test
Normal file
31
tools/regression-tests/in.lj.test
Normal file
@ -0,0 +1,31 @@
|
||||
# 3d Lennard-Jones melt
|
||||
|
||||
variable x index 1
|
||||
variable y index 1
|
||||
variable z index 1
|
||||
|
||||
variable xx equal 20*$x
|
||||
variable yy equal 20*$y
|
||||
variable zz equal 20*$z
|
||||
|
||||
units lj
|
||||
atom_style atomic
|
||||
|
||||
lattice fcc 0.8442
|
||||
region box block 0 ${xx} 0 ${yy} 0 ${zz}
|
||||
create_box 1 box
|
||||
create_atoms 1 box
|
||||
mass 1 1.0
|
||||
|
||||
velocity all create 1.44 87287 loop geom
|
||||
|
||||
pair_style lj/cut 2.5
|
||||
pair_coeff 1 1 1.0 1.0 2.5
|
||||
|
||||
neighbor 0.3 bin
|
||||
neigh_modify delay 0 every 20 check no
|
||||
|
||||
fix 1 all nve
|
||||
thermo 10
|
||||
thermo_style yaml
|
||||
run 100
|
||||
27
tools/regression-tests/in.rhodo
Normal file
27
tools/regression-tests/in.rhodo
Normal file
@ -0,0 +1,27 @@
|
||||
# Rhodopsin model
|
||||
|
||||
units real
|
||||
neigh_modify delay 5 every 1 #REG:ADD check no
|
||||
|
||||
atom_style full
|
||||
bond_style harmonic
|
||||
angle_style charmm
|
||||
dihedral_style charmm
|
||||
improper_style harmonic
|
||||
pair_style lj/charmm/coul/long 8.0 10.0
|
||||
pair_modify mix arithmetic
|
||||
kspace_style pppm 1e-4
|
||||
|
||||
read_data data.rhodo
|
||||
|
||||
fix 1 all shake 0.0001 5 0 m 1.0 a 232
|
||||
fix 2 all npt temp 300.0 300.0 100.0 &
|
||||
z 0.0 0.0 1000.0 mtk no pchain 0 tchain 1
|
||||
|
||||
special_bonds charmm
|
||||
|
||||
thermo 50 #REG:SUB thermo 20
|
||||
thermo_style multi #REG:SUB thermo_style yaml
|
||||
timestep 2.0
|
||||
|
||||
run 100 #REG:SUB run 200 post no
|
||||
27
tools/regression-tests/in.rhodo.test
Normal file
27
tools/regression-tests/in.rhodo.test
Normal file
@ -0,0 +1,27 @@
|
||||
# Rhodopsin model
|
||||
|
||||
units real
|
||||
neigh_modify delay 5 every 1 check no
|
||||
|
||||
atom_style full
|
||||
bond_style harmonic
|
||||
angle_style charmm
|
||||
dihedral_style charmm
|
||||
improper_style harmonic
|
||||
pair_style lj/charmm/coul/long 8.0 10.0
|
||||
pair_modify mix arithmetic
|
||||
kspace_style pppm 1e-4
|
||||
|
||||
read_data data.rhodo
|
||||
|
||||
fix 1 all shake 0.0001 5 0 m 1.0 a 232
|
||||
fix 2 all npt temp 300.0 300.0 100.0 &
|
||||
z 0.0 0.0 1000.0 mtk no pchain 0 tchain 1
|
||||
|
||||
special_bonds charmm
|
||||
|
||||
thermo 20
|
||||
thermo_style yaml
|
||||
timestep 2.0
|
||||
|
||||
run 200 post no
|
||||
172
tools/regression-tests/run_tests.py
Normal file
172
tools/regression-tests/run_tests.py
Normal file
@ -0,0 +1,172 @@
|
||||
'''
|
||||
UPDATE: Oct 25, 2023:
|
||||
Launching the LAMMPS binary under testing using a configuration defined in a yaml file (e.g. config.yaml)
|
||||
this way we can launch LAMMPS with mpirun with more flexibility. Also it simplifies the build configuration.
|
||||
|
||||
python3 run_tests.py /path/to/lmp_binary
|
||||
|
||||
Original plan: using the LAMMPS Python module
|
||||
The following steps are for setting up regression tests with the LAMMPS Python module
|
||||
|
||||
0) Create a virtual environment, and activate it
|
||||
|
||||
python -m venv lmp-venv
|
||||
source lmp-venv/bin/activate
|
||||
PYTHON_EXECUTABLE=`which python`
|
||||
INSTALL_PREFIX=$(${PYTHON_EXECUTABLE} -c "import sys; print(sys.prefix)")
|
||||
|
||||
1) Build LAMMPS as a shared lib and install the LAMMPS python module into the virtual environment
|
||||
|
||||
git clone https://github.com/lammps/lammps.git lammps
|
||||
cd lammps
|
||||
mkdir build && cd build
|
||||
cmake ../cmake/presets/basic.cmake -DBUILD_SHARED_LIBS=on -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX
|
||||
make -j4
|
||||
make install-python
|
||||
|
||||
2) Run this script, after activating the virtual environment and having the input scripts with markers ready:
|
||||
|
||||
source lmp-venv/bin/activate
|
||||
python3 run_tests.py
|
||||
|
||||
'''
|
||||
|
||||
#from lammps import lammps
|
||||
import sys
|
||||
import re, yaml
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
from yaml import CSafeLoader as Loader
|
||||
except ImportError:
|
||||
from yaml import SafeLoader as Loader
|
||||
|
||||
'''
|
||||
inputFileName: input file with comments #REG:ADD and #REG:SUB as markers
|
||||
outputFileName: modified input file ready for testing
|
||||
'''
|
||||
def processing_markers(inputFileName, outputFileName):
|
||||
# read in the script
|
||||
with open(inputFileName, 'r') as file:
|
||||
data = file.read()
|
||||
|
||||
# replace #REG:ADD with empty string (i.e. adding the text at the end of the line)
|
||||
data = data.replace("#REG:ADD", "")
|
||||
|
||||
# replace the line contaning #REG:SUB with a line with the text that follows this marker
|
||||
data = data.splitlines()
|
||||
separator="#REG:SUB"
|
||||
out = []
|
||||
for line in data:
|
||||
s = line.split(separator)
|
||||
if len(s) < 2:
|
||||
out.append(line)
|
||||
else:
|
||||
out.append(s[1])
|
||||
|
||||
# write data to the new script
|
||||
with open(outputFileName, 'w') as file:
|
||||
for line in out:
|
||||
file.write(line + "\n")
|
||||
|
||||
'''
|
||||
yamlFileName: input YAML file with thermo structured as described in https://docs.lammps.org/Howto_structured_data.html
|
||||
return: thermo, which is a list containing a dictionary for each run where the tag "keywords" maps to the list
|
||||
of thermo header strings and the tag “data” has a list of lists where the outer list represents the lines
|
||||
of output and the inner list the values of the columns matching the header keywords for that step.
|
||||
'''
|
||||
def extract_thermo(yamlFileName):
|
||||
docs = ""
|
||||
with open(yamlFileName) as f:
|
||||
for line in f:
|
||||
m = re.search(r"^(keywords:.*$|data:$|---$|\.\.\.$| - \[.*\]$)", line)
|
||||
if m: docs += m.group(0) + '\n'
|
||||
|
||||
thermo = list(yaml.load_all(docs, Loader=Loader))
|
||||
return thermo
|
||||
|
||||
'''
|
||||
launch LAMMPS using the configuration defined in the dictionary config with an input file
|
||||
TODO:
|
||||
- generate new reference values if needed
|
||||
- wrap subprocess with try/catch to handle exceptions
|
||||
'''
|
||||
def execute(lmp_binary, config, input_file_name, generate_ref_yaml=False):
|
||||
cmd_str = config['mpiexec'] + " " + config['mpiexec_numproc_flag'] + " " + config['nprocs'] + " "
|
||||
cmd_str += lmp_binary + " -in " + input_file_name + " " + config['args']
|
||||
print(f"Execute: {cmd_str}")
|
||||
p = subprocess.run(cmd_str, shell=True, text=True, capture_output=True)
|
||||
output = p.stdout.split('\n')
|
||||
|
||||
'''
|
||||
TODO:
|
||||
- process "lmp -h" to get the list of installed packages
|
||||
- automate tagging the example input scripts of the installed packages
|
||||
'''
|
||||
if __name__ == "__main__":
|
||||
|
||||
lmp_binary = ""
|
||||
# if lmp binary is specified in the command line
|
||||
if len(sys.argv) >= 2:
|
||||
lmp_binary = sys.argv[1]
|
||||
|
||||
# list of input scripts with markers #REG:SUB and #REG:ADD
|
||||
input_list=['in.lj', 'in.rhodo']
|
||||
|
||||
# read in the configuration of the tests
|
||||
with open("config.yaml", 'r') as f:
|
||||
config = yaml.load(f, Loader=Loader)
|
||||
print(config)
|
||||
|
||||
# check if lmp_binary is specified in the config yaml
|
||||
if lmp_binary == "":
|
||||
if config['lmp_binary'] == "":
|
||||
print("Needs a valid LAMMPS binary")
|
||||
exit
|
||||
else:
|
||||
lmp_binary = config['lmp_binary']
|
||||
|
||||
# iterative over the input scripts
|
||||
for input in input_list:
|
||||
input_test=input + '.test'
|
||||
processing_markers(input, input_test)
|
||||
|
||||
str_t = "Running " + input_test
|
||||
print(str_t)
|
||||
print(f"-"*len(str_t))
|
||||
|
||||
# using the LAMMPS python module (for single-proc runs)
|
||||
# lmp = lammps()
|
||||
# lmp.file(input_test)
|
||||
|
||||
# or more customizable with config.yaml
|
||||
execute(lmp_binary, config, input_test)
|
||||
|
||||
# process thermo output
|
||||
thermo = extract_thermo("log.lammps")
|
||||
|
||||
num_runs = len(thermo)
|
||||
if num_runs == 0:
|
||||
print(f"Failed with {input_test}\n")
|
||||
continue
|
||||
|
||||
print(f"Number of runs: {num_runs}")
|
||||
|
||||
# read in the thermo yaml output
|
||||
thermo_ref_file = 'thermo.' + input + '.yaml'
|
||||
thermo_ref = extract_thermo(thermo_ref_file)
|
||||
|
||||
# comparing output vs reference values
|
||||
width = 20
|
||||
print("Quantities".ljust(width) + "Output".center(width) + "Reference".center(width) + "Diff.".center(width))
|
||||
irun = 0
|
||||
num_fields = len(thermo[irun]['keywords'])
|
||||
for i in range(num_fields):
|
||||
val = thermo[irun]['data'][2][i]
|
||||
ref = thermo[0]['data'][2][i]
|
||||
diff = float(val) - float(ref)
|
||||
print(f"{thermo[0]['keywords'][i].ljust(width)} {str(val).rjust(20)} {str(ref).rjust(20)} {str(diff).rjust(20)}")
|
||||
print("-"*(4*width+3))
|
||||
|
||||
|
||||
|
||||
15
tools/regression-tests/thermo.in.lj.yaml
Normal file
15
tools/regression-tests/thermo.in.lj.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
keywords: ['Step', 'Temp', 'KinEng', 'PotEng', 'E_bond', 'E_angle', 'E_dihed', 'E_impro', 'E_vdwl', 'E_coul', 'E_long', 'Press', ]
|
||||
data:
|
||||
- [0, 1.44000000000001, 2.15993250000001, -6.77336805323422, 0, 0, 0, 0, -6.77336805323422, 0, 0, -5.01970725908556, ]
|
||||
- [10, 1.12539487029313, 1.68803955255514, -6.30005271976029, 0, 0, 0, 0, -6.30005271976029, 0, 0, -2.55968522600129, ]
|
||||
- [20, 0.625793798302192, 0.938661363368992, -5.55655653922756, 0, 0, 0, 0, -5.55655653922756, 0, 0, 0.973517658007722, ]
|
||||
- [30, 0.745927295413064, 1.11885597777762, -5.73951278150759, 0, 0, 0, 0, -5.73951278150759, 0, 0, 0.339284096694852, ]
|
||||
- [40, 0.731026217827733, 1.09650505988764, -5.71764564663628, 0, 0, 0, 0, -5.71764564663628, 0, 0, 0.388973418756238, ]
|
||||
- [50, 0.740091517740786, 1.11010258482128, -5.73150426762886, 0, 0, 0, 0, -5.73150426762886, 0, 0, 0.335273324523691, ]
|
||||
- [60, 0.750500641591031, 1.12571578266897, -5.74713299283555, 0, 0, 0, 0, -5.74713299283555, 0, 0, 0.26343139026926, ]
|
||||
- [70, 0.755436366857812, 1.13311913920702, -5.75480059117447, 0, 0, 0, 0, -5.75480059117447, 0, 0, 0.224276619217515, ]
|
||||
- [80, 0.759974280364828, 1.13992579675285, -5.76187162670983, 0, 0, 0, 0, -5.76187162670983, 0, 0, 0.191626237124102, ]
|
||||
- [90, 0.760464250735042, 1.14066072934081, -5.76280209529731, 0, 0, 0, 0, -5.76280209529731, 0, 0, 0.189478083345243, ]
|
||||
- [100, 0.757453103239936, 1.13614414924569, -5.75850548601596, 0, 0, 0, 0, -5.75850548601596, 0, 0, 0.207261053624723, ]
|
||||
...
|
||||
15
tools/regression-tests/thermo.in.rhodo.yaml
Normal file
15
tools/regression-tests/thermo.in.rhodo.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
keywords: ['Step', 'Temp', 'KinEng', 'PotEng', 'E_bond', 'E_angle', 'E_dihed', 'E_impro', 'E_vdwl', 'E_coul', 'E_long', 'Press', 'Volume', ]
|
||||
data:
|
||||
- [0, 299.039674593374, 21444.8312841477, -46801.0376681541, 2537.99401058653, 10921.3742085766, 5211.78649955145, 213.511585445475, -2307.86341545531, 207025.89272923, -270403.733286089, -149.330107246328, 307995.0335, ]
|
||||
- [20, 299.99775596386, 21513.5375298139, -46857.6878168353, 2540.16808710553, 10813.4472821057, 5184.14211975371, 221.342010137235, -2204.37204196886, 206976.604587209, -270389.019861177, 477.300972239503, 307985.712575511, ]
|
||||
- [40, 300.820676434129, 21572.5510726462, -46903.9535613665, 2554.70824060399, 10802.5198367863, 5193.55697621983, 227.543745597181, -2099.98472913888, 206823.579169277, -270405.876800712, 139.994267989278, 308012.644819437, ]
|
||||
- [60, 299.2331882218, 21458.7085969772, -46780.429323943, 2596.24317980854, 10780.8170148765, 5226.16290108029, 222.228413660505, -2104.75642217625, 206899.797834027, -270400.92224522, 127.22108251404, 308056.810003531, ]
|
||||
- [80, 300.46072237423, 21546.737928972, -46847.0583926036, 2536.59042271716, 10924.8018010137, 5186.04740702919, 222.7881900458, -2041.9411984891, 206726.747509985, -270402.092524906, -413.008542107374, 308097.593860177, ]
|
||||
- [100, 301.090606450347, 21591.9083825557, -46882.6386958151, 2567.98068348825, 10781.9571167463, 5198.74922392828, 216.786418763304, -1902.66178448095, 206659.522653541, -270404.973007801, 6.7406473046388, 308134.228503829, ]
|
||||
- [120, 300.685941196944, 21562.8888950994, -46837.9522831012, 2541.01730379153, 10831.9758258843, 5226.65101853851, 223.572832322853, -1975.83494841013, 206719.093753221, -270404.42806845, 428.656137442736, 308222.498901718, ]
|
||||
- [140, 298.380498037274, 21397.5601986261, -46664.8022666901, 2493.80367285064, 10925.8992265538, 5266.80649683893, 219.398357899592, -1911.54569787679, 206747.9911322, -270407.155455156, -173.318924696789, 308402.211640527, ]
|
||||
- [160, 297.736178370372, 21351.3545352186, -46582.6109596667, 2492.19606551665, 11004.0458067009, 5281.49837380749, 213.676293532578, -2047.52570313019, 206880.475440937, -270406.977237031, 42.9380783207654, 308627.866482533, ]
|
||||
- [180, 299.513482118553, 21478.8091248888, -46647.4003388357, 2471.17948439442, 11079.0862594569, 5266.33520079545, 227.130563582703, -2320.66315429553, 207032.450828902, -270402.919521672, 36.7672752293621, 308836.815084476, ]
|
||||
- [200, 300.804014463663, 21571.356203952, -46650.2048512757, 2488.69566833254, 11073.4385663243, 5221.75299737997, 232.855292128454, -2167.74358296738, 206902.920361046, -270402.124153519, 20.6683483419149, 308997.56038946, ]
|
||||
...
|
||||
Reference in New Issue
Block a user