Skip to content

Commit a2d6259

Browse files
committed
add lammps runs
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent f662370 commit a2d6259

File tree

7 files changed

+231
-15
lines changed

7 files changed

+231
-15
lines changed

google/kubecon/lammps/run1/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,17 @@ Let's plot results! Make sure you have seaborn / matplotlib / pandas installed.
318318

319319
```bash
320320
mkdir -p ./img/osu-benchmarks
321-
python plot-times.py --results ./data/osu-benchmarks --out ./img/osu-benchmarks
321+
python plot-osu-benchmarks.py --results ./data/osu-benchmarks --out ./img/osu-benchmarks
322322
```
323323

324+
### LAMMPS
325+
326+
```bash
327+
mkdir -p ./img/lammps
328+
python plot-lammps.py --results ./data/lammps --out ./img/lammps
329+
```
330+
331+
324332
### Singularity for HPCToolkit
325333

326334
We will need to run this as a post analysis to get the data locally, and across nodes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
,ranks,pods,time
2+
0,704,8,5.51242
3+
1,704,8,5.89967
4+
2,704,8,6.04301
5+
3,704,8,6.02985
6+
4,704,8,5.36226
7+
5,352,4,3.63868
8+
6,352,4,3.68496
9+
7,352,4,3.87733
10+
8,352,4,3.74458
11+
9,352,4,3.57988
12+
10,1408,16,6.50231
13+
11,1408,16,6.83839
14+
12,1408,16,7.26995
15+
13,1408,16,7.07252
16+
14,1408,16,6.49528
17+
15,88,1,1.73022
18+
16,88,1,1.81762
19+
17,88,1,1.7879
20+
18,88,1,1.75843
21+
19,88,1,1.72793
22+
20,176,2,3.04352
23+
21,176,2,3.22597
24+
22,176,2,2.90511
25+
23,176,2,3.02252
26+
24,176,2,3.09605
Loading
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import collections
5+
import fnmatch
6+
import os
7+
8+
import matplotlib.pyplot as plt
9+
import metricsoperator.utils as utils
10+
import pandas
11+
import seaborn as sns
12+
from metricsoperator.metrics import get_metric
13+
14+
plt.style.use("bmh")
15+
here = os.path.dirname(os.path.abspath(__file__))
16+
17+
18+
def get_parser():
19+
parser = argparse.ArgumentParser(
20+
description="Plot LAMMPS",
21+
formatter_class=argparse.RawTextHelpFormatter,
22+
)
23+
parser.add_argument(
24+
"--results",
25+
help="directory with raw results data",
26+
default=os.path.join(here, "data", "lammps"),
27+
)
28+
parser.add_argument(
29+
"--out",
30+
help="directory to save parsed results",
31+
default=os.path.join(here, "img", "lammps"),
32+
)
33+
return parser
34+
35+
36+
def recursive_find(base, pattern="*.*"):
37+
"""
38+
Recursively find and yield files matching a glob pattern.
39+
"""
40+
for root, _, filenames in os.walk(base):
41+
for filename in fnmatch.filter(filenames, pattern):
42+
yield os.path.join(root, filename)
43+
44+
45+
def find_json_inputs(input_dir):
46+
"""
47+
Find json inputs (results files)
48+
"""
49+
files = []
50+
for filename in recursive_find(input_dir, pattern="*.json"):
51+
# We only have data for small
52+
if "-small-" not in filename or "cache" in filename:
53+
continue
54+
files.append(filename)
55+
return files
56+
57+
58+
def main():
59+
"""
60+
Run the main plotting operation!
61+
"""
62+
parser = get_parser()
63+
args, _ = parser.parse_known_args()
64+
65+
# Output images and data
66+
outdir = os.path.abspath(args.out)
67+
indir = os.path.abspath(args.results)
68+
if not os.path.exists(outdir):
69+
os.makedirs(outdir)
70+
71+
# Find input files (skip anything with test)
72+
files = find_json_inputs(indir)
73+
if not files:
74+
raise ValueError(f"There are no input files in {indir}")
75+
76+
# This does the actual parsing of data into a formatted variant
77+
# Has keys results, iters, and columns
78+
df = parse_data(files)
79+
df.to_csv(os.path.join(outdir, "lammps-times.csv"))
80+
plot_results(df, outdir)
81+
82+
83+
def plot_results(df, outdir):
84+
"""
85+
Plot lammps results
86+
"""
87+
# Plot each!
88+
colors = sns.color_palette("hls", 8)
89+
hexcolors = colors.as_hex()
90+
types = list(df.ranks.unique())
91+
92+
# ALWAYS double check this ordering, this
93+
# is almost always wrong and the colors are messed up
94+
palette = collections.OrderedDict()
95+
for t in types:
96+
palette[t] = hexcolors.pop(0)
97+
98+
make_plot(
99+
df,
100+
title="LAMMPS Times (2x2x2)",
101+
tag="lammps",
102+
ydimension="time",
103+
xdimension="ranks",
104+
palette=palette,
105+
outdir=outdir,
106+
ext="png",
107+
plotname="lammps",
108+
hue="ranks",
109+
plot_type="bar",
110+
xlabel="MPI Ranks",
111+
ylabel="Time (seconds)",
112+
)
113+
114+
115+
def parse_data(files):
116+
"""
117+
Given a listing of files, parse into results data frame
118+
"""
119+
# Parse into data frame
120+
df = pandas.DataFrame(columns=["ranks", "pods", "time"])
121+
idx = 0
122+
m = get_metric("app-lammps")()
123+
124+
for filename in files:
125+
# This is a list, each a json result, 20x
126+
items = utils.read_json(filename)
127+
for item in items:
128+
# Parse the data into a result, including times
129+
# The parser expects a raw log (not by lines)
130+
data = "\n".join(item["data"])
131+
132+
result = m.parse_log(data)
133+
134+
# These are used for identifiers across the data
135+
pods = result["metadata"]["pods"]
136+
for datum in result["data"]:
137+
loop_time = datum["loop_time"]
138+
ranks = datum["ranks"]
139+
df.loc[idx, :] = [ranks, pods, loop_time]
140+
idx += 1
141+
return df
142+
143+
144+
def make_plot(
145+
df,
146+
title,
147+
tag,
148+
ydimension,
149+
xdimension,
150+
palette,
151+
xlabel,
152+
ylabel,
153+
ext="pdf",
154+
plotname="lammps",
155+
plot_type="violin",
156+
hue="ranks",
157+
outdir="img",
158+
):
159+
"""
160+
Helper function to make common plots.
161+
"""
162+
plotfunc = sns.boxplot
163+
if plot_type == "violin":
164+
plotfunc = sns.violinplot
165+
166+
ext = ext.strip(".")
167+
plt.figure(figsize=(12, 12))
168+
sns.set_style("dark")
169+
ax = plotfunc(
170+
x=xdimension, y=ydimension, hue=hue, data=df, whis=[5, 95], palette=palette
171+
)
172+
plt.title(title)
173+
ax.set_xlabel(xlabel, fontsize=16)
174+
ax.set_ylabel(ylabel, fontsize=16)
175+
ax.set_xticklabels(ax.get_xmajorticklabels(), fontsize=14)
176+
ax.set_yticklabels(ax.get_yticks(), fontsize=14)
177+
plt.savefig(os.path.join(outdir, f"{tag}_{plotname}.{ext}"))
178+
plt.clf()
179+
180+
181+
if __name__ == "__main__":
182+
main()

google/kubecon/lammps/run1/plot-osu-benchmarks.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import argparse
2-
import pandas
3-
from metricsoperator.metrics import get_metric
4-
from metricsoperator import utils as utils
5-
import matplotlib.pyplot as plt
6-
import seaborn as sns
72
import fnmatch
83
import json
94
import os
105
import re
116

7+
import matplotlib.pyplot as plt
8+
import pandas
9+
import seaborn as sns
10+
from metricsoperator import utils as utils
11+
from metricsoperator.metrics import get_metric
12+
1213
plt.style.use("bmh")
1314
here = os.path.dirname(os.path.abspath(__file__))
1415

@@ -21,19 +22,16 @@ def get_parser():
2122
parser.add_argument(
2223
"--results",
2324
help="directory with raw results data",
24-
default=os.path.join(here, "data"),
25+
default=os.path.join(here, "data", "osu-benchmarks"),
2526
)
2627
parser.add_argument(
2728
"--out",
2829
help="directory to save parsed results",
29-
default=os.path.join(here, "img"),
30+
default=os.path.join(here, "img", "osu-benchmarks"),
3031
)
3132
return parser
3233

3334

34-
axes_default = {"x": "Size"}
35-
36-
3735
def recursive_find(base, pattern="*.*"):
3836
"""
3937
Recursively find and yield files matching a glob pattern.

google/kubecon/lammps/run1/run-lammps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
import os
54
import json
5+
import os
66
import time
7-
from metricsoperator import MetricsOperator
7+
88
import metricsoperator.utils as utils
9+
from metricsoperator import MetricsOperator
910

1011
here = os.path.abspath(os.path.dirname(__file__))
1112

google/kubecon/lammps/run1/run-osu-benchmarks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
import os
54
import json
5+
import os
66
import time
7-
from metricsoperator import MetricsOperator
7+
88
import metricsoperator.utils as utils
9+
from metricsoperator import MetricsOperator
910

1011
here = os.path.abspath(os.path.dirname(__file__))
1112

0 commit comments

Comments
 (0)