-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubmit.py
More file actions
85 lines (59 loc) · 2.33 KB
/
submit.py
File metadata and controls
85 lines (59 loc) · 2.33 KB
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
76
77
78
79
80
81
82
83
84
85
""" A python script to submit to the qsub queue. """
import sys
import os
from optparse import OptionParser
from subprocess import call
DEF_QUEUE = 'exe-x86_64'
def encode_envlist(d):
return ','.join('%s=%s' % (key, item) for key, item in d.iteritems())
def submit(ifile, queue, onlyprint=False):
mypath = os.path.split(os.path.realpath(sys.argv[0]))[0]
ipath = os.path.split(os.path.realpath(ifile))[0]
env = encode_envlist(dict(FMM_INPUT_FILE=os.path.join(ipath, ifile),
FMM_PATH=mypath))
runid = os.path.splitext(os.path.basename(ifile))[0]
script = os.path.join(mypath, 'qrun.sh')
args = {'-N': runid,
'-j': 'oe',
'-q': queue,
'-o': 'localhost:%s' % os.path.join(ipath, runid + '.out'),
'-v': env}
cmd = ('qsub %s %s'
% (' '.join('%s %s' % (key, item)
for key, item in args.iteritems()),
script))
if not onlyprint:
call(cmd, shell=True)
else:
print(cmd)
def completed(ifile):
runid = os.path.splitext(os.path.basename(ifile))[0]
ipath = os.path.split(os.path.realpath(ifile))[0]
ofile = os.path.join(ipath, runid + '.h5')
if not os.path.exists(ofile):
return False
itime, otime = [os.stat(f).st_mtime for f in ifile, ofile]
if otime > itime:
return True
return False
def main():
parser = OptionParser()
parser.add_option("--queue", "-q", dest="queue", type="str",
help="Queue to submit to", default=DEF_QUEUE)
parser.add_option("--check-completed", "-c", dest="check",
action="store_true",
help="Check for a .h5 file to see if the code has already run",
default=False)
parser.add_option("--only-print", "-p", dest="onlyprint",
action="store_true",
help="Just print commands, do nothing.",
default=False)
(opts, args) = parser.parse_args()
for ifile in args:
if opts.check and completed(ifile):
print("Skipping %s due to an existing and newer .h5 file"
% ifile)
continue
submit(ifile, queue=opts.queue, onlyprint=opts.onlyprint)
if __name__ == '__main__':
main()