-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtardis_multiple_runner.py
executable file
·68 lines (47 loc) · 2.3 KB
/
tardis_multiple_runner.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
#!/usr/bin/env python
import numpy as np
import argparse
import glob
import shlex
import subprocess
def main(rootname):
naepochs = glob.glob("tardis_%05d*.yml" % rootname)
nepochs = len(naepochs)
epochs =[]
for i in xrange (nepochs):
epoch =(naepochs[i].rsplit("_")[-1].strip()).rsplit(".")[-2].strip()
epochs.append(int(epoch))
return epochs
def write_submit(Nthreads, rootname, mode):
epochs = main(rootname)
if mode == 'batch':
defaultfile = 'mpa-pascal-default.cmd'
for i in xrange(len(epochs)):
filename = 'tardis_%05d_%d.yml' %(rootname, epochs[i])
with open(defaultfile, 'r') as file:
filedata = file.read()
filedata = filedata.replace('NTHREADS', str(Nthreads))
filedata = filedata.replace('executablefile', './run_tardis.py')
filedata = filedata.replace('filename', str(filename))
filedata = filedata.replace('rootname', str(rootname))
filedata = filedata.replace('epoch', str(epochs[i]))
with open('mpa-pascal_%05d_%d.cmd' % (rootname, epochs[i]), 'w') as file:
file.write(filedata)
p = subprocess.Popen(shlex.split("qsub mpa-pascal_%05d_%d.cmd" % (rootname, epochs[i])))
if mode == 'local':
for i in xrange(len(epochs)):
defaultfile = 'submit_local_default.sh'
filename = 'tardis_%05d_%d.yml' %(rootname, epochs[i])
with open(defaultfile, 'r') as file:
filedata = file.read()
filedata = filedata.replace('executablefile', './run_tardis.py')
filedata = filedata.replace('filename', str(filename))
filedata = filedata.replace('rootname', str(rootname))
filedata = filedata.replace('epoch', str(epochs[i]))
with open('submit_local_%05d_%d.sh' % (rootname, epochs[i]), 'w') as file:
file.write(filedata)
subprocess.Popen(shlex.split("chmod +x submit_local_%05d_%d.sh" % (rootname, epochs[i])))
with open("tardis_%d_%d.log" %(rootname, epochs[i]), 'w+') as err:
subprocess.Popen(shlex.split("./submit_local_%05d_%d.sh" % (rootname, epochs[i])), stdout = err , stderr = err )
if __name__ == "__main__":
write_submit(Nthreads, rootname, mode)