Skip to content

Commit 9d6719b

Browse files
committed
add trace tagging support
1 parent 8b56595 commit 9d6719b

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

pypop/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def _preprocess_traces_parse_args():
133133
parser.add_argument(
134134
"--dimemas-path", type=str, metavar="PATH", help="Path to Dimemas executable"
135135
)
136+
137+
parser.add_argument(
138+
"--tag", type=str, metavar="TAG", help="Tag to apply to trace(s)"
139+
)
136140
parser.add_argument(
137141
"--outfile-path",
138142
type=str,
@@ -274,6 +278,7 @@ def preprocess_traces():
274278
force_recalculation=config.force_recalculation,
275279
chop_to_roi=config.chop_to_roi,
276280
outpath=config.outfile_path,
281+
tag=config.tag,
277282
)
278283

279284

pypop/metrics/metricset.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class MetricSet:
5959
"Threads per Process": "",
6060
"Total Threads": "",
6161
"Hybrid Layout": "",
62+
"Tag": "",
6263
}
6364

6465
def __init__(self, stats_data, ref_key=None, sort_keys=True):
@@ -102,9 +103,10 @@ def _choose_ref_key(stats_dict):
102103

103104
return min(
104105
stats_dict.items(),
105-
key=lambda x: "{:05}_{:05}".format(
106+
key=lambda x: "{:05}_{:05}_{}".format(
106107
sum(x[1].metadata.threads_per_process),
107108
max(x[1].metadata.threads_per_process),
109+
x[1].metadata.tag,
108110
),
109111
)[0]
110112

@@ -165,6 +167,7 @@ def _create_subdataframe(self, metadata, idxkey):
165167
],
166168
index=[idxkey],
167169
),
170+
"Tag": pandas.Series(data=[metadata.tag], index=[idxkey]),
168171
}
169172

170173
for metric in self._metric_list:
@@ -182,6 +185,7 @@ def plot_table(
182185
**kwargs
183186
):
184187
from pypop.notebook_interface.plotting import MetricTable
188+
185189
return MetricTable(
186190
self,
187191
columns_key=columns_key,
@@ -201,6 +205,7 @@ def plot_scaling(
201205
**kwargs
202206
):
203207
from pypop.notebook_interface.plotting import ScalingPlot
208+
204209
return ScalingPlot(
205210
self,
206211
scaling_variable=scaling_variable,

pypop/trace/trace.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ def __new__(cls, filename, **kwargs):
4242
return super().__new__(cls)
4343

4444
@staticmethod
45-
def load(filename, force_recalculation=False, **kwargs):
45+
def load(filename, force_recalculation=False, tag=None, **kwargs):
4646

4747
if force_recalculation is False:
4848
# First try to open file as if it *is* a summary file
4949
try:
50-
return Trace._load_from_summary_file(filename, **kwargs)
50+
summaryloaded = Trace._load_from_summary_file(
51+
filename, tag=tag, **kwargs
52+
)
5153
except WrongLoaderError:
5254
# Otherwise, see if it has a summaryfile present
5355
try:
54-
return Trace._load_from_summary_file(
55-
Trace.get_summary_filename(filename), **kwargs
56+
summaryloaded = Trace._load_from_summary_file(
57+
Trace.get_summary_filename(filename), tag=tag, **kwargs
5658
)
5759
# Fallback - assume valid trace with no summary
5860
except (WrongLoaderError, FileNotFoundError):
@@ -62,21 +64,21 @@ def load(filename, force_recalculation=False, **kwargs):
6264
for loader in Trace._loader_registry.values():
6365
try:
6466
return loader(
65-
filename, force_recalculation=force_recalculation, **kwargs
67+
filename, force_recalculation=force_recalculation, tag=tag, **kwargs
6668
)
6769
except WrongLoaderError:
6870
pass
6971

7072
raise ValueError("Invalid or unsupported trace {}".format(filename))
7173

7274
@staticmethod
73-
def _load_from_summary_file(filename, **kwargs):
75+
def _load_from_summary_file(filename, tag=None, **kwargs):
7476

7577
# This will raise a WrongLoader error already so no need to trap and reraise
7678
metadata, _ = Trace._parse_summary_file(filename)
7779

7880
try:
79-
return Trace._loader_registry[metadata.trace_subclass_name](
81+
trace = Trace._loader_registry[metadata.trace_subclass_name](
8082
filename, **kwargs
8183
)
8284
except KeyError:
@@ -86,7 +88,12 @@ def _load_from_summary_file(filename, **kwargs):
8688
"".format(metadata.trace_subclass_name)
8789
)
8890

89-
def __init__(self, filename, force_recalculation=False, **kwargs):
91+
if tag is not None:
92+
warn("Loading from summary, tag argument ignored")
93+
94+
return trace
95+
96+
def __init__(self, filename, force_recalculation=False, tag=None, **kwargs):
9097
# Save keyword args for later
9198
self._kwargs = kwargs
9299

@@ -115,6 +122,8 @@ def __init__(self, filename, force_recalculation=False, **kwargs):
115122
pass
116123

117124
self._metadata = TraceMetadata(self)
125+
if tag:
126+
self._metadata.tag = tag
118127
self._statistics = None
119128

120129
# Loading from a tracefile so

pypop/trace/tracemetadata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ class TraceMetadata:
3535
# "layout": str,
3636
"tracefile_name": str,
3737
"fingerprint": str,
38+
"tag": str,
3839
}
3940

41+
_optional = {"tag"}
42+
4043
_needs_packing = ["layout", "threads_per_process"]
4144

4245
def __init__(self, parent):
@@ -58,7 +61,9 @@ def unpack_dataframe(dataframe):
5861
try:
5962
packed_data = dataframe[var]
6063
except KeyError as err:
61-
warn("Missing data value: {}".format(err))
64+
if var not in metadata._optional:
65+
warn("Missing metadata entry: {}".format(err))
66+
setattr(metadata, var, None)
6267
continue
6368
if var in metadata._needs_packing:
6469
unpack = getattr(metadata, "unpack_{}".format(var))
@@ -73,6 +78,8 @@ def pack_dataframe(self):
7378
data = {}
7479

7580
for var, vartype in self._datavars.items():
81+
if getattr(self, var) is None:
82+
continue
7683
if var in self._needs_packing:
7784
pack = getattr(self, "pack_{}".format(var))
7885
packed = pack(getattr(self, var), vartype)

pypop/traceset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
no_progress=False,
6767
outpath=None,
6868
ignore_cache=None,
69+
tag=None,
6970
):
7071
# Setup data structures
7172
self.traces = set()
@@ -79,7 +80,7 @@ def __init__(
7980

8081
# Add traces
8182
self.add_traces(
82-
path_list, force_recalculation, chop_to_roi, no_progress, outpath
83+
path_list, force_recalculation, chop_to_roi, no_progress, outpath, tag
8384
)
8485

8586
def add_traces(
@@ -89,6 +90,7 @@ def add_traces(
8990
chop_to_roi=False,
9091
no_progress=False,
9192
outpath=None,
93+
tag=None,
9294
):
9395
"""Collect statistics from provided trace files, currently only Extrae .prv files
9496
are supported.
@@ -137,6 +139,7 @@ def add_traces(
137139
force_recalculation=force_recalculation,
138140
chop_to_roi=chop_to_roi,
139141
outpath=outpath,
142+
tag=tag,
140143
)
141144
)
142145

0 commit comments

Comments
 (0)