Skip to content

Commit 5864f37

Browse files
author
telemin
committed
improve default metric ref_key choice
1 parent 015f800 commit 5864f37

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

pypop/metrics/metricset.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,42 @@ def __init__(self, stats_data, ref_key=None, sort_keys=True):
7373
used as the dataframe index. If a list, a dict will be constructed by
7474
enumeration.
7575
76-
ref_key: scalar
76+
ref_key: str or None
7777
Key of stats_dict that should be used as the reference for calculation of
78-
scaling values. If not specified, the lexical minimum key will be used (i.e
79-
``min(stats_dict.keys())``.
78+
scaling values. By default the trace with smallest number of processes and
79+
smallest number of threads per process will be used.
8080
8181
sort_keys: bool
8282
If true (default), lexically sort the keys in the returned DataFrame.
8383
"""
8484

8585
self._stats_dict = MetricSet._dictify_stats(stats_data)
8686
self._metric_data = None
87-
self._ref_key = ref_key
8887
self._sort_keys = sort_keys
88+
self._ref_key = (
89+
self._choose_ref_key(self._stats_dict) if ref_key is None else ref_key
90+
)
8991

9092
def _calculate_metrics(self):
9193
raise NotImplementedError
9294

9395
def _repr_html_(self):
9496
return self.metric_data._repr_html_()
9597

98+
@staticmethod
99+
def _choose_ref_key(stats_dict):
100+
""" Take the stats dict and choose an appropriate reference trace.
101+
102+
As a default choice choose the smallest number of processes, breaking ties with
103+
smallest number of threads per process
104+
"""
105+
106+
sort_key = lambda x: "{:05}_{:05}".format(
107+
x[1].metadata.num_processes, x[1].metadata.threads_per_process[0]
108+
)
109+
110+
return min(stats_dict.items(), key=sort_key)[0]
111+
96112
@property
97113
def metric_data(self):
98114
"""pandas.DataFrame: Calculated metric data.

0 commit comments

Comments
 (0)