Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
Implemented some caching of attributes in some classes
  • Loading branch information
henricasanova committed Dec 16, 2024
1 parent ee7744a commit f413684
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 27 deletions.
9 changes: 4 additions & 5 deletions tests/bare_metal_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

if __name__ == "__main__":


current_dir = pathlib.Path(__file__).parent.resolve()
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")

Expand All @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions tests/batch_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +44,7 @@
["BatchHost1", "BatchHost2"],
"/scratch",
{},
{"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024.0})
{"ServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD": 1024})

# Coverage
cs.get_name()
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 4 additions & 5 deletions tests/cloud_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/compound_job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ["/"])
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions tests/file_registry_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

if __name__ == "__main__":


current_dir = pathlib.Path(__file__).parent.resolve()
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")

Expand Down Expand Up @@ -61,5 +60,4 @@
frs.remove_entry(ss2, file1)
assert frs.lookup_entry(file1) == [], "Should not find entry in file registry service"


simulation.terminate()
2 changes: 1 addition & 1 deletion tests/simulation_events_test.py_DISABLED
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion tests/workflow_job_task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,5 @@
except wrench.WRENCHException as e:
pass


simulation.terminate()

2 changes: 1 addition & 1 deletion tests/workflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion wrench/bare_metal_compute_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from wrench.compute_service import ComputeService


# noinspection GrazieInspection
class BareMetalComputeService(ComputeService):
"""
WRENCH Bare Metal Compute Service class
Expand Down
5 changes: 4 additions & 1 deletion wrench/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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:
"""
Expand Down
20 changes: 16 additions & 4 deletions wrench/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,31 +103,39 @@ 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:
"""
Get the task's minimum number of required cores
: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:
"""
Get the task's maximum number of required cores
: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:
"""
Get the task's memory requirement
: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:
"""
Expand Down

0 comments on commit f413684

Please sign in to comment.