Skip to content

Commit

Permalink
Rename make_superthicket (#98)
Browse files Browse the repository at this point in the history
* Rename make_superthicket to from_statsframes

* Rename function param profiles_from_meta to metadata_key
  • Loading branch information
michaelmckinsey1 authored Oct 9, 2023
1 parent e908a15 commit 8bd8fcf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
10 changes: 5 additions & 5 deletions thicket/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ def _handle_statsframe():
return combined_th

@staticmethod
def _index(thickets, superthicket=False):
def _index(thickets, from_statsframes=False):
"""Unify a list of thickets into a single thicket
Arguments:
superthicket (bool): whether the result is a superthicket
from_statsframes (bool): Whether this method was invoked from from_statsframes
Returns:
unify_graph (hatchet.Graph): unified graph,
Expand All @@ -316,7 +316,7 @@ def _fill_perfdata(perfdata, fill_value=np.nan):

return perfdata

def _superthicket_metadata(metadata):
def _from_statsframes_metadata(metadata):
"""Aggregate data in Metadata"""

def _agg_to_set(obj):
Expand Down Expand Up @@ -373,8 +373,8 @@ def _agg_to_set(obj):
unify_df = _fill_perfdata(unify_df)

# Metadata-specific operations
if superthicket:
_superthicket_metadata(unify_metadata)
if from_statsframes:
_from_statsframes_metadata(unify_metadata)

# Sort PerfData
unify_df.sort_index(inplace=True)
Expand Down
16 changes: 7 additions & 9 deletions thicket/tests/test_make_superthicket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from thicket import Thicket as th


def test_make_superthicket(mpi_scaling_cali):
def test_from_statsframes(mpi_scaling_cali):
th_list = []
for file in mpi_scaling_cali:
th_list.append(th.from_caliperreader(file))
Expand All @@ -17,30 +17,28 @@ def test_make_superthicket(mpi_scaling_cali):
t.statsframe.dataframe["test"] = t_val
t_val += 2

superthicket = th.make_superthicket(th_list)
tk = th.from_statsframes(th_list)

# Check level values
assert set(superthicket.dataframe.index.get_level_values("thicket")) == {
assert set(tk.dataframe.index.get_level_values("thicket")) == {
0,
1,
2,
3,
4,
}
# Check performance data table values
assert set(superthicket.dataframe["test"]) == {0, 2, 4, 6, 8}
assert set(tk.dataframe["test"]) == {0, 2, 4, 6, 8}

superthicket_named = th.make_superthicket(
th_list, profiles_from_meta="mpi.world.size"
)
tk_named = th.from_statsframes(th_list, metadata_key="mpi.world.size")

# Check level values
assert set(superthicket_named.dataframe.index.get_level_values("thicket")) == {
assert set(tk_named.dataframe.index.get_level_values("thicket")) == {
27,
64,
125,
216,
343,
}
# Check performance data table values
assert set(superthicket_named.dataframe["test"]) == {0, 2, 4, 6, 8}
assert set(tk_named.dataframe["test"]) == {0, 2, 4, 6, 8}
30 changes: 15 additions & 15 deletions thicket/thicket.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def concat_thickets(thickets, axis="index", calltree="union", **kwargs):
valid kwargs:
if axis="index":
superthicket (bool): Whether the result is a superthicket
from_statsframes (bool): Whether this method was invoked from from_statsframes
if axis="columns":
headers (list): List of headers to use for the new columnar multi-index.
metadata_key (str): Name of the column from the metadata tables to replace the 'profile'
Expand All @@ -284,9 +284,9 @@ def concat_thickets(thickets, axis="index", calltree="union", **kwargs):
(thicket): concatenated thicket
"""

def _index(thickets, superthicket=False):
def _index(thickets, from_statsframes=False):
thicket_parts = Ensemble._index(
thickets=thickets, superthicket=superthicket
thickets=thickets, from_statsframes=from_statsframes
)

return Thicket(
Expand Down Expand Up @@ -328,7 +328,7 @@ def columnar_join(thicket_list, header_list=None, metadata_key=None):
)

@staticmethod
def unify_ensemble(th_list, superthicket=False):
def unify_ensemble(th_list, from_statsframes=False):
raise ValueError(
"unify_ensemble is deprecated. Use 'concat_thickets(axis='index'...)' instead."
)
Expand Down Expand Up @@ -597,21 +597,21 @@ def tree(
)

@staticmethod
def make_superthicket(th_list, profiles_from_meta=None):
"""Convert a list of thickets into a 'superthicket'.
def from_statsframes(th_list, metadata_key=None):
"""Compose a list of Thickets with data in their statsframes.
Their individual aggregated statistics table are ensembled and become the
superthicket's performance data table.
The Thicket's individual aggregated statistics tables are ensembled and become the
new Thickets performance data table.
Arguments:
th_list (list): list of thickets
profiles_from_meta (str, optional): name of the metadata column to use as
metadata_key (str, optional): name of the metadata column to use as
the new second-level index. Uses the first value so this only makes
sense if provided column is all equal values and each thicket's columns
differ in value.
Returns:
(thicket): superthicket
(thicket): New Thicket object.
"""
# Pre-check of data structures
for th in th_list:
Expand All @@ -624,17 +624,17 @@ def make_superthicket(th_list, profiles_from_meta=None):

# Setup names list
th_names = []
if profiles_from_meta is None:
if metadata_key is None:
for i in range(len(th_list)):
th_names.append(i)
else: # profiles_from_meta was provided.
else: # metadata_key was provided.
for th in th_list:
# Get name from metadata table
name_list = th.metadata[profiles_from_meta].tolist()
name_list = th.metadata[metadata_key].tolist()

if len(name_list) > 1:
warnings.warn(
f"Multiple values for name {name_list} at thicket.metadata[{profiles_from_meta}]. Only the first will be used."
f"Multiple values for name {name_list} at thicket.metadata[{metadata_key}]. Only the first will be used."
)
th_names.append(name_list[0])

Expand Down Expand Up @@ -667,7 +667,7 @@ def make_superthicket(th_list, profiles_from_meta=None):
# Append copy to list
th_copy_list.append(th_copy)

return Thicket.concat_thickets(th_copy_list, superthicket=True)
return Thicket.concat_thickets(th_copy_list, from_statsframes=True)

def to_json(self, ensemble=True, metadata=True, stats=True):
jsonified_thicket = {}
Expand Down

0 comments on commit 8bd8fcf

Please sign in to comment.