From f4136840e34d46ac98eca3fda50a8323bc37c2c8 Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Mon, 16 Dec 2024 10:23:03 -1000 Subject: [PATCH] Some cleanup Implemented some caching of attributes in some classes --- tests/bare_metal_compute_service_test.py | 9 ++++----- tests/batch_compute_service_test.py | 6 +++--- tests/cloud_compute_service_test.py | 9 ++++----- tests/compound_job_test.py | 6 +++--- tests/file_registry_service_test.py | 2 -- tests/simulation_events_test.py_DISABLED | 2 +- tests/workflow_job_task_test.py | 1 - tests/workflow_test.py | 2 +- wrench/bare_metal_compute_service.py | 1 - wrench/file.py | 5 ++++- wrench/task.py | 20 ++++++++++++++++---- 11 files changed, 36 insertions(+), 27 deletions(-) diff --git a/tests/bare_metal_compute_service_test.py b/tests/bare_metal_compute_service_test.py index 0fd49ec..6aefcc3 100755 --- a/tests/bare_metal_compute_service_test.py +++ b/tests/bare_metal_compute_service_test.py @@ -15,7 +15,6 @@ if __name__ == "__main__": - current_dir = pathlib.Path(__file__).parent.resolve() platform_file_path = pathlib.Path(current_dir / "sample_platform.xml") @@ -42,7 +41,7 @@ "BatchHost2": (6, 12.0)}, "/scratch", {"BareMetalComputeServiceProperty::THREAD_STARTUP_OVERHEAD": "12s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) except wrench.WRENCHException as e: pass @@ -52,7 +51,7 @@ "BatchHost2": (6, 12.0)}, "/scratch", {"BareMetalComputeServiceProperty::THREAD_STARTUP_OVERHEAD": "12s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) # Coverage cs.get_name() @@ -132,9 +131,9 @@ # Trying a bogus job workflow1 = simulation.create_workflow() - t1 = workflow1.add_task("task", 10.0, 1, 2, 0.0) + t1 = workflow1.add_task("task", 10.0, 1, 2, 0) workflow2 = simulation.create_workflow() - t2 = workflow2.add_task("task", 10.0, 1, 2, 0.0) + t2 = workflow2.add_task("task", 10.0, 1, 2, 0) try: simulation.create_standard_job([t1, t2], {}) raise wrench.WRENCHException("Shouldn't be able to create a job with tasks from different workflows") diff --git a/tests/batch_compute_service_test.py b/tests/batch_compute_service_test.py index 297db53..8c7a852 100755 --- a/tests/batch_compute_service_test.py +++ b/tests/batch_compute_service_test.py @@ -34,7 +34,7 @@ ["BatchHost1", "CloudHost2"], "/scratch", {}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) raise wrench.WRENCHException("Shouldn't be able to create a bogus batch compute service") except wrench.WRENCHException as e: pass @@ -44,7 +44,7 @@ ["BatchHost1", "BatchHost2"], "/scratch", {}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) # Coverage cs.get_name() @@ -75,7 +75,7 @@ host = random.randint(1, 2) core = random.randint(1, 6) second = random.randint(5*60, 15*50) - service_specific_args = {"-N": str(host), "-c": str(core), "-t":str(second)} + service_specific_args = {"-N": str(host), "-c": str(core), "-t": str(second)} cs.submit_standard_job(job, service_specific_args) diff --git a/tests/cloud_compute_service_test.py b/tests/cloud_compute_service_test.py index 49cd1c8..c381fcb 100755 --- a/tests/cloud_compute_service_test.py +++ b/tests/cloud_compute_service_test.py @@ -32,7 +32,7 @@ ["CloudHost1_BOGUS", "CloudHost2"], "/scratch", {"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) raise wrench.WRENCHException("Shouldn't be able to create bogus cloud compute service") except wrench.WRENCHException as e: pass @@ -41,7 +41,7 @@ ["CloudHost1", "CloudHost2"], "/scratch", {"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) # Coverage ccs.get_name() @@ -55,14 +55,14 @@ try: bogus_my_vm = ccs.create_vm(1000, 100, {"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) raise wrench.WRENCHException("Should not be able to create a crazy VM") except wrench.WRENCHException as e: pass my_vm = ccs.create_vm(1, 100, {"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) my_vm.get_name() str(my_vm) repr(my_vm) @@ -138,7 +138,6 @@ except wrench.WRENCHException as e: pass - job = simulation.create_standard_job([task2], {}) vm_cs.submit_standard_job(job) event = simulation.wait_for_next_event() diff --git a/tests/compound_job_test.py b/tests/compound_job_test.py index 569d289..c40cc47 100755 --- a/tests/compound_job_test.py +++ b/tests/compound_job_test.py @@ -34,14 +34,14 @@ "CloudHost2": (6, 12.0)}, "/scratch", {"BareMetalComputeServiceProperty::THREAD_STARTUP_OVERHEAD": "12s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) bcs = simulation.create_batch_compute_service( "BatchHeadHost", ["BatchHost1", "BatchHost2"], "/scratch", {}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) # Create two storage service ss1 = simulation.create_simple_storage_service("StorageHost", ["/"]) @@ -120,7 +120,7 @@ assert sa.get_sleep_time() == 5.0, "SleepAction1 doesn't have the correct sleeptime" # Add a compute action to compound job - ca = cj.add_compute_action("ComputeAction1", 100.0, 0.0, 2, 1, ("AMDAHL", 0.8)) + ca = cj.add_compute_action("ComputeAction1", 100.0, 0, 2, 1, ("AMDAHL", 0.8)) ca.get_name() str(ca) repr(ca) diff --git a/tests/file_registry_service_test.py b/tests/file_registry_service_test.py index d617300..a33163e 100755 --- a/tests/file_registry_service_test.py +++ b/tests/file_registry_service_test.py @@ -15,7 +15,6 @@ if __name__ == "__main__": - current_dir = pathlib.Path(__file__).parent.resolve() platform_file_path = pathlib.Path(current_dir / "sample_platform.xml") @@ -61,5 +60,4 @@ frs.remove_entry(ss2, file1) assert frs.lookup_entry(file1) == [], "Should not find entry in file registry service" - simulation.terminate() diff --git a/tests/simulation_events_test.py_DISABLED b/tests/simulation_events_test.py_DISABLED index 97bf08d..71ec641 100755 --- a/tests/simulation_events_test.py_DISABLED +++ b/tests/simulation_events_test.py_DISABLED @@ -34,7 +34,7 @@ if __name__ == "__main__": "BatchHost2": (6, 12.0)}, "/scratch", {"BareMetalComputeServiceProperty::THREAD_STARTUP_OVERHEAD": "12s"}, - {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0}) + {"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024}) workflow = simulation.create_workflow() diff --git a/tests/workflow_job_task_test.py b/tests/workflow_job_task_test.py index e336b39..4dd6f15 100755 --- a/tests/workflow_job_task_test.py +++ b/tests/workflow_job_task_test.py @@ -145,6 +145,5 @@ except wrench.WRENCHException as e: pass - simulation.terminate() diff --git a/tests/workflow_test.py b/tests/workflow_test.py index 78a7e8d..49e71b6 100755 --- a/tests/workflow_test.py +++ b/tests/workflow_test.py @@ -96,7 +96,7 @@ f.close() workflow2 = simulation.create_workflow_from_json(wfcommons_json_workflow, "2", False, False, - False, 3.0, 3.0, False, + False, 3, 3, False, False, False) simulation.terminate() diff --git a/wrench/bare_metal_compute_service.py b/wrench/bare_metal_compute_service.py index db8159e..4359e3b 100644 --- a/wrench/bare_metal_compute_service.py +++ b/wrench/bare_metal_compute_service.py @@ -9,7 +9,6 @@ from wrench.compute_service import ComputeService -# noinspection GrazieInspection class BareMetalComputeService(ComputeService): """ WRENCH Bare Metal Compute Service class diff --git a/wrench/file.py b/wrench/file.py index 1a45a91..921f038 100644 --- a/wrench/file.py +++ b/wrench/file.py @@ -34,6 +34,7 @@ def __init__(self, simulation: Simulation, name: str) -> None: :type name: str """ super().__init__(simulation, name) + self.size = None def get_size(self) -> int: """ @@ -42,7 +43,9 @@ def get_size(self) -> int: :return: A number of bytes :rtype: int """ - return self._simulation._file_get_size(self) + if not self.size: + self.size = self._simulation._file_get_size(self) + return self.size; def __str__(self) -> str: """ diff --git a/wrench/task.py b/wrench/task.py index 7a59855..6826f7d 100644 --- a/wrench/task.py +++ b/wrench/task.py @@ -40,6 +40,10 @@ def __init__(self, simulation: Simulation, workflow: Workflow, name: str) -> Non """ self.workflow = workflow super().__init__(simulation, name) + self.flops = None + self.min_num_cores = None + self.max_num_cores = None + self.memory = None class TaskState(Enum): NOT_READY = 0 @@ -99,7 +103,9 @@ def get_flops(self) -> float: :return: A number of flops :rtype: float """ - return self._simulation._task_get_flops(self) + if not self.flops: + self.flops = self._simulation._task_get_flops(self) + return self.flops def get_min_num_cores(self) -> int: """ @@ -107,7 +113,9 @@ def get_min_num_cores(self) -> int: :return: A number of cores :rtype: integer """ - return self._simulation._task_get_min_num_cores(self) + if not self.min_num_cores: + self.min_num_cores = self._simulation._task_get_min_num_cores(self) + return self.min_num_cores def get_max_num_cores(self) -> int: """ @@ -115,7 +123,9 @@ def get_max_num_cores(self) -> int: :return: A number of cores :rtype: integer """ - return self._simulation._task_get_max_num_cores(self) + if not self.max_num_cores: + self.max_num_cores = self._simulation._task_get_max_num_cores(self) + return self.max_num_cores def get_memory(self) -> int: """ @@ -123,7 +133,9 @@ def get_memory(self) -> int: :return: A memory size in bytes :rtype: int """ - return self._simulation._task_get_memory(self) + if not self.memory: + self.memory = self._simulation._task_get_memory(self) + return self.memory def get_number_of_children(self) -> int: """