Skip to content

Commit

Permalink
Add support for exporting data
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmundGoodman committed Apr 7, 2024
1 parent 19f6288 commit 97b6de6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ matplotlib = "^3.8.3"
matplotlib-label-lines = "^0.7.0"
seaborn = "^0.13.2"
plotext = "^5.2.8"
pandas = "^2.2.1"

[tool.bandit]
exclude_dirs = [".venv/"]
Expand Down
42 changes: 42 additions & 0 deletions src/hpc_multibench/plot/export_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""A set of functions to export the results of a test bench run."""

import pandas as pd

from hpc_multibench.plot.plot_data import split_metric_uncertainty
from hpc_multibench.run_configuration import RunConfiguration
from hpc_multibench.uncertainties import UFloat
from hpc_multibench.yaml_model import ExportModel


def export_data(
plot: ExportModel,
all_metrics: list[tuple[RunConfiguration, dict[str, str | UFloat]]],
) -> None:
"""Construct and export a pandas data frame from the metrics."""
df_data: dict[str, list[float | str]] = {}
for run_configuration, metrics in all_metrics:
row_data: dict[str, float | str] = {"Run configuration": run_configuration.name}

for metric in metrics:
value, error = split_metric_uncertainty(metrics, metric)
row_data[metric] = value
if error is not None:
row_data[f"{metric} error"] = error

for column, cell in row_data.items():
if column not in df_data:
df_data[column] = []
df_data[column].append(cell)

export_df = pd.DataFrame(df_data)

if plot.export_path is None:
print(export_df.to_string())
elif plot.export_format == "csv":
export_df.to_csv(plot.export_path)
else:
raise NotImplementedError(
f"Export format '{plot.export_format}' not supported!"
)
4 changes: 1 addition & 3 deletions src/hpc_multibench/plot/plot_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from hpc_multibench.uncertainties import UFloat
from hpc_multibench.yaml_model import BarChartModel, LinePlotModel, RooflinePlotModel

# from labellines import labelLines


sns.set_theme()


Expand Down Expand Up @@ -78,6 +75,7 @@ def draw_roofline_plot(
plt.plot(x, y, label=label)
for label, (x, y) in roofline.compute_bound_ceilings.items():
plt.plot(x, y, label=label)
# from labellines import labelLines
# for ax in plt.gcf().axes:
# labelLines(ax.get_lines())
for name, (x_point, y_point, x_err, y_err) in data.items():
Expand Down
11 changes: 6 additions & 5 deletions src/hpc_multibench/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from typing_extensions import Self

from hpc_multibench.plot.export_data import export_data
from hpc_multibench.plot.plot_matplotlib import (
draw_bar_chart,
draw_line_plot,
Expand Down Expand Up @@ -82,7 +83,7 @@ def __init__(
# Validate that all configurations named in the test bench are defined
# in the test plan
for run_configuration_name in bench_model.run_configurations:
if run_configuration_name not in self.run_configuration_models.keys():
if run_configuration_name not in self.run_configuration_models:
raise RuntimeError(
f"'{run_configuration_name}' not in list of"
" defined run configurations!"
Expand All @@ -100,10 +101,7 @@ def instantiations(self) -> list[dict[str, Any]]:
(
[[(key, value)] for value in values]
if isinstance(key, str)
else [
[(k, v) for k, v in zip(key, setting, strict=True)]
for setting in values
]
else [list(zip(key, setting, strict=True)) for setting in values]
)
for key, values in self.bench_model.matrix.items()
]
Expand Down Expand Up @@ -424,3 +422,6 @@ def report(self) -> None:

for roofline_plot in self.bench_model.analysis.roofline_plots:
draw_roofline_plot(roofline_plot, aggregated_metrics)

for export_schema in self.bench_model.analysis.data_exports:
export_data(export_schema, aggregated_metrics)
11 changes: 6 additions & 5 deletions src/hpc_multibench/yaml_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ class RooflinePlotModel(BaseModel):
ert_json: Path


# class ExportModel(BaseModel):
# """A Pydantic model for a exporting a set of metrics."""
class ExportModel(BaseModel):
"""A Pydantic model for a exporting a set of metrics."""

# metrics: list[str]
# filename: Path | None = None
export_path: Path | None
export_format: str = "csv"
# metrics: list[str] | None = None


class AnalysisModel(BaseModel):
Expand All @@ -98,7 +99,7 @@ class AnalysisModel(BaseModel):
line_plots: list[LinePlotModel] = []
bar_charts: list[BarChartModel] = []
roofline_plots: list[RooflinePlotModel] = []
# exports: list[BarChartModel] = []
data_exports: list[ExportModel] = []


class RerunModel(BaseModel):
Expand Down

0 comments on commit 97b6de6

Please sign in to comment.