-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpara.py
55 lines (47 loc) · 1.64 KB
/
para.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
from shutil import copyfile,rmtree
import subprocess
import argparse
import datetime
import time
import os, shutil
import shutil
import sys
class para_dagger:
def __init__(self,result_dir):
import time
path = "./output/"+time.strftime("%y%m%d-%H%M%S")
if not os.path.exists(path):
os.mkdir(path)
#os.mkidr("~/clothsim/result/"+time.strftime("%y%m%d-%H%M%S"))
self.path = path
self.result_dir = result_dir
if not os.path.exists(self.result_dir):
os.mkdir(self.result_dir)
shutil.copyfile('source/clothsim.py', os.path.join(result_dir,'clothsim.py'))
pass
def create_script(self,jobName):
import os
job_path=os.path.join(self.path, jobName)
cwd=os.getcwd()
shutil.copytree(os.path.join(cwd,'source'),job_path)
os.chdir(job_path)
script_path = 'script.sh'
script=open(script_path,'w')
script.write('#!/bin/bash\n')
script.write('#SBATCH --job-name={jobName} --time={time}\n'.format(jobName=jobName, time=24*60))
script.write('source activate cloth\n')
script.write('python clothsim.py '+os.path.join(self.result_dir, jobName)+'\n')
script.close()
#execute script
ret=subprocess.check_output(['sbatch',script_path])
os.chdir(cwd)
#find jobid
c=''
for i in xrange(len(ret)):
if ret[i].isdigit():
c=c+ret[i]
return c
if __name__=='__main__':
dagger = para_dagger(sys.argv[1]);
for i in range(100):
print(dagger.create_script(jobName=str(i)))