11import os
2- from kepler_model .util .prom_types import TIMESTAMP_COL
3- from kepler_model .util import PowerSourceMap
42
5- from kepler_model .util .train_types import FeatureGroup , ModelOutputType , weight_support_trainers
6- from kepler_model .util .loader import load_metadata , load_scaler , get_model_group_path
7- from kepler_model .train .profiler .node_type_index import NodeTypeIndexCollection
83from kepler_model .estimate import load_model
4+ from kepler_model .train .profiler .node_type_index import NodeTypeIndexCollection
5+ from kepler_model .util import PowerSourceMap
6+ from kepler_model .util .loader import get_model_group_path , load_metadata , load_scaler
7+ from kepler_model .util .prom_types import TIMESTAMP_COL
8+ from kepler_model .util .train_types import FeatureGroup , ModelOutputType , weight_support_trainers
99
1010markers = ["o" , "s" , "^" , "v" , "<" , ">" , "p" , "P" , "*" , "x" , "+" , "|" , "_" ]
1111
@@ -18,14 +18,14 @@ def ts_plot(data, cols, title, output_folder, name, labels=None, subtitles=None,
1818
1919 sns .set (font_scale = 1.2 )
2020 fig , axes = plt .subplots (len (cols ), 1 , figsize = (plot_width , len (cols ) * plot_height ))
21- for i in range (0 , len (cols )):
21+ for i in range (len (cols )):
2222 if len (cols ) == 1 :
2323 ax = axes
2424 else :
2525 ax = axes [i ]
2626 if isinstance (cols [i ], list ):
2727 # multiple lines
28- for j in range (0 , len (cols [i ])):
28+ for j in range (len (cols [i ])):
2929 sns .lineplot (data = data , x = TIMESTAMP_COL , y = cols [i ][j ], ax = ax , label = labels [j ])
3030 ax .set_title (subtitles [i ])
3131 else :
@@ -52,27 +52,26 @@ def feature_power_plot(data, model_id, output_type, energy_source, feature_cols,
5252 col_num = len (actual_power_cols )
5353 width = max (10 , col_num * plot_width )
5454 fig , axes = plt .subplots (row_num , col_num , figsize = (width , row_num * plot_height ))
55- for xi in range (0 , row_num ):
55+ for xi in range (row_num ):
5656 feature_col = feature_cols [xi ]
57- for yi in range (0 , col_num ):
57+ for yi in range (col_num ):
5858 if row_num == 1 :
5959 if col_num == 1 :
6060 ax = axes
6161 else :
6262 ax = axes [yi ]
63+ elif col_num == 1 :
64+ ax = axes [xi ]
6365 else :
64- if col_num == 1 :
65- ax = axes [xi ]
66- else :
67- ax = axes [xi ][yi ]
66+ ax = axes [xi ][yi ]
6867 sorted_data = data .sort_values (by = [feature_col ])
6968 sns .scatterplot (data = sorted_data , x = feature_col , y = actual_power_cols [yi ], ax = ax , label = "actual" )
7069 sns .lineplot (data = sorted_data , x = feature_col , y = predicted_power_cols [yi ], ax = ax , label = "predicted" , color = "C1" )
7170 if xi == 0 :
7271 ax .set_title (actual_power_cols [yi ])
7372 if yi == 0 :
7473 ax .set_ylabel ("Power (W)" )
75- title = "{ } {} prediction correlation \n by {}" . format ( energy_source , output_type , model_id )
74+ title = f" { energy_source } { output_type } prediction correlation \n by { model_id } "
7675 plt .suptitle (title , x = 0.5 , y = 0.99 )
7776 plt .tight_layout ()
7877 filename = os .path .join (output_folder , name + ".png" )
@@ -96,7 +95,7 @@ def summary_plot(args, energy_source, summary_df, output_folder, name):
9695 energy_components = PowerSourceMap [energy_source ]
9796 col_num = len (energy_components )
9897 fig , axes = plt .subplots (col_num , 1 , figsize = (plot_width , plot_height * col_num ))
99- for i in range (0 , col_num ):
98+ for i in range (col_num ):
10099 component = energy_components [i ]
101100 data = summary_df [(summary_df ["energy_source" ] == energy_source ) & (summary_df ["energy_component" ] == component )]
102101 data = data .sort_values (by = ["Feature Group" , "MAE" ])
@@ -111,7 +110,7 @@ def summary_plot(args, energy_source, summary_df, output_folder, name):
111110 if i < col_num - 1 :
112111 ax .set_xlabel ("" )
113112 ax .legend (bbox_to_anchor = (1.05 , 1.05 ))
114- plt .suptitle ("{ } {} error". format ( energy_source , args . output_type ) )
113+ plt .suptitle (f" { energy_source } { args . output_type } error" )
115114 plt .tight_layout ()
116115 filename = os .path .join (output_folder , name + ".png" )
117116 fig .savefig (filename )
@@ -134,7 +133,7 @@ def metadata_plot(args, energy_source, metadata_df, output_folder, name):
134133 energy_components = PowerSourceMap [energy_source ]
135134 col_num = len (energy_components )
136135 fig , axes = plt .subplots (col_num , 1 , figsize = (plot_width , plot_height * col_num ))
137- for i in range (0 , col_num ):
136+ for i in range (col_num ):
138137 component = energy_components [i ]
139138 metadata_df = metadata_df .sort_values (by = "feature_group" )
140139 if col_num == 1 :
@@ -149,7 +148,7 @@ def metadata_plot(args, energy_source, metadata_df, output_folder, name):
149148 if i < col_num - 1 :
150149 ax .set_xlabel ("" )
151150 # ax.legend(bbox_to_anchor=(1.05, 1.05))
152- plt .suptitle ("Pipieline metadata of {} {}" . format ( energy_source .upper (), args .output_type ) )
151+ plt .suptitle (f "Pipieline metadata of { energy_source .upper ()} { args .output_type } " )
153152 plt .tight_layout ()
154153 plt .legend (frameon = False )
155154 filename = os .path .join (output_folder , name + ".png" )
@@ -174,7 +173,7 @@ def power_curve_plot(args, data_path, energy_source, output_folder, name):
174173
175174def _get_model (model_toppath , trainer , model_node_type , output_type , name , energy_source ):
176175 feature_group = FeatureGroup .BPFOnly
177- model_name = "{ }_{}" . format ( trainer , model_node_type )
176+ model_name = f" { trainer } _{ model_node_type } "
178177 group_path = get_model_group_path (model_toppath , output_type , feature_group , energy_source , name )
179178 model_path = os .path .join (group_path , model_name )
180179 model = load_model (model_path )
@@ -204,11 +203,12 @@ def _load_all_models(model_toppath, output_type, name, node_types, energy_source
204203
205204
206205def _plot_models (models , cpu_ms_max , energy_source , output_folder , name , max_plot = 15 , cpu_time_bin_num = 10 , sample_num = 20 ):
207- from kepler_model .util .train_types import BPF_FEATURES
208206 import numpy as np
209207 import pandas as pd
210208 import seaborn as sns
211209
210+ from kepler_model .util .train_types import BPF_FEATURES
211+
212212 sns .set_palette ("Paired" )
213213
214214 import matplotlib .pyplot as plt
@@ -253,7 +253,7 @@ def _plot_models(models, cpu_ms_max, energy_source, output_folder, name, max_plo
253253 ax = axes [axes_index // num_cols ][axes_index % num_cols ]
254254 node_type = data_with_prediction_index [0 ]
255255 data_with_prediction = data_with_prediction_index [1 ]
256- sns .lineplot (data = data_with_prediction , x = main_feature_col , y = predicted_col [energy_source ], label = "type={}" . format ( node_type ) , marker = markers [index ], ax = ax )
256+ sns .lineplot (data = data_with_prediction , x = main_feature_col , y = predicted_col [energy_source ], label = f "type={ node_type } " , marker = markers [index ], ax = ax )
257257 index += 1
258258 index = index % len (markers )
259259 if index % max_plot == 0 :
0 commit comments