@@ -37,7 +37,7 @@ def _init(self) -> None:
3737 def get_args (self ) -> typing .List [str ]:
3838 raise common .MFCException (f"MFCEngine::get_args: not implemented for { self .name } ." )
3939
40- def run (self , target_name : str ) -> None :
40+ def run (self , names : typing . List [ str ] ) -> None :
4141 raise common .MFCException (f"MFCEngine::run: not implemented for { self .name } ." )
4242
4343 def validate_job_options (self ) -> None :
@@ -78,7 +78,7 @@ def get_exec_cmd(self, target_name: str) -> typing.List[str]:
7878 return [self .mpibin .bin ] + self .mpibin .gen_params (self .mfc .args ) + flags + [binpath ]
7979
8080
81- def run (self , target_name : str ) -> None :
81+ def run (self , names : typing . List [ str ] ) -> None :
8282 if not self .bWorks :
8383 # Fix MFlowCode/MFC#21: Check whether attempting to run a job will hang
8484 # forever. This can happen when using the wrong queue system.
@@ -116,19 +116,19 @@ def run(self, target_name: str) -> None:
116116 + f"[bold magenta]Reason[/bold magenta]: { 'Time limit.' if p .is_alive () else 'Exit code.' } "
117117 )
118118
119+ for name in names :
120+ cons .print (f"[bold]Running [magenta]{ name } [/magenta][/bold]:" )
121+ cons .indent ()
119122
120- cons .print (f"Running [bold magenta]{ target_name } [/bold magenta]:" )
121- cons .indent ()
123+ if not self .mfc .args ["dry_run" ]:
124+ start_time = time .monotonic ()
125+ common .system (self .get_exec_cmd (name ), cwd = self .input .case_dirpath )
126+ end_time = time .monotonic ()
127+ cons .print (no_indent = True )
122128
123- if not self .mfc .args ["dry_run" ]:
124- start_time = time .monotonic ()
125- common .system (self .get_exec_cmd (target_name ), cwd = self .input .case_dirpath )
126- end_time = time .monotonic ()
127- cons .print (no_indent = True )
129+ cons .print (f"[bold green]Done[/bold green] (in { datetime .timedelta (seconds = end_time - start_time )} )" )
128130
129- cons .print (f"[bold green]Done[/bold green] (in { datetime .timedelta (seconds = end_time - start_time )} )" )
130-
131- cons .unindent ()
131+ cons .unindent ()
132132
133133 def validate_job_options (self , mfc ) -> None :
134134 if mfc .args ["nodes" ] != 1 :
@@ -150,19 +150,17 @@ def get_args(self) -> str:
150150Email (-@) { self .mfc .args ["email" ]}
151151"""
152152
153- def run (self , target_name : str ) -> None :
154- cons .print (f"Running [bold magenta]{ target_name } [/bold magenta]:" )
155- cons .indent ()
156-
153+ def run (self , names : typing .List [str ]) -> None :
157154 system = queues .get_system ()
158155 cons .print (f"Detected the [bold magenta]{ system .name } [/bold magenta] queue system." )
159156
160- self .__create_batch_file (system , target_name )
157+ cons .print (f"Running [bold magenta]{ common .format_list_to_string (names )} [/bold magenta]:" )
158+ cons .indent ()
159+
160+ self .__create_batch_file (system , names )
161161
162162 if not self .mfc .args ["dry_run" ]:
163- cons .print (no_indent = True )
164- self .__execute_batch_file (system , target_name )
165- cons .print (no_indent = True )
163+ self .__execute_batch_file (system , names )
166164
167165 cons .print ("[bold yellow]INFO:[/bold yellow] Batch file submitted! Please check your queue system for the job status." )
168166 cons .print ("[bold yellow]INFO:[/bold yellow] If an error occurs, please check the generated batch file and error logs for more information." )
@@ -173,16 +171,16 @@ def run(self, target_name: str) -> None:
173171 def __get_batch_dirpath (self ) -> str :
174172 return copy .copy (self .input .case_dirpath )
175173
176- def __get_batch_filename (self , target_name : str ) -> str :
177- return f"{ target_name } .sh"
174+ def __get_batch_filename (self , names : typing . List [ str ] ) -> str :
175+ return f"{ self . mfc . args [ 'name' ] } .sh"
178176
179- def __get_batch_filepath (self , target_name : str ):
177+ def __get_batch_filepath (self , names : typing . List [ str ] ):
180178 return os .path .abspath (os .sep .join ([
181179 self .__get_batch_dirpath (),
182- self .__get_batch_filename (target_name )
180+ self .__get_batch_filename (names )
183181 ]))
184182
185- def __generate_prologue (self , system : queues .QueueSystem ,) -> str :
183+ def __generate_prologue (self , system : queues .QueueSystem , names : typing . List [ str ] ) -> str :
186184 modules = f""
187185
188186 if common .does_system_use_modules ():
@@ -270,11 +268,11 @@ def __evaluate_expression(self, expr: str) -> str:
270268 except Exception as exc :
271269 raise common .MFCException (f"BatchEngine: { expr_original } (interpreted as { expr } ) is not a valid expression in the template file. Please check your spelling." )
272270
273- def __batch_evaluate (self , s : str , system : queues .QueueSystem , target_name : str ):
271+ def __batch_evaluate (self , s : str , system : queues .QueueSystem , names : typing . List [ str ] ):
274272 replace_list = [
275- ("{MFC::PROLOGUE}" , self .__generate_prologue (system )),
273+ ("{MFC::PROLOGUE}" , self .__generate_prologue (system , names )),
276274 ("{MFC::EPILOGUE}" , self .__generate_epilogue ()),
277- ("{MFC::BIN }" , self .get_binpath (target_name ))
275+ ("{MFC::BINARIES }" , ' ' . join ([ f"' { self .get_binpath (x ) } '" for x in names ] ))
278276 ]
279277
280278 for (key , value ) in replace_list :
@@ -298,27 +296,25 @@ def __batch_evaluate(self, s: str, system: queues.QueueSystem, target_name: str)
298296
299297 return s
300298
301- def __create_batch_file (self , system : queues .QueueSystem , target_name : str ):
302- cons .print ("> > Generating batch file..." )
303- filepath = self .__get_batch_filepath (target_name )
304- cons .print ("> > Evaluating template file..." )
305- content = self .__batch_evaluate (system .template , system , target_name )
299+ def __create_batch_file (self , system : queues .QueueSystem , names : typing . List [ str ] ):
300+ cons .print ("> Generating batch file..." )
301+ filepath = self .__get_batch_filepath (names )
302+ cons .print ("> Evaluating template file..." )
303+ content = self .__batch_evaluate (system .template , system , names )
306304
307- cons .print ("> > Writing batch file..." )
305+ cons .print ("> Writing batch file..." )
308306 common .file_write (filepath , content )
309307
310- def __execute_batch_file (self , system : queues .QueueSystem , target_name : str ):
308+ def __execute_batch_file (self , system : queues .QueueSystem , names : typing . List [ str ] ):
311309 # We CD to the case directory before executing the batch file so that
312310 # any files the queue system generates (like .err and .out) are created
313311 # in the correct directory.
314- cmd = system .gen_submit_cmd (self .__get_batch_filename (target_name ))
312+ cmd = system .gen_submit_cmd (self .__get_batch_filename (names ))
315313
316314 if common .system (cmd , cwd = self .__get_batch_dirpath ()) != 0 :
317315 raise common .MFCException (f"Submitting batch file for { system .name } failed. It can be found here: { self .__get_batch_filepath (target_name )} . Please check the file for errors." )
318316
319317 def validate_job_options (self , mfc ) -> None :
320- if len (mfc .args ["targets" ]) != 1 :
321- raise common .MFCException (f"The Batch engine requires a unique target (-t) to run." )
322318 pass
323319
324320
@@ -337,4 +333,3 @@ def get_engine(slug: str) -> Engine:
337333 raise common .MFCException (f"Unsupported engine { slug } ." )
338334
339335 return engine
340-
0 commit comments