Skip to content

Commit 015f800

Browse files
author
telemin
committed
improve metricset handling of tracesets
1 parent e944a94 commit 015f800

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

pypop/metrics/hybrid.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class MPI_OpenMP_Ineff_Metrics(MetricSet):
3737
Metric("IPC Scaling", 2, "IPC Scaling"),
3838
]
3939

40-
_default_metric_key = "Hybrid Layout"
40+
_default_metric_key = "Number of Processes"
41+
_default_group_key = "Threads per Process"
4142

4243
def _calculate_metrics(self, ref_key=None, sort_keys=True):
4344
if not ref_key:
@@ -186,7 +187,8 @@ class MPI_OpenMP_Metrics(MetricSet):
186187
Metric("IPC Scaling", 2, "IPC Scaling"),
187188
]
188189

189-
_default_metric_key = "Hybrid Layout"
190+
_default_metric_key = "Number of Processes"
191+
_default_group_key = "Threads per Process"
190192

191193
def _calculate_metrics(self, ref_key=None, sort_keys=True):
192194
if not ref_key:
@@ -344,7 +346,8 @@ class MPI_OpenMP_Multiplicative_Metrics(MetricSet):
344346
Metric("IPC Scaling", 2, "IPC Scaling"),
345347
]
346348

347-
_default_metric_key = "Hybrid Layout"
349+
_default_metric_key = "Number of Processes"
350+
_default_group_key = "Threads per Process"
348351

349352
def _calculate_metrics(self, ref_key=None, sort_keys=True):
350353
if not ref_key:

pypop/metrics/judit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Judit_Hybrid_Metrics(MetricSet):
3232
Metric("IPC Scaling", 2, "IPC Scaling"),
3333
]
3434

35-
_default_metric_key = "Hybrid Layout"
35+
_default_metric_key = "Number of Processes"
36+
_default_group_key = "Threads per Process"
3637

3738
def _calculate_metrics(self, ref_key=None, sort_keys=True):
3839
if not ref_key:

pypop/metrics/metricset.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import matplotlib.ticker as mtick
1818

1919
from ..trace import Trace
20+
from ..traceset import TraceSet
2021
from .._plotsettings import pypop_mpl_params, figparams
2122

2223
__all__ = ["Metric", "MetricSet"]
@@ -54,12 +55,20 @@ class MetricSet:
5455
"""
5556

5657
_default_metric_key = None
58+
_default_group_key = None
5759

58-
def __init__(self, stats_dict, ref_key=None, sort_keys=True):
60+
_key_descriptions = {
61+
"Number of Processes": "",
62+
"Threads per Process": "",
63+
"Total Threads": "",
64+
"Hybrid Layout": "",
65+
}
66+
67+
def __init__(self, stats_data, ref_key=None, sort_keys=True):
5968
"""
6069
Parameters
6170
----------
62-
stats_dict: dict or list of `pd.DataFrame`
71+
stats_data: TraceSet instance, dict, iterable or instance of Trace
6372
Statistics as collected with `collect_statistics()`. Dictionary keys will be
6473
used as the dataframe index. If a list, a dict will be constructed by
6574
enumeration.
@@ -73,16 +82,7 @@ def __init__(self, stats_dict, ref_key=None, sort_keys=True):
7382
If true (default), lexically sort the keys in the returned DataFrame.
7483
"""
7584

76-
if not isinstance(stats_dict, dict):
77-
stats_dict = {k: v for k, v in enumerate(stats_dict)}
78-
79-
for df in stats_dict.values():
80-
if not isinstance(df, Trace):
81-
raise ValueError(
82-
"stats_dict must be an iterable of pypop.traceset.RunData"
83-
)
84-
85-
self._stats_dict = stats_dict
85+
self._stats_dict = MetricSet._dictify_stats(stats_data)
8686
self._metric_data = None
8787
self._ref_key = ref_key
8888
self._sort_keys = sort_keys
@@ -101,6 +101,22 @@ def metric_data(self):
101101
self._calculate_metrics(ref_key=self._ref_key)
102102
return self._metric_data
103103

104+
@staticmethod
105+
def _dictify_stats(stats_data):
106+
if isinstance(stats_data, TraceSet):
107+
return {k: v for k, v in enumerate(stats_data.traces)}
108+
else:
109+
if isinstance(stats_data, Trace):
110+
return {0: stats_data}
111+
if not isinstance(stats_data, dict):
112+
stats_data = {k: v for k, v in enumerate(stats_data)}
113+
114+
for df in stats_data.values():
115+
if not isinstance(df, Trace):
116+
raise ValueError("stats_dict must be an iterable of pypop.trace.Trace")
117+
118+
return stats_data
119+
104120
@property
105121
def metrics(self):
106122
"""List of :py:class:`pypop.metrics.Metric`: List of metrics that will be

pypop/traceset.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def by_threads_per_process(self):
176176
177177
This is a helper function equivalent to
178178
179-
by_key(lambda x: x.metadata.rank_threads[0])
179+
by_key(lambda x: x.metadata.threads_per_process[0])
180180
181181
Returns
182182
-------
@@ -185,3 +185,26 @@ def by_threads_per_process(self):
185185
"""
186186

187187
return self.by_key(lambda x: x.metadata.threads_per_process[0])
188+
189+
def by_hybrid_layout(self):
190+
"""Return a dictionary of traces keyed by hybrid layout
191+
192+
This is a helper function equivalent to
193+
194+
by_key(
195+
lambda x: "{}x{}".format(
196+
x.metadata.num_processes, x.metadata.threads_per_process[0]
197+
)
198+
)
199+
200+
Returns
201+
-------
202+
traces_by_key: dict
203+
A dictionary of traces organised by the requested key
204+
"""
205+
206+
return self.by_key(
207+
lambda x: "{}x{}".format(
208+
x.metadata.num_processes, x.metadata.threads_per_process[0]
209+
)
210+
)

0 commit comments

Comments
 (0)