-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timeseries and calc_temporal_pattern (#88)
* timeseries and temporal pattern functionality initial tests added test files fixed the from_timeseries function memory pattern mapping works, still needs cleanup adding memory pattern visual to tree refactor to temporal pattern * switched to concat_thickets from unify_ensemble
- Loading branch information
Showing
9 changed files
with
8,126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2022 Lawrence Livermore National Security, LLC and other | ||
# Thicket Project Developers. See the top-level LICENSE file for details. | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
from ..utils import verify_thicket_structures | ||
|
||
|
||
def calc_temporal_pattern(thicket, columns=None): | ||
"""Calculate the associated temporal pattern with the passed in columns. | ||
Designed to take in a timeseries thicket, and append two columns to the | ||
aggregated statistics (statsframe) table for the temporal pattern calculated on each node over time. | ||
The two additional columns include the _temporal_score, and the _pattern associated with that score. | ||
The score assigns a value between 0 and 1 based on how drastically the values change over time | ||
Arguments: | ||
thicket (thicket): timeseries Thicket object | ||
columns (list): List of numeric columns to calculate temporal pattern. | ||
Note, if using a columnar joined thicket a list of tuples must be passed in | ||
with the format (column index, column name). | ||
Returns: | ||
(list): returns a list of output statsframe column names | ||
""" | ||
if columns is None: | ||
raise ValueError( | ||
"To see a list of valid columns, run 'Thicket.performance_cols'." | ||
) | ||
|
||
if "iteration" not in thicket.dataframe.index.names: | ||
raise ValueError( | ||
"Must have a timeseries thicket with iteration as an index level" | ||
) | ||
|
||
verify_thicket_structures(thicket.dataframe, index=["node"], columns=columns) | ||
|
||
output_column_names = [] | ||
|
||
for column in columns: | ||
if not pd.api.types.is_numeric_dtype(thicket.dataframe[column]): | ||
raise ValueError("Column data type must be numeric") | ||
pattern_col = [] | ||
score_col = [] | ||
# for any node that has temporal values we can calculate the pattern per node | ||
for node, node_df in thicket.dataframe.groupby(level=0): | ||
# if the node has any nans, pattern is none | ||
if node_df[column].isna().values.any(): | ||
pattern = "none" | ||
score = np.nan | ||
else: | ||
values = node_df[column] | ||
score = 1 - (sum(values) / (max(values) * len(values))) | ||
if score < 0.2: | ||
pattern = "constant" | ||
elif score >= 0.2 and score < 0.4: | ||
pattern = "phased" | ||
elif score >= 0.4 and score < 0.6: | ||
pattern = "dynamic" | ||
else: | ||
pattern = "sporadic" | ||
pattern_col.append(pattern) | ||
score_col.append(score) | ||
|
||
# add the new columns to the statsframe and output list | ||
pattern_column_name = column + "_pattern" | ||
score_column_name = column + "_temporal_score" | ||
thicket.statsframe.dataframe[pattern_column_name] = pattern_col | ||
thicket.statsframe.dataframe[score_column_name] = score_col | ||
output_column_names.append(pattern_column_name) | ||
output_column_names.append(score_column_name) | ||
|
||
return output_column_names |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
__rec=node,id=21,attr=10,data=1612,parent=3 | ||
__rec=node,id=92,attr=8,data=caliper.config,parent=21 | ||
__rec=node,id=89,attr=10,data=1612,parent=1 | ||
__rec=node,id=90,attr=8,data=iterations,parent=89 | ||
__rec=node,id=22,attr=8,data=cali.caliper.version,parent=21 | ||
__rec=node,id=23,attr=22,data=2.10.0-dev | ||
__rec=node,id=91,attr=90,data=100,parent=23 | ||
__rec=node,id=93,attr=92,data=,parent=91 | ||
__rec=node,id=30,attr=10,data=85,parent=5 | ||
__rec=node,id=67,attr=8,data=min#time.duration.ns,parent=30 | ||
__rec=node,id=68,attr=8,data=max#time.duration.ns,parent=30 | ||
__rec=node,id=69,attr=8,data=sum#time.duration.ns,parent=30 | ||
__rec=node,id=70,attr=8,data=avg#time.duration.ns,parent=30 | ||
__rec=node,id=32,attr=10,data=85,parent=2 | ||
__rec=node,id=85,attr=8,data=count,parent=32 | ||
__rec=node,id=86,attr=8,data=aggregate.slot,parent=32 | ||
__rec=node,id=26,attr=10,data=2133,parent=1 | ||
__rec=node,id=27,attr=8,data=loop.iterations,parent=26 | ||
__rec=node,id=31,attr=8,data=timeseries.starttime,parent=30 | ||
__rec=node,id=33,attr=8,data=timeseries.snapshot,parent=32 | ||
__rec=ctx,ref=93,attr=67=68=69=70=85=86=27=31=33,data=448713.000000=448713.000000=448713.000000=448713.000000=1=0=0=1689118709.135139=0 | ||
__rec=node,id=18,attr=10,data=276,parent=3 | ||
__rec=node,id=20,attr=8,data=region,parent=18 | ||
__rec=node,id=94,attr=20,data=main | ||
__rec=ctx,ref=94=93,attr=67=68=69=70=85=86=27=31=33,data=59851.000000=59851.000000=59851.000000=59851.000000=1=1=0=1689118709.135139=0 | ||
__rec=node,id=95,attr=20,data=init,parent=94 | ||
__rec=node,id=42,attr=8,data=min#region.count,parent=30 | ||
__rec=node,id=43,attr=8,data=max#region.count,parent=30 | ||
__rec=node,id=44,attr=8,data=sum#region.count,parent=30 | ||
__rec=node,id=45,attr=8,data=avg#region.count,parent=30 | ||
__rec=ctx,ref=95=93,attr=42=43=44=45=67=68=69=70=85=86=27=31=33,data=1.000000=1.000000=1.000000=1.000000=12219.000000=12219.000000=12219.000000=12219.000000=1=2=0=1689118709.135139=0 | ||
__rec=node,id=34,attr=10,data=2133,parent=5 | ||
__rec=node,id=35,attr=8,data=timeseries.duration,parent=34 | ||
__rec=ctx,ref=94=93,attr=27=31=33=35=31,data=0=1689118709.135139=0=0.001398=1689118709.136537 | ||
__rec=node,id=28,attr=10,data=85,parent=1 | ||
__rec=node,id=29,attr=8,data=loop.start_iteration,parent=28 | ||
__rec=ctx,ref=94=93,attr=67=68=69=70=85=86=27=29=31=33,data=200739.000000=200739.000000=200739.000000=200739.000000=1=0=20=0=1689118709.136537=1 | ||
__rec=node,id=19,attr=8,data=loop,parent=18 | ||
__rec=node,id=103,attr=19,data=mainloop,parent=94 | ||
__rec=ctx,ref=103=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=19.000000=1.000000=3306.000000=13928.000000=282447.000000=4787.237288=59=1=20=0=1689118709.136537=1 | ||
__rec=node,id=104,attr=20,data=foo,parent=103 | ||
__rec=ctx,ref=104=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=141457.000000=219005.000000=3281358.000000=164067.900000=20=2=20=0=1689118709.136537=1 | ||
__rec=node,id=12,attr=10,data=84,parent=6 | ||
__rec=node,id=16,attr=8,data=class.iteration,parent=12 | ||
__rec=node,id=96,attr=16,data=true,parent=1 | ||
__rec=node,id=97,attr=10,data=21,parent=96 | ||
__rec=node,id=98,attr=8,data=iteration#mainloop,parent=97 | ||
__rec=ctx,ref=103=93,attr=27=29=31=33=35=31=98,data=20=0=1689118709.136537=1=0.003734=1689118709.140271=19 | ||
__rec=ctx,ref=103=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=3238.000000=83328.000000=357604.000000=5960.066667=60=0=20=20=1689118709.140271=2 | ||
__rec=ctx,ref=104=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=159474.000000=209917.000000=3364016.000000=168200.800000=20=1=20=20=1689118709.140271=2 | ||
__rec=ctx,ref=103=93,attr=27=29=31=33=35=31=98,data=20=20=1689118709.140271=2=0.003722=1689118709.143993=39 | ||
__rec=ctx,ref=103=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=3213.000000=84229.000000=402162.000000=6702.700000=60=0=20=40=1689118709.143993=3 | ||
__rec=ctx,ref=104=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=159545.000000=335990.000000=3522373.000000=176118.650000=20=1=20=40=1689118709.143993=3 | ||
__rec=ctx,ref=103=93,attr=27=29=31=33=35=31=98,data=20=40=1689118709.143993=3=0.003928=1689118709.147921=59 | ||
__rec=ctx,ref=103=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=3342.000000=96083.000000=348946.000000=5815.766667=60=0=20=60=1689118709.147921=4 | ||
__rec=ctx,ref=104=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=136880.000000=173199.000000=3203448.000000=160172.400000=20=1=20=60=1689118709.147921=4 | ||
__rec=ctx,ref=103=93,attr=27=29=31=33=35=31=98,data=20=60=1689118709.147921=4=0.003560=1689118709.151481=79 | ||
__rec=ctx,ref=103=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=3308.000000=112210.000000=407532.000000=6792.200000=60=0=20=80=1689118709.151481=5 | ||
__rec=ctx,ref=104=93,attr=42=43=44=45=67=68=69=70=85=86=27=29=31=33,data=1.000000=1.000000=20.000000=1.000000=156252.000000=715191.000000=4120824.000000=206041.200000=20=1=20=80=1689118709.151481=5 | ||
__rec=ctx,ref=103=93,attr=27=29=31=33=35=31=98,data=20=80=1689118709.151481=5=0.004522=1689118709.156003=99 | ||
__rec=ctx,ref=103=93,attr=42=43=44=45=67=68=69=70=85=86=27=31=33,data=1.000000=1.000000=1.000000=1.000000=114486.000000=114486.000000=114486.000000=114486.000000=1=0=0=1689118709.156003=6 | ||
__rec=ctx,ref=103=93,attr=27=31=33=35=31,data=0=1689118709.156003=6=0.000119=1689118709.156122 | ||
__rec=node,id=24,attr=8,data=cali.channel,parent=21 | ||
__rec=node,id=25,attr=24,data=default | ||
__rec=globals,ref=93=25 |
34 changes: 34 additions & 0 deletions
34
thicket/tests/data/example-timeseries/mem_power_timeseries.cali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
__rec=node,id=26,attr=10,data=2125,parent=1 | ||
__rec=node,id=27,attr=8,data=loop.iterations,parent=26 | ||
__rec=node,id=30,attr=10,data=2061,parent=2 | ||
__rec=node,id=31,attr=8,data=memstat.vmsize,parent=30 | ||
__rec=node,id=32,attr=8,data=memstat.vmrss,parent=30 | ||
__rec=node,id=33,attr=8,data=memstat.data,parent=30 | ||
__rec=node,id=36,attr=10,data=2133,parent=2 | ||
__rec=node,id=37,attr=8,data=variorum.val.power_node_watts,parent=36 | ||
__rec=node,id=38,attr=8,data=variorum.power_node_watts,parent=36 | ||
__rec=node,id=18,attr=10,data=268,parent=3 | ||
__rec=node,id=20,attr=8,data=region,parent=18 | ||
__rec=node,id=41,attr=20,data=main | ||
__rec=node,id=21,attr=10,data=1612,parent=3 | ||
__rec=node,id=22,attr=8,data=cali.caliper.version,parent=21 | ||
__rec=node,id=23,attr=22,data=2.10.0 | ||
__rec=ctx,ref=41=23,attr=27=31=32=33=37=38,data=0=923=679=537=389=194 | ||
__rec=node,id=28,attr=10,data=77,parent=1 | ||
__rec=node,id=29,attr=8,data=loop.start_iteration,parent=28 | ||
__rec=node,id=19,attr=8,data=loop,parent=18 | ||
__rec=node,id=45,attr=19,data=lulesh.cycle,parent=41 | ||
__rec=node,id=12,attr=10,data=76,parent=6 | ||
__rec=node,id=16,attr=8,data=class.iteration,parent=12 | ||
__rec=node,id=42,attr=16,data=true,parent=1 | ||
__rec=node,id=43,attr=10,data=13,parent=42 | ||
__rec=node,id=44,attr=8,data=iteration#lulesh.cycle,parent=43 | ||
__rec=ctx,ref=45=23,attr=27=29=31=32=33=37=38=44,data=20=0=1000=743=614=391=390=19 | ||
__rec=ctx,ref=45=23,attr=27=29=31=32=33=37=38=44,data=20=20=1000=743=614=392=391=39 | ||
__rec=ctx,ref=45=23,attr=27=29=31=32=33=37=38=44,data=20=40=1000=743=614=392=392=59 | ||
__rec=ctx,ref=45=23,attr=27=29=31=32=33=37=38=44,data=20=60=1000=743=614=392=392=79 | ||
__rec=ctx,ref=45=23,attr=27=29=31=32=33=37=38=44,data=20=80=1000=743=614=398=395=99 | ||
__rec=ctx,ref=45=23,attr=27=31=32=33=37=38,data=0=1000=743=614=398=398 | ||
__rec=node,id=24,attr=8,data=cali.channel,parent=21 | ||
__rec=node,id=25,attr=24,data=default | ||
__rec=globals,ref=23=25 |
Oops, something went wrong.