From fadd1b39291511753bba04c78c486d54a9de168b Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Fri, 30 Aug 2024 00:10:19 +0200 Subject: [PATCH] added eval diff with ref --- tests/create_database.py | 6 ++-- tests/lunch_bench.py | 61 ++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/tests/create_database.py b/tests/create_database.py index 55c5718..59cdee2 100644 --- a/tests/create_database.py +++ b/tests/create_database.py @@ -9,11 +9,11 @@ from feather_bench import FeatherBench # Save molecules to JSON -save_molecules_to_json(FeatherBench, 'FeatherBench.json') +#save_molecules_to_json(FeatherBench, 'FeatherBench.json') # Load molecules from JSON -loaded_molecules = load_molecules_from_json('FeatherBench.json') -print(loaded_molecules) +#loaded_molecules = load_molecules_from_json('FeatherBench.json') +#print(loaded_molecules) # Create a database and add molecules db_name = 'FeatherBench.db' diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py index 678a4fc..69a6093 100644 --- a/tests/lunch_bench.py +++ b/tests/lunch_bench.py @@ -57,9 +57,21 @@ parser.add_argument( default='light', help="Specify the type of data set: light (default), medium, or heavy." ) +parser.add_argument( + '-t', '--thresh', + type=float, + default=1e-8, + help='Threshold for acceptable difference (default: 1e-8)' +) + + + + args = parser.parse_args() +THRESH = args.thresh + if args.set_type == 'light': bench = 'FeatherBench' bench_title = "\n\nSelected Light Benchmark: {}\n\n".format(bench) @@ -106,11 +118,11 @@ class Quack_Job: spinner = ['|', '/', '-', '\\'] idx = 0 while not done_event.is_set(): - stdout_col(f'\r Testing {self.methd} ({self.basis}) {spinner[idx]}', "yellow") + stdout_col(f'\r Testing {self.methd} ({self.basis}) {spinner[idx]}', "cyan") sys.stdout.flush() idx = (idx + 1) % len(spinner) - time.sleep(0.1) - stdout_col(f'\r Testing {self.methd} ({self.basis}) ', "yellow") + time.sleep(0.05) + stdout_col(f'\r Testing {self.methd} ({self.basis}) \n', "cyan") done_event = threading.Event() spinner_thread = threading.Thread(target=display_spinner) @@ -147,7 +159,37 @@ class Quack_Job: done_event.set() spinner_thread.join() + + def check_data(self, data_ref): + filepath = '../test/Rtest.dat' + data_new = {} + try: + # read data_new + with open(filepath, 'r') as f: + lines = f.readlines() + for i in range(0, len(lines) - 1, 2): + key = lines[i].strip() + value = lines[i + 1].strip() + data_new[key] = float(value) # Convert value to float + + # Compare with data_ref + for key in data_ref: + if key not in data_new: + print_col(f" 😐 {key} missing ⚠ī¸ ", "yellow") + else: + diff = abs(data_new[key] - data_ref[key]) / (1e-15 + abs(data_ref[key])) + if(diff <= THRESH): + print_col(f" 🙂 {key}: ✔ī¸ ", "green") + else: + print_col(f" ☚ī¸ {key}: ❌ {data_ref[key]} ≠ {data_new[key]}", "red") + except FileNotFoundError: + print_col(f"Error: The file '{filepath}' does not exist.", "red") + sys.exist(1) + except Exception as e: + print_col(f"An error occurred: {str(e)}", "red") + sys.exist(1) + # --- @@ -169,35 +211,24 @@ def main(): for mol_prop_name, mol_prop_data in mol_data.items(): - #print_col(" Testing {}".format(mol_prop_name), "cyan") - methd = mol_prop_name[len('properties_'):] if(len(mol_prop_data) == 0): - #print_col(" {} is empty. Skipping...".format(mol_prop_name), "cyan") - #print() continue for basis_name, basis_data in mol_prop_data.items(): - #print_col(" Basis set: {}".format(basis_name), "yellow") if(len(basis_data) == 0): - #print_col(" {} is empty. Skipping...".format(basis_name), "yellow") - #print() continue work_methd = Path('{}/{}'.format(work_path, methd)) if not work_methd.exists(): work_methd.mkdir(parents=True, exist_ok=True) - #print(f"Directory '{work_methd}' created.\n") New_Quack_Job = Quack_Job(mol_name, mol_mult, basis_name, mol_geom, methd) New_Quack_Job.prep_inp() New_Quack_Job.run(work_path) - -# for name, val in basis_data.items(): -# print(f" name = {name}") -# print(f" val = {val}") + New_Quack_Job.check_data(basis_data) print() print()