forked from lkwagner/autogenv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitter.py
76 lines (69 loc) · 2.4 KB
/
submitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import subprocess as sub
import importlib
import os
import shutil
import sys
import time
#####################################################################################
class LocalSubmitter:
"""Abstract submission class. Defines interaction with queuing system (for
nonqueuing defines how to execute jobs). Child classes must define:
__init__:
can have any parameters, but should set up any variables like queue time and number of
processor cores
_submit_job(self,
inpfns : list of input filenames (list of strings)
outfn : where stdout should be sent (string)
jobname : job name for the queue (string)
loc : directory where job should be run (string)
)
returns a list of queue ids (list of strings)
"""
#-------------------------------------------------------
def _qsub(self,exe,prep_commands=[],final_commands=[],
name="",stdout="runstdout",loc=""):
""" Helper function for executable submitters.
Should work in most cases to simplify code."""
if loc=="": loc=os.getcwd()
if name=="": name=loc
header = []
exeline = exe
commands = header + prep_commands + [exeline] + final_commands
outstr = ""
for c in commands:
print(c)
sub.call(c,stdout=open(stdout,'w'),shell=True)
return []
#-------------------------------------------------------
def check_PBS_status(queueid):
"""Utility function to determine the status of a PBS job."""
try:
qstat = sub.check_output(
"qstat %s"%queueid, stderr=sub.STDOUT, shell=True
).decode().split('\n')[-2].split()[4]
except sub.CalledProcessError:
return "unknown"
if qstat == "R" or qstat == "Q":
return "running"
if qstat == "C" or qstat == "E":
return "finished"
return 'unknown'
#-------------------------------------------------------
def check_PBS_stati(queueid):
"""Utility function to determine the status of a set PBS job.
Can be done with one qstat call which can improve speed."""
try:
qstat = sub.check_output(
"qstat ", stderr=sub.STDOUT, shell=True
).decode()
except sub.CalledProcessError:
return "unknown"
qstat=qstat.split('\n')
for qid in queueid:
for line in qstat:
spl=line.split()
if qid in line and len(spl) > 4:
stat=line.split()[4]
if stat == "R" or stat == "Q":
return "running"
return 'unknown'