@@ -38,14 +38,14 @@ def __init__(self,
3838 self .tasks_futures = {}
3939 self .task_id = 0
4040
41- def translate (self , output_file_name : pathlib .Path ) -> None :
41+ def translate (self , output_folder : pathlib .Path ) -> None :
4242 """
43- Translate a workflow benchmark description (WfFormat) into a Dask workflow application.
43+ Translate a workflow benchmark description (WfFormat) into an actual workflow application.
4444
45- :param output_file_name : The name of the output file (e.g., workflow.py) .
46- :type output_file_name : pathlib.Path
45+ :param output_folder : The path to the folder in which the workflow benchmark will be generated .
46+ :type output_folder : pathlib.Path
4747 """
48- noindent_python_codelines = self ._dask_wftasks_codelines ("randomizer" )
48+ noindent_python_codelines = self ._dask_wftasks_codelines ("randomizer" , output_folder )
4949
5050 for task_name in self .root_task_names :
5151 noindent_python_codelines .extend (self ._parse_tasks (task_name ))
@@ -61,30 +61,53 @@ def translate(self, output_file_name: pathlib.Path) -> None:
6161 with open (this_dir .joinpath ("templates/dask_template.py" )) as fp :
6262 run_workflow_code = fp .read ()
6363 run_workflow_code = run_workflow_code .replace ("# Generated code goes here" , wf_codelines )
64- with open ("dask_workflow.py" , "w" ) as fp :
64+
65+ # write benchmark files
66+ output_folder .mkdir (parents = True )
67+ with open (output_folder .joinpath ("dask_workflow.py" ), "w" ) as fp :
6568 fp .write (run_workflow_code )
69+
70+ # additional files
71+ self ._copy_binary_files (output_folder )
72+ self ._generate_input_files (output_folder )
6673
6774 def _dask_wftasks_codelines (self ,
6875 randomizer_varname : str ,
76+ output_folder : pathlib .Path ,
6977 simulate_minimum_execution_time : float = 0.1 ,
7078 simulate_maximum_execution_time : float = 1.1 ) -> list [str ]:
7179 """
7280 Build the code definining all tasks in the workflow, i.e. WorkflowTask instances.
7381
7482 :param randomizer_varname: The name of the randomizer.
7583 :type randomizer_varname: str
84+ :param output_folder: The path to the folder in which the workflow benchmark will be generated.
85+ :type output_folder: pathlib.Path
7686
7787 :return: The non-indented Python lines of code used to instantiate the WorkflowTask instances.
7888 :rtype: list[str]
7989 """
8090 codelines = ["randomizer = random.Random(seed)" ,
8191 "TASKS = {}" ]
8292 for task in self .tasks .values ():
83- input_files = [f .name for f in task .files if f .link == FileLink .INPUT ]
84- output_files = [f .name for f in task .files if f .link == FileLink .OUTPUT ]
93+ input_files = [str (output_folder .joinpath (f"data/{ f .name } " )) for f in task .files if f .link == FileLink .INPUT ]
94+ output_files = [str (output_folder .joinpath (f"data/{ f .name } " )) for f in task .files if f .link == FileLink .OUTPUT ]
95+ program = output_folder .joinpath (f'bin/{ task .program } ' )
96+ args = []
97+ print (task .args )
98+ for a in task .args :
99+ if "--out" in a :
100+ a = a .replace ("{" , "\" {" ).replace ("}" , "}\" " ).replace (".txt'" , ".txt\\ \\ \" " ).replace ("'" , "\\ \\ \" " + str (output_folder .joinpath ("data" )) + "/" ).replace (": " , ":" )
101+ elif "--" not in a :
102+ a = str (output_folder .joinpath ("data" , a ))
103+ else :
104+ a = a .replace ("'" , "\" " )
105+ args .append (a )
106+ print (args )
107+ print ("" )
85108 code = [f"WorkflowTask(dag_id = '{ task .name } '," ,
86109 f" name = '{ task .name } '," ,
87- f" command_arguments = { [task . program ] + task . args } ," ,
110+ f" command_arguments = { [str ( program ) ] + args } ," ,
88111 f" inputs = { input_files } ," ,
89112 f" outputs = { output_files } ," ,
90113 " simulate = simulate," ,
@@ -94,6 +117,7 @@ def _dask_wftasks_codelines(self,
94117 " )" ]
95118 codelines .append (f"TASKS['{ task .name } '] = { code [0 ]} " )
96119 codelines .extend ([codeline for codeline in code [1 :]])
120+ # exit(1)
97121 return codelines
98122
99123 def _parse_tasks (self , task_name : str ) -> list [str ]:
@@ -115,7 +139,7 @@ def _parse_tasks(self, task_name: str) -> list[str]:
115139 self .parsed_tasks .append (task_name )
116140 self .tasks_futures [task_name ] = f"fut_dv_{ self .task_id } "
117141 self .task_id += 1
118- noindent_python_codelines = [f"{ self .tasks_futures [task_name ]} = client.submit(execute_task, TASKS['{ task_name } '], [] )" ]
142+ noindent_python_codelines = [f"{ self .tasks_futures [task_name ]} = client.submit(execute_task, TASKS['{ task_name } '], { self . task_parents [ task_name ] } )" ]
119143
120144 # parse children
121145 for child in self .task_children [task_name ]:
0 commit comments