Skip to content

Commit

Permalink
Replace plotting with polars
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonis committed Feb 6, 2025
1 parent 574df25 commit 2a10739
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 135 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
jinja2
matplotlib
numpy
pandas
polars
scipy
sympy>=1.9
175 changes: 41 additions & 134 deletions tools/mapping-tester/plotconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import matplotlib.pyplot as plt
import numpy as np
import pandas
from pandas.api.types import is_numeric_dtype
import polars as pl


def parseArguments(args):
Expand All @@ -29,10 +28,6 @@ def parseArguments(args):
return parser.parse_args(args)


def lavg(l):
return math.exp(sum(map(math.log, l)) / len(l))


# seaborn.color_palette("colorblind", 10).as_hex()
style_colours = [
"#0173b2",
Expand All @@ -50,148 +45,36 @@ def lavg(l):
styles = [(c, m) for m in style_markers for c in style_colours]


def plotConv(ax, df, yname):
xmin = df["mesh A"].min()
xmax = df["mesh A"].max()
ymin = df[yname].min()
ymax = df[yname].max()

print(xmin, xmax)
print(ymin, ymax)


def plotError(df, prefix):
yname = "relative-l2"
if yname not in df.columns:
print(f"Skipping {yname} as not found in dataset.")
return
fig, ax = plt.subplots(sharex=True, sharey=True)
series = df.groupby("mapping")
for grouped, style in zip(series, styles):
name, group = grouped
if group[yname].max() == 0:
print(f"Dropping {yname}-series {name} as all 0")
continue
color, marker = style
group.plot(
ax=ax,
logy=True,
logx=is_numeric_dtype(df["mesh A"]),
x="mesh A",
y=yname,
label=name,
marker=marker,
color=color,
)
ax.set_xlabel("edge length(h) of mesh A")
ax.set_ylabel("relative-l2 error mapping to mesh B")

plotConv(ax, df, yname)

plt.gca().invert_xaxis()
plt.grid()
plt.savefig(prefix + "-error.pdf")


def plotMemory(df, prefix):
yname = "peakMemB"
def plot(df: pl.DataFrame, yname: str, ylabel: str, filename: str):
if yname not in df.columns:
print(f"Skipping {yname} as not found in dataset.")
return
fig, ax = plt.subplots(sharex=True, sharey=True)
series = df.groupby("mapping")
for grouped, style in zip(series, styles):
name, group = grouped
if group[yname].max() == 0:
print(f"Dropping {yname}-series {name} as all 0")
continue
color, marker = style
group.plot(
ax=ax,
logy=True,
logx=is_numeric_dtype(df["mesh A"]),
x="mesh A",
y=yname,
label=name,
marker=marker,
color=color,
)
ax.set_xlabel("edge length(h) of mesh A")
ax.set_ylabel("peak memory of participant B [Kbytes]")

# plotConv(ax, df, yname)

plt.gca().invert_xaxis()
plt.grid()
plt.savefig(prefix + "-peakMemB.pdf")


def plotComputeMappingTime(df, prefix):
yname = "computeMappingTime"
if yname not in df.columns:
print(f"Skipping {yname} as not found in dataset.")
return
fig, ax = plt.subplots(sharex=True, sharey=True)
series = df.groupby("mapping")
for grouped, style in zip(series, styles):
name, group = grouped
if group[yname].max() == 0:
print(f"Dropping {yname}-series {name} as all 0")
continue
color, marker = style
group.plot(
ax=ax,
logy=True,
logx=is_numeric_dtype(df["mesh A"]),
x="mesh A",
y=yname,
label=name,
marker=marker,
color=color,
)

ax.set_xlabel("edge length(h) of mesh A")
ax.set_ylabel("time to compute mapping [us]")
ax.set_ylabel(ylabel)
ax.set_yscale("log")
if df["mesh A"].dtype.is_numeric():
ax.set_xscale("log")

# plotConv(ax, df, yname)

plt.gca().invert_xaxis()
plt.grid()
plt.savefig(prefix + "-computet.pdf")


def plotMapDataTime(df, prefix):
yname = "mapDataTime"
if yname not in df.columns:
print(f"Skipping {yname} as not found in dataset.")
return
fig, ax = plt.subplots(sharex=True, sharey=True)
series = df.groupby("mapping")
series = df.group_by("mapping")
for grouped, style in zip(series, styles):
name, group = grouped
if group[yname].max() == 0:
print(f"Dropping {yname}-series {name} as all 0")
continue
color, marker = style
group.plot(
ax=ax,
logy=True,
logx=is_numeric_dtype(df["mesh A"]),
x="mesh A",
y=yname,
ax.plot(
group["mesh A"],
group[yname],
label=name,
marker=marker,
color=color,
)

ax.set_xlabel("edge length(h) of mesh A")
ax.set_ylabel("time to map Data [us]")

# plotConv(ax, df, yname)

plt.gca().invert_xaxis()
plt.grid()
plt.savefig(prefix + "-mapt.pdf")
plt.savefig(filename + ".pdf")


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

df = pandas.read_csv(args.file)
df = pl.read_csv(args.file).sort("mesh A")
toMeshes = df["mesh B"].unique()
assert (
len(toMeshes) == 1
), f"There are {len(toMeshes)} to-meshes but only 1 is allowed. Fix your dataset!"
df.sort_values("mesh A", inplace=True)
plotError(df, args.prefix)
plotMemory(df, args.prefix)
plotMapDataTime(df, args.prefix)
plotComputeMappingTime(df, args.prefix)

if not df["mesh A"].dtype.is_numeric():
print("Note: 'mesh A' isn't numeric. The x-axis will not use log scaling.")

plot(
df,
yname="relative-l2",
ylabel="relative-l2 error mapping to mesh B",
filename=f"{args.prefix}-error",
)
plot(
df,
yname="peakMemB",
ylabel="peak memory of participant B [Kbytes]",
filename=f"{args.prefix}-peakMemB",
)
plot(
df,
yname="computeMappingTime",
ylabel="time to compute mapping [us]",
filename=f"{args.prefix}-computet",
)
plot(
df,
yname="mapDataTime",
ylabel="time to map Data [us]",
filename=f"{args.prefix}-mapt",
)

return 0


Expand Down

0 comments on commit 2a10739

Please sign in to comment.