Skip to content

Commit 2a10739

Browse files
committed
Replace plotting with polars
1 parent 574df25 commit 2a10739

File tree

2 files changed

+41
-135
lines changed

2 files changed

+41
-135
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
jinja2
22
matplotlib
33
numpy
4-
pandas
54
polars
65
scipy
76
sympy>=1.9

tools/mapping-tester/plotconv.py

Lines changed: 41 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import matplotlib.pyplot as plt
77
import numpy as np
8-
import pandas
9-
from pandas.api.types import is_numeric_dtype
8+
import polars as pl
109

1110

1211
def parseArguments(args):
@@ -29,10 +28,6 @@ def parseArguments(args):
2928
return parser.parse_args(args)
3029

3130

32-
def lavg(l):
33-
return math.exp(sum(map(math.log, l)) / len(l))
34-
35-
3631
# seaborn.color_palette("colorblind", 10).as_hex()
3732
style_colours = [
3833
"#0173b2",
@@ -50,148 +45,36 @@ def lavg(l):
5045
styles = [(c, m) for m in style_markers for c in style_colours]
5146

5247

53-
def plotConv(ax, df, yname):
54-
xmin = df["mesh A"].min()
55-
xmax = df["mesh A"].max()
56-
ymin = df[yname].min()
57-
ymax = df[yname].max()
58-
59-
print(xmin, xmax)
60-
print(ymin, ymax)
61-
62-
63-
def plotError(df, prefix):
64-
yname = "relative-l2"
65-
if yname not in df.columns:
66-
print(f"Skipping {yname} as not found in dataset.")
67-
return
68-
fig, ax = plt.subplots(sharex=True, sharey=True)
69-
series = df.groupby("mapping")
70-
for grouped, style in zip(series, styles):
71-
name, group = grouped
72-
if group[yname].max() == 0:
73-
print(f"Dropping {yname}-series {name} as all 0")
74-
continue
75-
color, marker = style
76-
group.plot(
77-
ax=ax,
78-
logy=True,
79-
logx=is_numeric_dtype(df["mesh A"]),
80-
x="mesh A",
81-
y=yname,
82-
label=name,
83-
marker=marker,
84-
color=color,
85-
)
86-
ax.set_xlabel("edge length(h) of mesh A")
87-
ax.set_ylabel("relative-l2 error mapping to mesh B")
88-
89-
plotConv(ax, df, yname)
90-
91-
plt.gca().invert_xaxis()
92-
plt.grid()
93-
plt.savefig(prefix + "-error.pdf")
94-
95-
96-
def plotMemory(df, prefix):
97-
yname = "peakMemB"
48+
def plot(df: pl.DataFrame, yname: str, ylabel: str, filename: str):
9849
if yname not in df.columns:
9950
print(f"Skipping {yname} as not found in dataset.")
10051
return
101-
fig, ax = plt.subplots(sharex=True, sharey=True)
102-
series = df.groupby("mapping")
103-
for grouped, style in zip(series, styles):
104-
name, group = grouped
105-
if group[yname].max() == 0:
106-
print(f"Dropping {yname}-series {name} as all 0")
107-
continue
108-
color, marker = style
109-
group.plot(
110-
ax=ax,
111-
logy=True,
112-
logx=is_numeric_dtype(df["mesh A"]),
113-
x="mesh A",
114-
y=yname,
115-
label=name,
116-
marker=marker,
117-
color=color,
118-
)
119-
ax.set_xlabel("edge length(h) of mesh A")
120-
ax.set_ylabel("peak memory of participant B [Kbytes]")
12152

122-
# plotConv(ax, df, yname)
123-
124-
plt.gca().invert_xaxis()
125-
plt.grid()
126-
plt.savefig(prefix + "-peakMemB.pdf")
127-
128-
129-
def plotComputeMappingTime(df, prefix):
130-
yname = "computeMappingTime"
131-
if yname not in df.columns:
132-
print(f"Skipping {yname} as not found in dataset.")
133-
return
13453
fig, ax = plt.subplots(sharex=True, sharey=True)
135-
series = df.groupby("mapping")
136-
for grouped, style in zip(series, styles):
137-
name, group = grouped
138-
if group[yname].max() == 0:
139-
print(f"Dropping {yname}-series {name} as all 0")
140-
continue
141-
color, marker = style
142-
group.plot(
143-
ax=ax,
144-
logy=True,
145-
logx=is_numeric_dtype(df["mesh A"]),
146-
x="mesh A",
147-
y=yname,
148-
label=name,
149-
marker=marker,
150-
color=color,
151-
)
152-
15354
ax.set_xlabel("edge length(h) of mesh A")
154-
ax.set_ylabel("time to compute mapping [us]")
55+
ax.set_ylabel(ylabel)
56+
ax.set_yscale("log")
57+
if df["mesh A"].dtype.is_numeric():
58+
ax.set_xscale("log")
15559

156-
# plotConv(ax, df, yname)
157-
158-
plt.gca().invert_xaxis()
159-
plt.grid()
160-
plt.savefig(prefix + "-computet.pdf")
161-
162-
163-
def plotMapDataTime(df, prefix):
164-
yname = "mapDataTime"
165-
if yname not in df.columns:
166-
print(f"Skipping {yname} as not found in dataset.")
167-
return
168-
fig, ax = plt.subplots(sharex=True, sharey=True)
169-
series = df.groupby("mapping")
60+
series = df.group_by("mapping")
17061
for grouped, style in zip(series, styles):
17162
name, group = grouped
17263
if group[yname].max() == 0:
17364
print(f"Dropping {yname}-series {name} as all 0")
17465
continue
17566
color, marker = style
176-
group.plot(
177-
ax=ax,
178-
logy=True,
179-
logx=is_numeric_dtype(df["mesh A"]),
180-
x="mesh A",
181-
y=yname,
67+
ax.plot(
68+
group["mesh A"],
69+
group[yname],
18270
label=name,
18371
marker=marker,
18472
color=color,
18573
)
18674

187-
ax.set_xlabel("edge length(h) of mesh A")
188-
ax.set_ylabel("time to map Data [us]")
189-
190-
# plotConv(ax, df, yname)
191-
19275
plt.gca().invert_xaxis()
19376
plt.grid()
194-
plt.savefig(prefix + "-mapt.pdf")
77+
plt.savefig(filename + ".pdf")
19578

19679

19780
def main(argv):
@@ -201,16 +84,40 @@ def main(argv):
20184
plt.rcParams["figure.figsize"] = "8, 8"
20285
plt.rcParams["figure.autolayout"] = "true"
20386

204-
df = pandas.read_csv(args.file)
87+
df = pl.read_csv(args.file).sort("mesh A")
20588
toMeshes = df["mesh B"].unique()
20689
assert (
20790
len(toMeshes) == 1
20891
), f"There are {len(toMeshes)} to-meshes but only 1 is allowed. Fix your dataset!"
209-
df.sort_values("mesh A", inplace=True)
210-
plotError(df, args.prefix)
211-
plotMemory(df, args.prefix)
212-
plotMapDataTime(df, args.prefix)
213-
plotComputeMappingTime(df, args.prefix)
92+
93+
if not df["mesh A"].dtype.is_numeric():
94+
print("Note: 'mesh A' isn't numeric. The x-axis will not use log scaling.")
95+
96+
plot(
97+
df,
98+
yname="relative-l2",
99+
ylabel="relative-l2 error mapping to mesh B",
100+
filename=f"{args.prefix}-error",
101+
)
102+
plot(
103+
df,
104+
yname="peakMemB",
105+
ylabel="peak memory of participant B [Kbytes]",
106+
filename=f"{args.prefix}-peakMemB",
107+
)
108+
plot(
109+
df,
110+
yname="computeMappingTime",
111+
ylabel="time to compute mapping [us]",
112+
filename=f"{args.prefix}-computet",
113+
)
114+
plot(
115+
df,
116+
yname="mapDataTime",
117+
ylabel="time to map Data [us]",
118+
filename=f"{args.prefix}-mapt",
119+
)
120+
214121
return 0
215122

216123

0 commit comments

Comments
 (0)