@@ -116,7 +116,6 @@ def get_running_jobs_torque(job_pattern: str, target_system: Optional[TARGET_SYS
116
116
list of job names that are currently running
117
117
118
118
"""
119
- # job_pattern = (VP_\w+)
120
119
qstat = _check_command_for_target_system ("qstat" , target_system )
121
120
out = subprocess .check_output (qstat ).decode ("utf-8" )
122
121
return re .findall (rf"\S* { job_pattern } \s*\w+\s*\S*\s*R" , out )
@@ -136,10 +135,8 @@ def get_running_jobs_slurm(job_pattern: str):
136
135
list of job names that are currently running
137
136
138
137
"""
139
- # job_pattern = (VP_\w+)
140
- # out = subprocess.check_output("squeue").decode("utf-8")
141
- # return re.findall(rf"\S* {job_pattern}\s*\w+\s*\S*\s*R", out)
142
- raise NotImplementedError ("Not implemented yet!" )
138
+ out = subprocess .check_output ("squeue" ).decode ("utf-8" )
139
+ return re .findall (rf"\d+\s*\w+\s*{ job_pattern } \s*\w+\s*R\S*" , out )
143
140
144
141
145
142
def build_job_submit_torque (
@@ -200,13 +197,19 @@ def build_job_submit_torque(
200
197
return qsub_command
201
198
202
199
200
+ def _check_partition_slurm (partition : str , gres : str ):
201
+ if partition in ("v100" , "a100" ):
202
+ assert partition in gres
203
+
204
+
203
205
def build_job_submit_slurm (
204
206
job_name : str ,
205
207
script_name : str ,
206
208
target_system : Optional [TARGET_SYSTEM ] = "woody" ,
207
209
nodes : Optional [int ] = 1 ,
208
210
tasks_per_node : Optional [int ] = 4 ,
209
211
gres : Optional [str ] = "gpu:1" ,
212
+ partition : Optional [str ] = None ,
210
213
walltime : Optional [str ] = "24:00:00" ,
211
214
mail_type : Optional [Literal ["BEGIN" , "END" , "FAIL" , "ALL" ]] = "ALL" ,
212
215
args : Optional [Sequence [str ]] = None ,
@@ -231,6 +234,8 @@ def build_job_submit_slurm(
231
234
gres : str, optional
232
235
configuration of requested GPUs (for tinygpu)
233
236
Default: "gpu:1" (for tinygpu)
237
+ partition : str, optional
238
+ partition for tinygpu when specific nodes (e.g., A100 or V100) are requested.
234
239
walltime : str, optional
235
240
required wall clock time (runtime) in the format ``HH:MM:SS``.
236
241
Default: "24:00:00" (24 hours)
@@ -251,8 +256,13 @@ def build_job_submit_slurm(
251
256
252
257
"""
253
258
sbatch = _check_command_for_target_system ("sbatch" , target_system = target_system )
254
- sbatch_command = f"{ sbatch } --job-name { job_name } --nodes={ nodes } --ntasks-per-node={ tasks_per_node } "
259
+ sbatch_command = f"{ sbatch } --job-name { job_name } "
260
+ if target_system != "tinygpu" :
261
+ sbatch_command += f"--nodes={ nodes } --ntasks-per-node={ tasks_per_node } "
255
262
if target_system == "tinygpu" :
263
+ if partition is not None :
264
+ _check_partition_slurm (partition , gres )
265
+ sbatch_command += f"--partition={ partition } "
256
266
sbatch_command += f"--gres={ gres } "
257
267
sbatch_command += f"--time={ walltime } --mail-type={ mail_type } { script_name } "
258
268
@@ -300,16 +310,22 @@ def _add_arguments_torque(command_str: str, args: Optional[Sequence[str]] = None
300
310
301
311
def _add_arguments_slurm (command_str : str , args : Optional [Sequence [str ]] = None , ** kwargs ) -> str :
302
312
if len (kwargs ) != 0 or args is not None :
313
+ command_str += "--export="
303
314
if args is not None :
304
315
command_str += 'PARAMS="'
305
316
for arg in args :
306
317
command_str += f"{ arg } "
307
- command_str = command_str .strip ()
308
- command_str += '" '
318
+ command_str = command_str .strip () + '"'
319
+ if len (kwargs ) != 0 :
320
+ command_str += ","
309
321
if len (kwargs ) != 0 :
310
322
for key , value in kwargs .items ():
311
- command_str += f" { key } ={ value } ,"
312
- # remove the last comma
313
- command_str = command_str [:- 1 ]
323
+ command_str += f' { key } =" { value } ",'
324
+ # remove the last comma and add the quote again
325
+ command_str = command_str [:- 2 ] + '"'
314
326
315
327
return command_str .strip ()
328
+
329
+
330
+ if __name__ == "__main__" :
331
+ print (build_job_submit_slurm ("VP_01" , "jobscript.sh" , "tinygpu" , BASE_PATH = "hello" , SUBJECT_ID = "VP_01" ))
0 commit comments