-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.py
63 lines (45 loc) · 1.41 KB
/
submit.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
import argparse
import logging
import os
import subprocess
logging.basicConfig(level='INFO', format='[%(name)s] %(levelname)s %(message)s')
log = logging.getLogger('submit.py')
def get_args():
argp = argparse.ArgumentParser()
argp.add_argument('--name', required=True)
argp.add_argument('--script', default='/dev/stdin')
argp.add_argument('--datapath')
return argp.parse_args()
def launch(name, script, datapath):
dirp = os.path.dirname(os.path.realpath(__file__))
job_cmd = '{}\n{}\n{}'.format(
open(dirp + '/submit_header.sh', 'r').read(),
open(script, 'r').read(),
open(dirp + '/submit_footer.sh', 'r').read(),
)
wdir = os.getenv('HOME')
qsub_cmd = [
'qsub',
'-q', '@hades',
'-N', name,
'-d', wdir,
'-joe', '-koe',
'-l', 'walltime=48:00:00,nodes=1:ppn=1,mem=8gb',
]
if datapath is not None:
qsub_cmd += ['-v', 'DATAPATH={}'.format(datapath)]
log.info('command: %s', ' '.join(qsub_cmd))
proc = subprocess.Popen(
qsub_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True
)
jobid, _ = proc.communicate(job_cmd)
log.info('Submitted job name=%s, id=%s', name, jobid.strip())
return jobid
def main():
args = get_args()
launch(args.name, args.script, args.datapath)
if __name__ == '__main__':
main()