From c7130e7c8a948ef09944273fa03c826d9be65694 Mon Sep 17 00:00:00 2001 From: Caleb Schilly <132086024+cwschilly@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:22:44 -0400 Subject: [PATCH] #533: Add test cases for communication alone and mixed compute-communication case (#541) * #533: initial commit; add new tests for synthetic blocks dataset * #533: update with more changes * #533: update tests to use W_max instead of of load imbalance * #533: set BFO to false; increase n_iterations * #533: update logic to avoid writing configuration files * #533: loosen constraints on W_max in tests --- tests/acceptance/test_permutations.py | 2 +- tests/acceptance/test_synthetic_blocks.py | 116 ++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/test_synthetic_blocks.py diff --git a/tests/acceptance/test_permutations.py b/tests/acceptance/test_permutations.py index d5ad62be..f3277a3b 100644 --- a/tests/acceptance/test_permutations.py +++ b/tests/acceptance/test_permutations.py @@ -46,7 +46,7 @@ def generate_configuration(self, alpha, beta, gamma, permutation): "output_file_stem": "output_file" } - # Return the path to the config file + # Return the configuration return config def run_test(self, config, test_case, expected_w_max): diff --git a/tests/acceptance/test_synthetic_blocks.py b/tests/acceptance/test_synthetic_blocks.py new file mode 100644 index 00000000..64e50244 --- /dev/null +++ b/tests/acceptance/test_synthetic_blocks.py @@ -0,0 +1,116 @@ +import os +import unittest + +from src.lbaf.Applications.LBAF_app import LBAFApplication + +class TestSyntheticBlocksLB(unittest.TestCase): + """Class to run acceptance tests""" + + def setUp(self): + return + + def tearDown(self): + return + + def generate_configuration(self, alpha, beta, gamma): + """Creates and returns the path to a YAML configuration file.""" + # Determine filepaths + acceptance_dir = os.path.dirname(__file__) + test_dir = os.path.dirname(acceptance_dir) + data_dir = os.path.join(os.path.dirname(test_dir), "data") + + # Create YAML configuration + config = { + "from_data": { + "data_stem": f"{data_dir}/synthetic-blocks/synthetic-dataset-blocks", + "phase_ids": [0] + }, + "work_model": { + "name": "AffineCombination", + "parameters": { + "alpha": alpha, + "beta": beta, + "gamma": gamma + } + }, + "brute_force_optimization": False, + "algorithm": { + "name": "InformAndTransfer", + "phase_id": 0, + "parameters": { + "n_iterations": 10, + "n_rounds": 2, + "fanout": 2, + "order_strategy": "element_id", + "transfer_strategy": "Recursive", + "criterion": "Tempered", + "max_objects_per_transfer": 8, + "deterministic_transfer": True + } + }, + "logging_level": "info", + "output_dir": os.path.join(acceptance_dir, "output"), + "output_file_stem": "output_file" + } + + # Return the configuration + return config + + def run_test(self, config, test_case, expected_w_max): + """Compare LBAF's results to the expected imbalance.""" + # Determine current directory + acceptance_dir = os.path.dirname(__file__) + + # Run LBAF + lbaf = LBAFApplication() + lbaf.run(cfg=config, cfg_dir=acceptance_dir) + + # Check w_max file exists + output_dir = os.path.join(acceptance_dir, "output") + imbalance_filepath = os.path.join(output_dir, "imbalance.txt") + w_max_filepath = os.path.join(output_dir, "w_max.txt") + self.assertTrue(os.path.isfile(w_max_filepath), f"File: {w_max_filepath} does not exist!") + + # Validate w_max value + with open(w_max_filepath, 'r', encoding="utf-8") as w_max_file: + w_max = float(w_max_file.read()) + self.assertLessEqual(w_max, expected_w_max, f"@@@@@ [{test_case}] FOUND W_MAX: {w_max} @@@@@") + + # Clean up + os.remove(w_max_filepath) + os.remove(imbalance_filepath) + + def test_synthetic_blocks_lb(self): + # Initialize test cases + test_cases = { + "load_only": { + "alpha": 1.0, + "beta": 0.0, + "gamma": 0.0, + "W_max": 2.5 # optimum is 2.0, but accept <= 2.5 + }, + "off_node_communication_only": { + "alpha": 0.0, + "beta": 1.0, + "gamma": 0.0, + "W_max": 0.0 + }, + "load+off_node_communication": { + "alpha": 1.0, + "beta": 1.0, + "gamma": 0.0, + "W_max": 4.5 # optimum is 4.0, but accept <= 4.5 + } + } + + for test_case, test_params in test_cases.items(): + cfg = self.generate_configuration( + alpha=test_params["alpha"], + beta=test_params["beta"], + gamma=test_params["gamma"] + ) + self.run_test(cfg, test_case, test_params["W_max"]) + + +if __name__ == "__main__": + unittest.main()