1717import matplotlib .ticker as mtick
1818
1919from ..trace import Trace
20+ from ..traceset import TraceSet
2021from .._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
0 commit comments