-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslurm_submit.py
78 lines (62 loc) · 2.05 KB
/
slurm_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/python
"""
Creates the necessary file for submitting a job to slurm and submits it.
Usage::
python slurm_submit.py myscript.py [batch]
Default behavior submits to queue ``play`` with settings::
#SBATCH --time=0-00:15:00 --mem-per-cpu=5000
#SBATCH -p play
if "batch" is the last parameter these settings are used::
#SBATCH --time=5-00:00:00 --mem-per-cpu=5000
#SBATCH -p batch
(The filename to be submitted is myscript.sh)
"""
import sys
import subprocess
def main():
# script to be executed
pythonscript = sys.argv[1]
if pythonscript[-3:] != ".py":
print "trying to submit a non-python script, exiting.."
print "make changes if you want this to be possible"
exit()
basename = pythonscript[:-3] # corresponds to "myscript"
try:
f = open(pythonscript, "r")
f.close()
except:
print "something wrong with the filename perhaps, exiting..."
# default goes to play
play = True
try:
batchstring = sys.argv[2]
if batchstring == "batch":
play = False
print "submitting to batch..."
except:
print "submitting to play..."
shfname = basename + ".sh"
outfname = basename + ".out"
stringtowrite = ""
stringtowrite += "#!/bin/bash\n"
if play:
stringtowrite += "#SBATCH --time=0-00:15:00 --mem-per-cpu=5000 \n"
stringtowrite += "#SBATCH -p play \n"
else:
stringtowrite += "#SBATCH --time=5-00:00:00 --mem-per-cpu=5000 \n"
stringtowrite += "#SBATCH -p batch \n"
stringtowrite += "#SBATCH -o " + outfname + "\n"
stringtowrite += "#SBATCH -n 12 \n"
stringtowrite += "#SBATCH -N1-1 \n"
stringtowrite += "\n"
stringtowrite += \
"module load igraph/0.6 python-igraph/0.6 scipy/0.11.0 matlab\n"
stringtowrite += "\n"
stringtowrite += "python " + pythonscript
f = open(shfname, "w")
print shfname
f.write(stringtowrite)
f.close() # flushes the conent
subprocess.call(["sbatch", shfname])
if __name__ == "__main__":
main()