Skip to content

Commit aff252c

Browse files
authored
Merge pull request #21 from mhkarsten/powerletrics_pynvml_integratiion
Improved Fib Example with Plot
2 parents 0148212 + ee18713 commit aff252c

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

examples/hello-world-fibonacci/RunnerConfig.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ def create_run_table_model(self) -> RunTableModel:
5555
"""Create and return the run_table model here. A run_table is a List (rows) of tuples (columns),
5656
representing each run performed"""
5757
factor1 = FactorModel("fib_type", ['iter', 'mem', 'rec'])
58-
factor2 = FactorModel("problem_size", [10, 20, 30])
58+
factor2 = FactorModel("problem_size", [10, 35, 40, 5000, 10000])
5959
self.run_table_model = RunTableModel(
6060
factors=[factor1, factor2],
6161
exclude_combinations=[
62-
{factor2: [10]}, # all runs having treatment "10" will be excluded
63-
{factor1: ['iter'], factor2: [30]}, # all runs having the combination ("iter", 30) will be excluded
62+
{factor2: [10]}, # all runs having treatment "10" will be excluded
63+
{factor1: ['rec'], factor2: [5000, 10000]},
64+
{factor1: ['mem', 'iter'], factor2: [35, 40]}, # all runs having the combination ("iter", 30) will be excluded
6465
],
65-
repetitions = 3,
66-
data_columns=["total_power (J)", "runtime (sec)", "avg_mem (bytes)"]
66+
repetitions = 10,
67+
data_columns=["energy", "runtime", "memory"]
6768
)
6869
return self.run_table_model
6970

@@ -114,9 +115,9 @@ def populate_run_data(self, context: RunnerContext) -> Optional[Dict[str, Any]]:
114115
eb_log, eb_summary = self.profiler.parse_log(self.profiler.logfile,
115116
self.profiler.summary_logfile)
116117

117-
return {"total_power (J)": eb_summary["total_joules"],
118-
"runtime (sec)": eb_summary["runtime_seconds"],
119-
"total_mem (bytes)": list(eb_log["TOTAL_MEMORY"].values())[-1]}
118+
return {"energy": list(eb_log["PACKAGE_ENERGY (J)"].values())[-1] - list(eb_log["PACKAGE_ENERGY (J)"].values())[0],
119+
"runtime": eb_summary["runtime_seconds"],
120+
"memory": max(eb_log["USED_MEMORY"].values())}
120121

121122
def after_experiment(self) -> None:
122123
"""Perform any activity required after stopping the experiment here
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import matplotlib.pyplot as plt
2+
import pandas as pd
3+
from pathlib import Path
4+
import seaborn as sb
5+
import sys
6+
import os
7+
8+
exp_path = os.path.join("examples", "hello-world-fibonacci")
9+
10+
if __name__ == "__main__":
11+
if not os.path.exists(os.path.join(exp_path, "experiments", "new_runner_experiment")):
12+
print("Please run the example, so a valid 'experiments' directory exists")
13+
exit(1)
14+
15+
results = pd.read_csv(os.path.join(exp_path, "experiments", "new_runner_experiment", "run_table.csv"))
16+
17+
print(results)
18+
19+
sb.stripplot(data=results,
20+
x="fib_type",
21+
y="energy",
22+
hue="problem_size",
23+
palette="Paired",
24+
order=["mem", "iter", "rec"],
25+
jitter=True)
26+
27+
plt.xlabel("Fibonacci Type")
28+
plt.ylabel("Energy Consumption (Joules)")
29+
plt.title("ER Demo Results")
30+
31+
plt.savefig(os.path.join(exp_path, "fib_plot.png"))
32+
33+
34+
35+
36+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pandas
2+
seaborn

experiment-runner/Plugins/Profilers/EnergiBridge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def stop(self, wait=False):
8282
# If runtime was too short, energibridge doesnt provide a summary
8383
# Approximate this instead
8484
if not last_line.startswith("Energy consumption"):
85+
print("[WARNING] EnergiBridge summary approximated, runtime too short")
8586
last_line = self.generate_summary()
8687

8788
f.write(last_line)

0 commit comments

Comments
 (0)