diff options
-rwxr-xr-x | bin/analyze-archive.py | 70 | ||||
-rwxr-xr-x | bin/analyze-timing.py | 60 | ||||
-rwxr-xr-x | bin/eval-outlier-removal.py | 12 | ||||
-rwxr-xr-x | bin/eval-rel-energy.py | 26 | ||||
-rwxr-xr-x | bin/test_corrcoef.py | 34 |
5 files changed, 101 insertions, 101 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index d248d1b..2044731 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -107,7 +107,7 @@ from dfatool.dfatool import CrossValidator from dfatool.utils import filter_aggregate_by_param from dfatool.automata import PTA -opts = {} +opt = dict() def print_model_quality(results): @@ -302,57 +302,57 @@ if __name__ == "__main__": for option, parameter in raw_opts: optname = re.sub(r"^--", "", option) - opts[optname] = parameter + opt[optname] = parameter - if "ignored-trace-indexes" in opts: + if "ignored-trace-indexes" in opt: ignored_trace_indexes = list( - map(int, opts["ignored-trace-indexes"].split(",")) + map(int, opt["ignored-trace-indexes"].split(",")) ) if 0 in ignored_trace_indexes: print("[E] arguments to --ignored-trace-indexes start from 1") - if "discard-outliers" in opts: - discard_outliers = float(opts["discard-outliers"]) + if "discard-outliers" in opt: + discard_outliers = float(opt["discard-outliers"]) - if "function-override" in opts: - for function_desc in opts["function-override"].split(";"): + if "function-override" in opt: + for function_desc in opt["function-override"].split(";"): state_or_tran, attribute, *function_str = function_desc.split(" ") function_override[(state_or_tran, attribute)] = " ".join(function_str) - if "show-models" in opts: - show_models = opts["show-models"].split(",") + if "show-models" in opt: + show_models = opt["show-models"].split(",") - if "show-quality" in opts: - show_quality = opts["show-quality"].split(",") + if "show-quality" in opt: + show_quality = opt["show-quality"].split(",") - if "cross-validate" in opts: - xv_method, xv_count = opts["cross-validate"].split(":") + if "cross-validate" in opt: + xv_method, xv_count = opt["cross-validate"].split(":") xv_count = int(xv_count) - if "filter-param" in opts: - opts["filter-param"] = list( - map(lambda x: x.split("="), opts["filter-param"].split(",")) + if "filter-param" in opt: + opt["filter-param"] = list( + map(lambda x: x.split("="), opt["filter-param"].split(",")) ) else: - opts["filter-param"] = list() + opt["filter-param"] = list() - if "with-safe-functions" in opts: + if "with-safe-functions" in opt: safe_functions_enabled = True - if "hwmodel" in opts: - pta = PTA.from_file(opts["hwmodel"]) + if "hwmodel" in opt: + pta = PTA.from_file(opt["hwmodel"]) except getopt.GetoptError as err: print(err) sys.exit(2) raw_data = RawData( - args, with_traces=("export-traces" in opts or "plot-traces" in opts) + args, with_traces=("export-traces" in opt or "plot-traces" in opt) ) preprocessed_data = raw_data.get_preprocessed_data() - if "export-traces" in opts: + if "export-traces" in opt: uw_per_sot = dict() for trace in preprocessed_data: for state_or_transition in trace["trace"]: @@ -363,16 +363,16 @@ if __name__ == "__main__": elem["uW"] = list(elem["uW"]) uw_per_sot[name].append(state_or_transition) for name, data in uw_per_sot.items(): - target = f"{opts['export-traces']}/{name}.json" + target = f"{opt['export-traces']}/{name}.json" print(f"exporting {target} ...") with open(target, "w") as f: json.dump(data, f) - if "plot-traces" in opts: + if "plot-traces" in opt: traces = list() for trace in preprocessed_data: for state_or_transition in trace["trace"]: - if state_or_transition["name"] == opts["plot-traces"]: + if state_or_transition["name"] == opt["plot-traces"]: traces.extend( map(lambda x: x["uW"], state_or_transition["offline"]) ) @@ -380,7 +380,7 @@ if __name__ == "__main__": traces, xlabel="t [1e-5 s]", ylabel="P [uW]", - title=opts["plot-traces"], + title=opt["plot-traces"], family=True, ) @@ -395,7 +395,7 @@ if __name__ == "__main__": preprocessed_data, ignored_trace_indexes ) - filter_aggregate_by_param(by_name, parameters, opts["filter-param"]) + filter_aggregate_by_param(by_name, parameters, opt["filter-param"]) model = PTAModel( by_name, @@ -410,7 +410,7 @@ if __name__ == "__main__": if xv_method: xv = CrossValidator(PTAModel, by_name, parameters, arg_count) - if "param-info" in opts: + if "param-info" in opt: for state in model.states(): print("{}:".format(state)) for param in model.parameters(): @@ -428,8 +428,8 @@ if __name__ == "__main__": ) ) - if "plot-unparam" in opts: - for kv in opts["plot-unparam"].split(";"): + if "plot-unparam" in opt: + for kv in opt["plot-unparam"].split(";"): state_or_trans, attribute, ylabel = kv.split(":") fname = "param_y_{}_{}.pdf".format(state_or_trans, attribute) plotter.plot_y( @@ -677,8 +677,8 @@ if __name__ == "__main__": ] ) - if "plot-param" in opts: - for kv in opts["plot-param"].split(";"): + if "plot-param" in opt: + for kv in opt["plot-param"].split(";"): state_or_trans, attribute, param_name, *function = kv.split(" ") if len(function): function = gplearn_to_function(" ".join(function)) @@ -692,12 +692,12 @@ if __name__ == "__main__": extra_function=function, ) - if "export-energymodel" in opts: + if "export-energymodel" in opt: if not pta: print("[E] --export-energymodel requires --hwmodel to be set") sys.exit(1) json_model = model.to_json() - with open(opts["export-energymodel"], "w") as f: + with open(opt["export-energymodel"], "w") as f: json.dump(json_model, f, indent=2, sort_keys=True) sys.exit(0) diff --git a/bin/analyze-timing.py b/bin/analyze-timing.py index e565c8f..4039f45 100755 --- a/bin/analyze-timing.py +++ b/bin/analyze-timing.py @@ -84,7 +84,7 @@ from dfatool.dfatool import CrossValidator from dfatool.utils import filter_aggregate_by_param from dfatool.parameters import prune_dependent_parameters -opts = {} +opt = dict() def print_model_quality(results): @@ -193,49 +193,49 @@ if __name__ == "__main__": for option, parameter in raw_opts: optname = re.sub(r"^--", "", option) - opts[optname] = parameter + opt[optname] = parameter - if "ignored-trace-indexes" in opts: + if "ignored-trace-indexes" in opt: ignored_trace_indexes = list( - map(int, opts["ignored-trace-indexes"].split(",")) + map(int, opt["ignored-trace-indexes"].split(",")) ) if 0 in ignored_trace_indexes: print("[E] arguments to --ignored-trace-indexes start from 1") - if "discard-outliers" in opts: - discard_outliers = float(opts["discard-outliers"]) + if "discard-outliers" in opt: + discard_outliers = float(opt["discard-outliers"]) - if "function-override" in opts: - for function_desc in opts["function-override"].split(";"): + if "function-override" in opt: + for function_desc in opt["function-override"].split(";"): state_or_tran, attribute, *function_str = function_desc.split(" ") function_override[(state_or_tran, attribute)] = " ".join(function_str) - if "show-models" in opts: - show_models = opts["show-models"].split(",") + if "show-models" in opt: + show_models = opt["show-models"].split(",") - if "show-quality" in opts: - show_quality = opts["show-quality"].split(",") + if "show-quality" in opt: + show_quality = opt["show-quality"].split(",") - if "cross-validate" in opts: - xv_method, xv_count = opts["cross-validate"].split(":") + if "cross-validate" in opt: + xv_method, xv_count = opt["cross-validate"].split(":") xv_count = int(xv_count) - if "with-safe-functions" in opts: + if "with-safe-functions" in opt: safe_functions_enabled = True - if "hwmodel" in opts: - with open(opts["hwmodel"], "r") as f: + if "hwmodel" in opt: + with open(opt["hwmodel"], "r") as f: hwmodel = json.load(f) - if "corrcoef" not in opts: - opts["corrcoef"] = False + if "corrcoef" not in opt: + opt["corrcoef"] = False - if "filter-param" in opts: - opts["filter-param"] = list( - map(lambda x: x.split("="), opts["filter-param"].split(",")) + if "filter-param" in opt: + opt["filter-param"] = list( + map(lambda x: x.split("="), opt["filter-param"].split(",")) ) else: - opts["filter-param"] = list() + opt["filter-param"] = list() except getopt.GetoptError as err: print(err) @@ -250,20 +250,20 @@ if __name__ == "__main__": prune_dependent_parameters(by_name, parameters) - filter_aggregate_by_param(by_name, parameters, opts["filter-param"]) + filter_aggregate_by_param(by_name, parameters, opt["filter-param"]) model = AnalyticModel( by_name, parameters, arg_count, - use_corrcoef=opts["corrcoef"], + use_corrcoef=opt["corrcoef"], function_override=function_override, ) if xv_method: xv = CrossValidator(AnalyticModel, by_name, parameters, arg_count) - if "param-info" in opts: + if "param-info" in opt: for state in model.names: print("{}:".format(state)) for param in model.parameters: @@ -273,8 +273,8 @@ if __name__ == "__main__": ) ) - if "plot-unparam" in opts: - for kv in opts["plot-unparam"].split(";"): + if "plot-unparam" in opt: + for kv in opt["plot-unparam"].split(";"): state_or_trans, attribute, ylabel = kv.split(":") fname = "param_y_{}_{}.pdf".format(state_or_trans, attribute) plotter.plot_y( @@ -456,8 +456,8 @@ if __name__ == "__main__": [static_quality, analytic_quality, lut_quality], [None, param_info, None] ) - if "plot-param" in opts: - for kv in opts["plot-param"].split(";"): + if "plot-param" in opt: + for kv in opt["plot-param"].split(";"): state_or_trans, attribute, param_name, *function = kv.split(" ") if len(function): function = gplearn_to_function(" ".join(function)) diff --git a/bin/eval-outlier-removal.py b/bin/eval-outlier-removal.py index d8b0e9d..14f0e60 100755 --- a/bin/eval-outlier-removal.py +++ b/bin/eval-outlier-removal.py @@ -5,7 +5,7 @@ import re import sys from dfatool.dfatool import PTAModel, RawData, pta_trace_to_aggregate -opts = {} +opt = dict() def model_quality_table(result_lists, info_list): @@ -63,17 +63,17 @@ if __name__ == "__main__": for option, parameter in raw_opts: optname = re.sub(r"^--", "", option) - opts[optname] = parameter + opt[optname] = parameter - if "ignored-trace-indexes" in opts: + if "ignored-trace-indexes" in opt: ignored_trace_indexes = list( - map(int, opts["ignored-trace-indexes"].split(",")) + map(int, opt["ignored-trace-indexes"].split(",")) ) if 0 in ignored_trace_indexes: print("[E] arguments to --ignored-trace-indexes start from 1") - if "discard-outliers" in opts: - discard_outliers = float(opts["discard-outliers"]) + if "discard-outliers" in opt: + discard_outliers = float(opt["discard-outliers"]) except getopt.GetoptError as err: print(err) diff --git a/bin/eval-rel-energy.py b/bin/eval-rel-energy.py index 44db226..8a2be13 100755 --- a/bin/eval-rel-energy.py +++ b/bin/eval-rel-energy.py @@ -5,7 +5,7 @@ import re import sys from dfatool.dfatool import PTAModel, RawData, pta_trace_to_aggregate -opts = {} +opt = dict() def get_file_groups(args): @@ -38,32 +38,32 @@ if __name__ == "__main__": for option, parameter in raw_opts: optname = re.sub(r"^--", "", option) - opts[optname] = parameter + opt[optname] = parameter - if "ignored-trace-indexes" in opts: + if "ignored-trace-indexes" in opt: ignored_trace_indexes = list( - map(int, opts["ignored-trace-indexes"].split(",")) + map(int, opt["ignored-trace-indexes"].split(",")) ) if 0 in ignored_trace_indexes: print("[E] arguments to --ignored-trace-indexes start from 1") - if "discard-outliers" in opts: - discard_outliers = float(opts["discard-outliers"]) + if "discard-outliers" in opt: + discard_outliers = float(opt["discard-outliers"]) - if "function-override" in opts: - for function_desc in opts["function-override"].split(";"): + if "function-override" in opt: + for function_desc in opt["function-override"].split(";"): state_or_tran, attribute, *function_str = function_desc.split(" ") function_override[(state_or_tran, attribute)] = " ".join( function_str ) - if "show-models" in opts: - show_models = opts["show-models"].split(",") + if "show-models" in opt: + show_models = opt["show-models"].split(",") - if "show-quality" in opts: - show_quality = opts["show-quality"].split(",") + if "show-quality" in opt: + show_quality = opt["show-quality"].split(",") - if "with-safe-functions" in opts: + if "with-safe-functions" in opt: safe_functions_enabled = True except getopt.GetoptError as err: diff --git a/bin/test_corrcoef.py b/bin/test_corrcoef.py index e389d01..0b1ca54 100755 --- a/bin/test_corrcoef.py +++ b/bin/test_corrcoef.py @@ -7,7 +7,7 @@ from dfatool import plotter from dfatool.dfatool import PTAModel, RawData, pta_trace_to_aggregate from dfatool.dfatool import gplearn_to_function -opts = {} +opt = dict() def print_model_quality(results): @@ -126,32 +126,32 @@ if __name__ == "__main__": for option, parameter in raw_opts: optname = re.sub(r"^--", "", option) - opts[optname] = parameter + opt[optname] = parameter - if "ignored-trace-indexes" in opts: + if "ignored-trace-indexes" in opt: ignored_trace_indexes = list( - map(int, opts["ignored-trace-indexes"].split(",")) + map(int, opt["ignored-trace-indexes"].split(",")) ) if 0 in ignored_trace_indexes: print("[E] arguments to --ignored-trace-indexes start from 1") - if "discard-outliers" in opts: - discard_outliers = float(opts["discard-outliers"]) + if "discard-outliers" in opt: + discard_outliers = float(opt["discard-outliers"]) - if "function-override" in opts: - for function_desc in opts["function-override"].split(";"): + if "function-override" in opt: + for function_desc in opt["function-override"].split(";"): state_or_tran, attribute, *function_str = function_desc.split(" ") function_override[(state_or_tran, attribute)] = " ".join( function_str ) - if "show-models" in opts: - show_models = opts["show-models"].split(",") + if "show-models" in opt: + show_models = opt["show-models"].split(",") - if "show-quality" in opts: - show_quality = opts["show-quality"].split(",") + if "show-quality" in opt: + show_quality = opt["show-quality"].split(",") - if "with-safe-functions" in opts: + if "with-safe-functions" in opt: safe_functions_enabled = True except getopt.GetoptError as err: @@ -184,8 +184,8 @@ if __name__ == "__main__": use_corrcoef=True, ) - if "plot-unparam" in opts: - for kv in opts["plot-unparam"].split(";"): + if "plot-unparam" in opt: + for kv in opt["plot-unparam"].split(";"): state_or_trans, attribute = kv.split(" ") plotter.plot_y(model.by_name[state_or_trans][attribute]) @@ -299,8 +299,8 @@ if __name__ == "__main__": print("heuristic:") model_summary_table([ref_static_quality, ref_analytic_quality, ref_lut_quality]) - if "plot-param" in opts: - for kv in opts["plot-param"].split(";"): + if "plot-param" in opt: + for kv in opt["plot-param"].split(";"): state_or_trans, attribute, param_name, *function = kv.split(" ") if len(function): function = gplearn_to_function(" ".join(function)) |