Skip to content

Commit

Permalink
Add aggregation script
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonis committed Feb 5, 2025
1 parent 56c6802 commit 2c74af5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/mapping_tester_runtime/reference-aggregated.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mapping,constraint,mesh A,mesh B,ranks A,ranks B,computeMappingTime,globalTime,initializeTime,mapDataTime,peakMemA,peakMemB
nn,consistent,coarse_mesh,fine_mesh,2,2,968.0,117537.33333333333,89569.66666666667,1.6666666666666667,116752.0,116426.66666666667
tps,consistent,coarse_mesh,fine_mesh,2,2,316.6666666666667,143683.0,115327.33333333333,483.6666666666667,115870.66666666667,129608.0
4 changes: 4 additions & 0 deletions examples/mapping_tester_runtime/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ export ASTE_B_MPIARGS=""

python3 "${MAPPING_TESTER}/repeat.py" 5 --file "test-statistics{}.csv"

python3 "${MAPPING_TESTER}/aggregate.py" test-statistics.csv mean -x

python3 "${MAPPING_TESTER}/compare.py" reference-statistics.csv test-statistics.csv

python3 "${MAPPING_TESTER}/compare.py" reference-aggregated.csv aggregated.csv
74 changes: 74 additions & 0 deletions tools/mapping-tester/aggregate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!python3

import argparse
import pathlib

import numpy as np
import polars as pl


def parseArguments():
parser = argparse.ArgumentParser(
description="Aggregates statistics of multiple runs. See mapping-tester repreat.py"
)
parser.add_argument(
"file",
type=pathlib.Path,
help="Statistics file to aggregate runs on",
)
parser.add_argument(
"kind",
choices=["mean", "median", "variance"],
help="Kind of aggregation",
)
parser.add_argument(
"-x",
"--exclude-min-max",
dest="exclude",
action="store_true",
help="Remove min and max from the data set before aggregating.",
)
parser.add_argument(
"--output",
"-o",
default="aggregated.csv",
type=pathlib.Path,
help="Statistics file write the aggregated results to.",
)
return parser.parse_args()


def trim(series: pl.Series):
return series.sort()[1:-1]


def run(file: pathlib.Path, kind: str, exclude: bool, dest: pathlib.Path):

df = pl.read_csv(file).drop("run")

# returns a lambda that creates a pl.Exception for a given column name
func = {
"median": lambda c: pl.col(c).median(),
"mean": lambda c: (
pl.col(c).map_batches(trim).mean() if exclude else pl.col(c).mean()
),
"variance": lambda c: (
pl.col(c).map_batches(trim).var() if exclude else pl.col(c).var()
),
}[kind]

case = ["mapping", "constraint", "mesh A", "mesh B", "ranks A", "ranks B"]
df = df.group_by(case).agg([func(c) for c in df.columns if c not in case])

print(f"Writing output to {dest}")
df.write_csv(dest)


def main():
args = parseArguments()
assert args.file.exists()
run(args.file, args.kind, args.exclude, args.output)


if __name__ == "__main__":
main()

0 comments on commit 2c74af5

Please sign in to comment.