-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathperformance_study.py
More file actions
376 lines (315 loc) · 10 KB
/
performance_study.py
File metadata and controls
376 lines (315 loc) · 10 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env python3
# Shared functions to use across analyses.
import json
import os
import re
from matplotlib.ticker import FormatStrFormatter
import matplotlib.pylab as plt
import pandas
import seaborn as sns
import yaml
sns.set_theme(style="whitegrid", palette="pastel")
def read_yaml(filename):
with open(filename, "r") as fd:
content = yaml.safe_load(fd)
return content
def read_json(filename):
with open(filename, "r") as fd:
content = json.loads(fd.read())
return content
def recursive_find(base, pattern="*.*"):
"""
Recursively find and yield directories matching a glob pattern.
"""
for root, dirnames, filenames in os.walk(base):
for dirname in dirnames:
if not re.search(pattern, dirname):
continue
yield os.path.join(root, dirname)
def recursive_find_files(base, pattern="*.*"):
"""
Recursively find and yield directories matching a glob pattern.
"""
for root, _, filenames in os.walk(base):
for filename in filenames:
if not re.search(pattern, filename):
continue
yield os.path.join(root, filename)
def find_inputs(input_dir, pattern="*.*", include_on_premises=False):
"""
Find inputs (times results files)
"""
files = []
for filename in recursive_find(input_dir, pattern):
# We only have data for small
if not include_on_premises and "on-premises" in filename:
continue
files.append(filename)
return files
def get_outfiles(base, pattern="[.]out"):
"""
Recursively find and yield directories matching a glob pattern.
"""
for root, _, filenames in os.walk(base):
for filename in filenames:
if not re.search(pattern, filename):
continue
yield os.path.join(root, filename)
def read_file(filename):
with open(filename, "r") as fd:
content = fd.read()
return content
def write_json(obj, filename):
with open(filename, "w") as fd:
fd.write(json.dumps(obj, indent=4))
def write_file(text, filename):
with open(filename, "w") as fd:
fd.write(text)
class ExperimentNameParser:
"""
Shared parser to convert directory path into components.
"""
def __init__(self, filename, indir):
self.filename = filename
self.indir = indir
self.parse()
def show(self):
print(self.cloud, self.env, self.env_type, self.size)
def parse(self):
parts = self.filename.replace(self.indir + os.sep, "").split(os.sep)
# These are consistent across studies
self.cloud = parts.pop(0)
self.env = parts.pop(0)
self.env_type = parts.pop(0)
size = parts.pop(0)
# Experiment is the plot label
self.experiment = os.path.join(self.cloud, self.env, self.env_type)
# Prefix is an identifier for parsed flux metadata, jobspec and events
self.prefix = os.path.join(self.experiment, size)
# If these are in the size, they are additional identifiers to indicate the
# environment type. Add to it instead of the size. I could skip some of these
# but I want to see the differences.
if "-" in size:
size, _ = size.split("-", 1)
self.size = int(size.replace("size", ""))
class ResultParser:
"""
Helper class to parse results into a data frame.
"""
def __init__(self, app):
self.init_df()
self.idx = 0
self.app = app
def init_df(self):
"""
Initialize an empty data frame for the application
"""
self.df = pandas.DataFrame(
columns=[
"experiment",
"cloud",
"env",
"env_type",
"nodes",
"application",
"metric",
"value",
"gpu_count",
]
)
def set_context(self, cloud, env, env_type, size, qualifier=None, gpu_count=0):
"""
Set the context for the next stream of results.
These are just fields to add to the data frame.
"""
self.cloud = cloud
self.env = env
self.env_type = env_type
self.size = size
# Extra metadata to add to experiment name
self.qualifier = qualifier
self.gpu_count = gpu_count
def add_result(self, metric, value):
"""
Add a result to the table
"""
# Unique identifier for the experiment plot
# is everything except for size
experiment = os.path.join(self.cloud, self.env, self.env_type)
if self.qualifier is not None:
experiment = os.path.join(experiment, self.qualifier)
self.df.loc[self.idx, :] = [
experiment,
self.cloud,
self.env,
self.env_type,
self.size,
self.app,
metric,
value,
self.gpu_count,
]
self.idx += 1
class ProblemSizeParser(ResultParser):
"""
Extended ResultParser that includes a problem size.
"""
def init_df(self):
"""
Initialize an empty data frame for the application
"""
self.df = pandas.DataFrame(
columns=[
"experiment",
"cloud",
"env",
"env_type",
"nodes",
"application",
"problem_size",
"metric",
"value",
"gpu_count",
]
)
def add_result(self, metric, value, problem_size):
"""
Add a result to the table
"""
# Unique identifier for the experiment plot
# is everything except for size
experiment = os.path.join(self.cloud, self.env, self.env_type)
if self.qualifier is not None:
experiment = os.path.join(experiment, self.qualifier)
self.df.loc[self.idx, :] = [
experiment,
self.cloud,
self.env,
self.env_type,
self.size,
self.app,
problem_size,
metric,
value,
self.gpu_count,
]
self.idx += 1
def parse_flux_metadata(item):
"""
Jobs run with flux have a jobspec and event metadata at the end
"""
item, metadata = item.split("START OF JOBSPEC")
metadata, events = metadata.split("START OF EVENTLOG")
jobspec = json.loads(metadata)
events = [json.loads(x) for x in events.split("\n") if x]
# QUESTION: is this the correct event, shell.start? I chose over init
# Note that I assume we want to start at init and done.
# This unit is in seconds
start = [x for x in events if x["name"] == "shell.start"][0]["timestamp"]
done = [x for x in events if x["name"] == "done"][0]["timestamp"]
duration = done - start
metadata = {"jobspec": jobspec, "events": events}
return item, duration, metadata
def parse_slurm_duration(item):
"""
Get the start and end time from the slurm output.
We want this to throwup if it is missing from the output.
"""
start = int(
[x for x in item.split("\n") if "Start time" in x][0].rsplit(" ", 1)[-1]
)
done = int([x for x in item.split("\n") if "End time" in x][0].rsplit(" ", 1)[-1])
return done - start
def remove_slurm_duration(item):
"""
Remove the start and end time from the slurm output.
"""
keepers = [x for x in item.split("\n") if not re.search("^(Start|End) time", x)]
return "\n".join(keepers)
def skip_result(dirname, filename):
"""
Return true if we should skip the result path.
"""
# I don't know if these are results or testing, skipping for now
# They are from aws parallel-cluster CPU
if os.path.join("experiment", "data") in filename:
return True
# These are OK
if "aks/cpu/size" in filename and "kripke" in filename:
return False
# These were redone with a placement group
if (
"aks/cpu/size" in filename
and "placement" not in filename
and "256" not in filename
and "128" not in filename
):
return True
return (
dirname.startswith("_")
or "configs" in filename
or "no-add" in filename
or "noefa" in filename
or "attempt-1" in filename
or "no-placement" in filename
or "shared-memory" in filename
)
def set_group_color_properties(plot_name, color_code, label):
# https://www.geeksforgeeks.org/how-to-create-boxplots-by-group-in-matplotlib/
for k, v in plot_name.items():
plt.setp(plot_name.get(k), color=color_code)
# use plot function to draw a small line to name the legend.
plt.plot([], c=color_code, label=label)
plt.legend()
def make_plot(
df,
title,
ydimension,
xdimension,
xlabel,
ylabel,
palette=None,
ext="png",
plotname="lammps",
hue=None,
outdir="img",
log_scale=False,
do_round=False,
):
"""
Helper function to make common plots.
"""
ext = ext.strip(".")
plt.figure(figsize=(12, 6))
sns.set_style("dark")
flierprops = dict(
marker=".", markerfacecolor="None", markersize=10, markeredgecolor="black"
)
ax = sns.boxplot(
x=xdimension,
y=ydimension,
flierprops=flierprops,
hue=hue,
data=df,
# gap=.1,
linewidth=0.4,
palette=palette,
whis=[5, 95],
# dodge=False,
)
plt.title(title)
print(log_scale)
ax.set_xlabel(xlabel, fontsize=16)
ax.set_ylabel(ylabel, fontsize=16)
ax.set_xticklabels(ax.get_xmajorticklabels(), fontsize=14)
ax.set_yticklabels(ax.get_yticks(), fontsize=14)
# plt.xticks(rotation=90)
if log_scale is True:
plt.gca().yaxis.set_major_formatter(
plt.ScalarFormatter(useOffset=True, useMathText=True)
)
if do_round is True:
ax.yaxis.set_major_formatter(FormatStrFormatter("%.3f"))
plt.tight_layout()
plt.savefig(os.path.join(outdir, f"{plotname}.{ext}"))
plt.clf()