-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_slurm_jobs.py
66 lines (57 loc) · 1.47 KB
/
create_slurm_jobs.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
import shutil
methods = ['dice-genetic']
datasets = ['boston','adult','compas','credit','garments']
folds = [0,1,2,3,4,5]
plausibs = [0]
optCs = [0]
optKs = [0]
# create configs
configs = list()
for method in methods:
for dataset in datasets:
for plaus in plausibs:
for optC in optCs:
for optK in optKs:
for fold in folds:
config = {
'method' : method,
'dataset' : dataset,
'plaus' : str(plaus),
'optC' : str(optC),
'optK' : str(optK),
'fold' : str(fold),
}
configs.append(config)
for config in configs:
# create job file
job_name = ""
for k in config:
job_name += k+"_"+config[k]+"_"
job_name = job_name[:-1] + ".job"
shutil.copy('template.job', 'slurm_jobs/'+job_name)
# modify job file
f = open('slurm_jobs/'+job_name, 'r')
ll = f.readlines()
f.close()
is_param_area = False
for i, l in enumerate(ll):
# remove "\n" for the comparisons
l = l.replace("\n","")
if l == "# START PARAMS":
# start writing params
is_param_area = True
continue
elif l == "# END PARAMS":
# finished
break
# set the params
for k in config:
if l.replace("\n","") == k.upper():
# found the param to set, set it!
ll[i] = k.upper()+"="+config[k]+"\n"
break
# write updated file
f = open('slurm_jobs/'+job_name, 'w')
for l in ll:
f.write(l)
f.close()