From 1957eb5ca853293d5b0b3b5531a08ede2af2e487 Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Fri, 8 Dec 2023 10:21:35 -0600 Subject: [PATCH 1/2] Attempted to change dir to individual example folders --- tools/regression-tests/run_tests.py | 77 ++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/tools/regression-tests/run_tests.py b/tools/regression-tests/run_tests.py index b6ac0e4a5e..60170410cb 100644 --- a/tools/regression-tests/run_tests.py +++ b/tools/regression-tests/run_tests.py @@ -49,7 +49,7 @@ except ImportError: inputFileName: input file with comments #REG:ADD and #REG:SUB as markers outputFileName: modified input file ready for testing ''' -def processing_markers(inputFileName, outputFileName): +def process_markers(inputFileName, outputFileName): # read in the script with open(inputFileName, 'r') as file: data = file.read() @@ -122,16 +122,57 @@ def execute(lmp_binary, config, input_file_name, generate_ref_yaml=False): p = subprocess.run(cmd_str, shell=True, text=True, capture_output=True) output = p.stdout.split('\n') + +''' + attempt to plug in the REG markers before each run command + #REG:ADD thermo 10 + #REG:ADD thermo_style yaml +''' + +def generate_markers(inputFileName, outputFileName): + # read in the script + with open(inputFileName, 'r') as file: + data = file.read() + + lines = data.splitlines() + out = [] + for line in lines: + s = line.split() + if len(s) > 0: + if s[0] == "run": + out.append(" #REG:ADD thermo 10") + out.append(" #REG:ADD thermo_style yaml") + out.append(line) + + # write data to the new script + with open(outputFileName, 'w') as file: + for line in out: + file.write(line + "\n") + ''' Iterate over a list of input files ''' -def iterate(input_list): +def iterate(input_list, input_has_markers=False): num_tests = len(input_list) test_id = 0 # iterative over the input scripts for input in input_list: - input_test=input + '.test' - processing_markers(input, input_test) + input_test = input + '.test' + + if input_has_markers == False: + input_markers = input + '.markers' + # if the .test file with the REG markers does not exist + # attempt to plug in the REG markers before each run command + if os.path.isfile(input_markers) == False: + + cmd_str = "cp " + input + " " + input_markers + os.system(cmd_str) + generate_markers(input, input_markers) + process_markers(input_markers, input_test) + else: + process_markers(input, input_test) + + # input.test should be ready for testing without markers but with the inserted thermo lines str_t = "\nRunning " + input_test + f" ({test_id+1}/{num_tests})" print(str_t) @@ -172,7 +213,7 @@ def iterate(input_list): print(f"nthermo_steps = {nthermo_steps}") for i in range(num_fields): val = thermo[irun]['data'][thermo_step][i] - ref = thermo_ref[0]['data'][thermo_step][i] + ref = thermo_ref[irun]['data'][thermo_step][i] diff = abs(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)) @@ -225,9 +266,29 @@ if __name__ == "__main__": # list of input scripts with markers #REG:SUB and #REG:ADD input_list=['in.lj', 'in.rhodo', 'in.eam'] - iterate(input_list) + iterate(input_list, input_has_markers=True) + automated = False + if automated == True: + # save current working dir + p = subprocess.run("pwd", shell=True, text=True, capture_output=True) + pwd = p.stdout.split('\n')[0] + print("Working dir" + pwd) - - + # change dir to an example + directory = "../../examples/melt" + print("Entering " + directory) + os.chdir(directory) + # create a symbolic link to the lammps binary at the present directory + cmd_str = "ln -s " + lmp_binary + " lmp" + os.system(cmd_str) + input_list=['in.melt'] + + iterate(input_list, input_has_markers=False) + # unlink the symbolic link + cmd_str = "unlink lmp" + os.system(cmd_str) + # get back to the working dir + cmd_str = "cd " + pwd + os.system(cmd_str) \ No newline at end of file From a6f82eb97052b1ec90b5508764375aaa0656e101 Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Sun, 10 Dec 2023 14:15:13 -0600 Subject: [PATCH 2/2] Added check if input files in a folder have REG markers --- tools/regression-tests/run_tests.py | 47 ++++++++++++++++++----------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/tools/regression-tests/run_tests.py b/tools/regression-tests/run_tests.py index 60170410cb..6d72c01b02 100644 --- a/tools/regression-tests/run_tests.py +++ b/tools/regression-tests/run_tests.py @@ -149,29 +149,40 @@ def generate_markers(inputFileName, outputFileName): for line in out: file.write(line + "\n") +def has_markers(input): + with open(input) as f: + if '#REG' in f.read(): + return True + return False + ''' Iterate over a list of input files ''' -def iterate(input_list, input_has_markers=False): +def iterate(input_list): num_tests = len(input_list) test_id = 0 # iterative over the input scripts for input in input_list: input_test = input + '.test' + + if os.path.isfile(input) == True: + if has_markers(input): + process_markers(input, input_test) + + else: + print("Input {input} does not have REG markers") + continue - if input_has_markers == False: - input_markers = input + '.markers' - # if the .test file with the REG markers does not exist - # attempt to plug in the REG markers before each run command - if os.path.isfile(input_markers) == False: - - cmd_str = "cp " + input + " " + input_markers - os.system(cmd_str) - generate_markers(input, input_markers) - process_markers(input_markers, input_test) - else: - process_markers(input, input_test) - + input_markers = input + '.markers' + # if the .test file with the REG markers does not exist + # attempt to plug in the REG markers before each run command + if os.path.isfile(input_markers) == False: + + cmd_str = "cp " + input + " " + input_markers + os.system(cmd_str) + generate_markers(input, input_markers) + process_markers(input_markers, input_test) + # input.test should be ready for testing without markers but with the inserted thermo lines str_t = "\nRunning " + input_test + f" ({test_id+1}/{num_tests})" @@ -265,10 +276,10 @@ if __name__ == "__main__": print(f"List of installed packages: {packages}") # list of input scripts with markers #REG:SUB and #REG:ADD - input_list=['in.lj', 'in.rhodo', 'in.eam'] - iterate(input_list, input_has_markers=True) + #input_list=['in.lj', 'in.rhodo', 'in.eam'] + #iterate(input_list) - automated = False + automated = True if automated == True: # save current working dir p = subprocess.run("pwd", shell=True, text=True, capture_output=True) @@ -284,7 +295,7 @@ if __name__ == "__main__": os.system(cmd_str) input_list=['in.melt'] - iterate(input_list, input_has_markers=False) + iterate(input_list) # unlink the symbolic link cmd_str = "unlink lmp"