-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrmaa_script.py
More file actions
executable file
·67 lines (51 loc) · 1.99 KB
/
drmaa_script.py
File metadata and controls
executable file
·67 lines (51 loc) · 1.99 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
# Jethro
# 2021.09.23
# Requires python 3 with drmaa package installed
# Requires drmaa shared object files in the submit environment:
# export DRMAA_LIBRARY_PATH=/mgmt/uge/8.6.8/lib/lx-amd64/libdrmaa.so.1.0
# To run:
# python submit.py
import drmaa
import os
import stat
import tempfile
def main():
"""Open and drmaa session, submit a bash script to be run on the cluster
close the drmaa session
"""
shell_script = tempfile.NamedTemporaryFile(dir='.', mode='w', delete=False)
outfile = os.path.join(os.getcwd(), 'ClusterEnvironment.txt')
shell_script.write("#!/bin/bash\n\n"
"printf 'python version is:\\n' > {outf}\n"
"which python >> {outf}\n"
"printf 'R version is:\\n' >> {outf}\n"
"which R >> {outf}\n\n"
"printf 'bash environment is:\\n': >> {outf}\n"
"env >> {outf}".format(outf=outfile))
shell_script.close()
# os.chmod(shell_script.name, 0555) # python 2
os.chmod(shell_script.name, 0o555)
# initialize session
s = drmaa.Session()
s.initialize()
print('A session was started successfully')
print('Session returns contact information: {}'.format(s.contact))
# create a job template
jt = s.createJobTemplate()
# SET for UGE on BMRC cluster
# FAILS with '-V' but '-v', works... neither used as jobEnvironment set instead
jt.nativeSpecification = "-cwd -q short.qc -pe shmem 2" # -v PATH={}".format(os.environ['PATH'])
jt.remoteCommand = os.path.join(os.getcwd(), shell_script.name)
jt.jobName = 'HelloCluster'
# jt.errorPath = shell_script + '.error'
jt.jobEnvironment = os.environ
jt.joinFiles=False
# run join
jobid = s.runJob(jt)
print('Job submitted with ID: {}'.format(jobid))
# clean up
s.deleteJobTemplate(jt)
s.exit()
# os.unlink(shell_script.name) # For some reason this also deletes ClusterEnvironment.txt
if __name__=='__main__':
main()