-
Notifications
You must be signed in to change notification settings - Fork 2
/
cluster_submitter.py
executable file
·188 lines (135 loc) · 5.79 KB
/
cluster_submitter.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
import argparse
from datetime import timedelta
import itertools
import subprocess
import sys
dats = ["3x3", "4x4", "5x5"]
"""source_ids = ["{1}", "{1}", "{1}"]
sink_ids = ["{9}", "{16}", "{13}"]
attacker_start_poses = [9, 16, 13]
attacker_range = [1.0]
source_periods = [1]
safety_periods = [5, 7, 9]
slots_per_second = [6, 7, 9]"""
all_options = {
"obj": [0, 1, 2, 3, 4, 5],
"num_fake_messages": [0, 3],
"message_sent_once": [0, 1],
"target_receive_ratio": [0.6, 0.8, 1.0],
}
option_keys = ("obj", "num_fake_messages", "message_sent_once", "target_receive_ratio")
def estimate_walltime(dat, options):
return timedelta(hours=48)
#if dat == "3x3":
# return timedelta(hours=6)
#elif dat == "4x4":
# if options["obj"] == 4:
# return timedelta(hours=48)
# else:
# return timedelta(hours=16)
#elif dat == "5x5":
# return timedelta(hours=48)
#else:
# return timedelta(hours=48)
class Cluster(object):
def __init__(self, dry_run):
self.dry_run = dry_run
def job_name(self, dat, options):
return dat + "_" + "_".join(map(str, options))
def generate_command(self, dat, options):
options_string = " ".join("-D {}={}".format(k, v) for (k, v) in options.items())
return "oplrun -v -w -deploy -profile {} -p SLP {}".format(options_string, dat)
def _walltime_to_str(self, walltime):
total_seconds = int(walltime.total_seconds())
hours, remainder = divmod(total_seconds, 60*60)
minutes, seconds = divmod(remainder, 60)
return "{:02d}:{:02d}:{:02d}".format(hours, minutes, seconds)
def pbs_submit(self, command, job_name, walltime, notify=None, hold=False, *args, **kwargs):
submit_command = "qsub -j oe -l nodes={}:ppn={} -l walltime={} -l mem={} -N \"{}\"".format(
self.nodes, self.ppn, self._walltime_to_str(walltime), self.pmem, job_name
)
if hasattr(self, "queue"):
submit_command += " -q {}".format(self.queue)
if notify:
submit_command += " -m bae -M {}".format(notify)
if hold:
submit_command += " -h"
cluster_command = "echo '{} >> ilp{}.txt' | {}".format(command, job_name, submit_command)
if hasattr(self, "max_walltime"):
if walltime > self.max_walltime:
raise RuntimeError("Unable to queue \"{}\" as its walltime is above the maximum".format(cluster_command))
self._submit_job(cluster_command)
def moab_submit(self, command, job_name, walltime, notify=None, hold=False, *args, **kwargs):
submit_command = "msub -j oe -l nodes={}:ppn={} -l walltime={} -l mem={} -N \"{}\"".format(
self.nodes, self.ppn, self._walltime_to_str(walltime), self.pmem, job_name
)
if hasattr(self, "queue"):
submit_command += " -q {}".format(self.queue)
if notify:
submit_command += " -m bae -M {}".format(notify)
if hold:
submit_command += " -h"
cluster_command = "echo '{} >> ilp{}.txt' | {}".format(command, job_name, submit_command)
if hasattr(self, "max_walltime"):
if walltime > self.max_walltime:
raise RuntimeError("Unable to queue \"{}\" as its walltime is above the maximum".format(cluster_command))
self._submit_job(cluster_command)
def _submit_job(self, command):
print(command)
if not self.dry_run:
subprocess.check_call(command, shell=True)
def submit_all(self, **kwargs):
option_product = list(itertools.product(*[all_options[key] for key in option_keys]))
for dat in dats:
for options in option_product:
try:
options_dict = dict(zip(option_keys, options))
walltime = estimate_walltime(dat, options_dict)
command = self.generate_command(dat, options_dict)
job_name = self.job_name(dat, options)
self.submit_command(command, job_name, walltime=walltime, **kwargs)
except RuntimeError as ex:
print(ex)
class Tinis(Cluster):
nodes = 1
ppn = 32 # Up to 32
pmem = "512gb" # Up to 1TB
queue = "fat"
max_walltime = timedelta(seconds=172800)
def __init__(self, dry_run):
super(Tinis, self).__init__(dry_run)
def submit_command(self, *args, **kwargs):
return self.moab_submit(*args, **kwargs)
class Orac(Cluster):
nodes = 1
ppn = 28 # Up to 28
pmem = "120gb" # Up to 128GB
def __init__(self, dry_run):
super(Orac, self).__init__(dry_run)
def submit_command(self, *args, **kwargs):
return self.moab_submit(*args, **kwargs)
class Chiron(Cluster):
nodes = 1
ppn = 48 # Up to 96
pmem = "512gb" # Up to 4TB
queue = "fat"
def __init__(self, dry_run):
super(Chiron, self).__init__(dry_run)
def submit_command(self, *args, **kwargs):
return self.pbs_submit(*args, **kwargs)
def cluster_names():
return [cluster.__name__ for cluster in Cluster.__subclasses__()]
def get_cluster(name):
return [cluster for cluster in Cluster.__subclasses__() if cluster.__name__ == name][0]
def main():
parser = argparse.ArgumentParser(description="Cluster Submitter", add_help=True)
parser.add_argument("cluster", type=str, help="The name of the cluster", choices=cluster_names())
parser.add_argument("--notify", type=str, default=None)
parser.add_argument("--dry-run", action="store_true", default=False)
parser.add_argument("--hold", action="store_true", default=False)
args = parser.parse_args(sys.argv[1:])
cluster = get_cluster(args.cluster)(args.dry_run)
cluster.submit_all(notify=args.notify, hold=args.hold)
if __name__ == "__main__":
main()