Skip to content

Commit 2fa2dc6

Browse files
committed
JSON workflow creation with value caching for speed
1 parent 5cc180f commit 2fa2dc6

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

wrench/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class File(SimulationItem):
2424
WRENCH File class
2525
"""
2626

27-
def __init__(self, simulation: Simulation, name: str) -> None:
27+
def __init__(self, simulation: Simulation, name: str, size: number = None) -> None:
2828
"""
2929
Constructor
3030
@@ -34,7 +34,7 @@ def __init__(self, simulation: Simulation, name: str) -> None:
3434
:type name: str
3535
"""
3636
super().__init__(simulation, name)
37-
self.size = None
37+
self.size = size
3838

3939
def get_size(self) -> int:
4040
"""

wrench/simulation.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# the Free Software Foundation, either version 3 of the License, or
88
# (at your option) any later version.
99

10+
import sys
1011
import atexit
1112
import json
1213
import pathlib
@@ -262,7 +263,7 @@ def add_file(self, name: str, size: int) -> File:
262263

263264
response = r.json()
264265
if response["wrench_api_request_success"]:
265-
new_file = File(self, name)
266+
new_file = File(self, name, size)
266267
self.files[name] = new_file
267268
return new_file
268269
raise WRENCHException(response["failure_cause"])
@@ -509,20 +510,35 @@ def create_workflow_from_json(self, json_object: json, reference_flop_rate: str,
509510
"ignore_avg_cpu": ignore_avg_cpu,
510511
"show_warnings": show_warnings}
511512

513+
sys.stderr.write("HERE\n")
514+
512515
r = self.__send_request_to_daemon(requests.post, f"{self.daemon_url}/{self.simid}/createWorkflowFromJSON",
513516
json_data=data)
514517
response = r.json()
515518

516519
# Create the workflow
517520
workflow = Workflow(self, response["workflow_name"])
518521

522+
sys.stderr.write("CREATING TASKS\n")
519523
# Create the tasks
520-
for task_name in response["tasks"]:
521-
workflow.tasks[task_name] = Task(self, workflow, task_name)
524+
for task_spec in response["tasks"]:
525+
task_name = task_spec["name"]
526+
task_flops = task_spec["flops"]
527+
task_min_num_cores = task_spec["min_num_cores"]
528+
task_max_num_cores = task_spec["max_num_cores"]
529+
task_memory = task_spec["memory"]
530+
workflow.tasks[task_name] = Task(self, workflow, task_name, task_flops, task_min_num_cores, task_max_num_cores, task_memory)
531+
522532

523533
# Create the files
524-
for file_name in response["files"]:
525-
self.files[file_name] = File(self, file_name)
534+
sys.stderr.write("CREATING FILES\n")
535+
print(response["files"])
536+
for file_spec in response["files"]:
537+
file_name = file_spec["name"]
538+
file_size = file_spec["size"]
539+
sys.stderr.write(f"---> {file_name}: {file_size}\n")
540+
self.files[file_name] = File(self, file_name, file_size)
541+
sys.stderr.write("CREATED FILES\n")
526542

527543
return workflow
528544

@@ -1572,7 +1588,7 @@ def _workflow_create_task(self, workflow: Workflow, name: str, flops: float, min
15721588

15731589
response = r.json()
15741590
if response["wrench_api_request_success"]:
1575-
workflow.tasks[name] = Task(self, workflow, name)
1591+
workflow.tasks[name] = Task(self, workflow, name, flops, min_num_cores, max_num_cores, memory)
15761592
return workflow.tasks[name]
15771593
raise WRENCHException(response["failure_cause"])
15781594

wrench/task.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class Task(SimulationItem):
2828
WRENCH Task class
2929
"""
3030

31-
def __init__(self, simulation: Simulation, workflow: Workflow, name: str) -> None:
31+
def __init__(self, simulation: Simulation, workflow: Workflow, name: str,
32+
flops: flops = None,
33+
min_num_cores: number = None,
34+
max_num_cores: number = None,
35+
memory: number = None) -> None:
3236
"""
3337
Constructor
3438
:param simulation: simulation object
@@ -40,10 +44,10 @@ def __init__(self, simulation: Simulation, workflow: Workflow, name: str) -> Non
4044
"""
4145
self.workflow = workflow
4246
super().__init__(simulation, name)
43-
self.flops = None
44-
self.min_num_cores = None
45-
self.max_num_cores = None
46-
self.memory = None
47+
self.flops = flops
48+
self.min_num_cores = min_num_cores
49+
self.max_num_cores = max_num_cores
50+
self.memory = memory
4751
self.input_files = None
4852
self.output_files = None
4953

0 commit comments

Comments
 (0)