diff options
-rwxr-xr-x | bin/analyze-archive.py | 53 | ||||
-rw-r--r-- | lib/model.py | 44 |
2 files changed, 76 insertions, 21 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index 35beae8..6e603d7 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -563,21 +563,28 @@ if __name__ == "__main__": static_model = model.get_static() if "static" in show_models or "all" in show_models: for state in model.states(): - print( - "{:10s}: {:.0f} µW ({:.2f})".format( - state, - static_model(state, "power"), - model.stats.generic_param_dependence_ratio(state, "power"), - ) - ) - for param in model.parameters(): + for attribute in model.attributes(state): + unit = " " + if attribute == "power": + unit = "µW" + elif attribute == "substate_count": + unit = "su" print( - "{:10s} dependence on {:15s}: {:.2f}".format( - "", - param, - model.stats.param_dependence_ratio(state, "power", param), + "{:10s}: {:.0f} {:s} ({:.2f})".format( + state, + static_model(state, attribute), + unit, + model.stats.generic_param_dependence_ratio(state, attribute), ) ) + for param in model.parameters(): + print( + "{:10s} dependence on {:15s}: {:.2f}".format( + "", + param, + model.stats.param_dependence_ratio(state, attribute, param), + ) + ) for trans in model.transitions(): # Mean power is not a typical transition attribute, but may be present for debugging or analysis purposes @@ -642,9 +649,8 @@ if __name__ == "__main__": safe_functions_enabled=safe_functions_enabled ) - if args.with_substates is not None: - substate_model = model.get_substates() - print(model.assess(substate_model, ref=model.sc_by_name)) + # substate_model = model.get_substates() + # print(model.assess(substate_model, ref=model.sc_by_name)) if "paramdetection" in show_models or "all" in show_models: for state in model.states_and_transitions(): @@ -699,29 +705,34 @@ if __name__ == "__main__": for attribute in model.attributes(state): if param_info(state, attribute): print( - "{:10s}: {}".format( + "{:10s} {:15s}: {}".format( state, + attribute, param_info(state, attribute)["function"].model_function, ) ) print( - "{:10s} {}".format( - "", param_info(state, attribute)["function"].model_args + "{:10s} {:15s} {}".format( + "", "", param_info(state, attribute)["function"].model_args ) ) for trans in model.transitions(): for attribute in model.attributes(trans): if param_info(trans, attribute): print( - "{:10s}: {:10s}: {}".format( + "{:10s} {:15s}: {:10s}: {}".format( trans, attribute, + attribute, param_info(trans, attribute)["function"].model_function, ) ) print( - "{:10s} {:10s} {}".format( - "", "", param_info(trans, attribute)["function"].model_args + "{:10s} {:15s} {:10s} {}".format( + "", + "", + "", + param_info(trans, attribute)["function"].model_args, ) ) diff --git a/lib/model.py b/lib/model.py index ab46dc7..f368314 100644 --- a/lib/model.py +++ b/lib/model.py @@ -725,6 +725,7 @@ class PTAModel: from .pelt import PELT self.pelt = PELT(**pelt) + self.find_substates() else: self.pelt = None self.stats = ParamStats( @@ -947,6 +948,49 @@ class PTAModel: penalty, ) + def find_substates(self): + """ + Finds substates via PELT and adds substate_count to by_name and by_param. + """ + states = self.states() + substates_by_param = dict() + for k in self.by_param.keys(): + if k[0] in states: + state_name = k[0] + if self.pelt.needs_refinement(self.by_param[k]["power_traces"]): + substates_by_param[k] = self.pelt_refine(k) + else: + substate_counts = [1 for i in self.by_param[k]["param"]] + substate_data = { + "duration": self.by_param[k]["duration"], + "power": self.by_param[k]["power"], + "power_std": self.by_param[k]["power_std"], + } + substates_by_param[k] = (substate_counts, substate_data) + + # suitable for AEMR modeling + sc_by_param = dict() + for param_key, (substate_counts, _) in substates_by_param.items(): + # do not append "substate_count" to "attributes" here. + # by_param[(foo, *)]["attributes"] is the same object as by_name[foo]["attributes"] + self.by_param[param_key]["substate_count"] = substate_counts + + for state_name in states: + param_offset = dict() + state = self.by_name[state_name] + state["attributes"].append("substate_count") + state["substate_count"] = list() + for i, param in enumerate(state["param"]): + param = tuple(param) + if param not in param_offset: + param_offset[param] = 0 + state["substate_count"].append( + self.by_param[(state_name, param)]["substate_count"][ + param_offset[param] + ] + ) + param_offset[param] += 1 + def get_substates(self): states = self.states() |