1010 sys .exit (1 )
1111
1212import matplotlib
13- matplotlib .use ('Qt5Agg ' )
14- from matplotlib .backends .backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
13+ matplotlib .use ('qtagg ' )
14+ from matplotlib .backends .backend_qtagg import FigureCanvasQTAgg as FigureCanvas
1515from matplotlib .figure import Figure
1616
1717class PandasModel (QAbstractTableModel ):
@@ -43,6 +43,8 @@ def headerData(self, col, orientation, role):
4343class QoRPlotter (QMainWindow ):
4444 def __init__ (self , csv_file ):
4545 super ().__init__ ()
46+ self .csv_file = csv_file
47+ self .pdk = "asap7" if "asap7" in csv_file .lower () else "sky130hd"
4648 self .setWindowTitle (f"QoR Path Correlation Debugger - { os .path .basename (csv_file )} " )
4749 self .df = pd .read_csv (csv_file )
4850
@@ -52,26 +54,41 @@ def __init__(self, csv_file):
5254
5355 # Controls
5456 ctrl_layout = QHBoxLayout ()
55- self .x_axis_cb = QComboBox ()
56- self .y_axis_cb = QComboBox ()
57+ self .x_stage_cb = QComboBox ()
58+ self .y_stage_cb = QComboBox ()
59+ self .metric_cb = QComboBox ()
5760
58- numeric_cols = self .df .select_dtypes (include = ['float64' , 'int64' ]).columns
59- self .x_axis_cb .addItems (numeric_cols )
60- self .y_axis_cb .addItems (numeric_cols )
61+ stages = ["3_place" , "5_grt" , "6_route" ]
62+ allowed_metrics = ["min_clk_period" , "net_delay" , "logic_delay" , "total_cap" , "buffers" ]
63+
64+ metrics = set ()
65+ for col in self .df .select_dtypes (include = ['float64' , 'int64' ]).columns :
66+ for stage in stages :
67+ if col .startswith (f"{ stage } _" ):
68+ m = col [len (f"{ stage } _" ):]
69+ if m in allowed_metrics :
70+ metrics .add (m )
71+
72+ self .x_stage_cb .addItems (stages )
73+ self .y_stage_cb .addItems (stages )
74+ self .metric_cb .addItems (sorted (list (metrics )))
6175
6276 # Try to set sensible defaults
63- slack_cols = [ c for c in numeric_cols if 'slack' in c ]
64- if len ( slack_cols ) >= 2 :
65- self . x_axis_cb . setCurrentText ( slack_cols [ 0 ])
66- self .y_axis_cb .setCurrentText (slack_cols [ - 1 ] )
77+ self . x_stage_cb . setCurrentText ( "5_grt" )
78+ self . y_stage_cb . setCurrentText ( "6_route" )
79+ if "min_clk_period" in metrics :
80+ self .metric_cb .setCurrentText ("min_clk_period" )
6781
68- self .x_axis_cb .currentTextChanged .connect (self .update_plot )
69- self .y_axis_cb .currentTextChanged .connect (self .update_plot )
82+ self .x_stage_cb .currentTextChanged .connect (self .update_plot )
83+ self .y_stage_cb .currentTextChanged .connect (self .update_plot )
84+ self .metric_cb .currentTextChanged .connect (self .update_plot )
7085
71- ctrl_layout .addWidget (QLabel ("X-Axis:" ))
72- ctrl_layout .addWidget (self .x_axis_cb )
73- ctrl_layout .addWidget (QLabel ("Y-Axis:" ))
74- ctrl_layout .addWidget (self .y_axis_cb )
86+ ctrl_layout .addWidget (QLabel ("X-Axis Stage:" ))
87+ ctrl_layout .addWidget (self .x_stage_cb )
88+ ctrl_layout .addWidget (QLabel ("Y-Axis Stage:" ))
89+ ctrl_layout .addWidget (self .y_stage_cb )
90+ ctrl_layout .addWidget (QLabel ("Metric:" ))
91+ ctrl_layout .addWidget (self .metric_cb )
7592 layout .addLayout (ctrl_layout )
7693
7794 # Plot
@@ -89,26 +106,51 @@ def __init__(self, csv_file):
89106 self .update_plot ()
90107
91108 def update_plot (self ):
109+ if self .df is None or self .df .empty :
110+ return
111+
112+ x_stage = self .x_stage_cb .currentText ()
113+ y_stage = self .y_stage_cb .currentText ()
114+ metric = self .metric_cb .currentText ()
115+
116+ x_col = f"{ x_stage } _{ metric } "
117+ y_col = f"{ y_stage } _{ metric } "
118+
119+ if x_col not in self .df .columns or y_col not in self .df .columns :
120+ return
121+
122+ valid_df = self .df [[x_col , y_col ]].dropna ()
123+ x_data = valid_df [x_col ]
124+ y_data = valid_df [y_col ]
125+
92126 self .ax .clear ()
93- x_col = self .x_axis_cb .currentText ()
94- y_col = self .y_axis_cb .currentText ()
127+ self .ax .scatter (x_data , y_data , alpha = 0.5 )
128+
129+ self .csv_file = csv_file
130+ self .pdk = "asap7" if "asap7" in csv_file .lower () else "sky130hd"
95131
96- if x_col and y_col :
97- x_data = self .df [x_col ]
98- y_data = self .df [y_col ]
99- self .ax .scatter (x_data , y_data , alpha = 0.5 )
132+ # Unit label
133+ unit_str = ""
134+ if "clk_period" in metric or "delay" in metric :
135+ if "asap7" in self .pdk :
136+ unit_str = " (ps)"
137+ else :
138+ unit_str = " (ns)"
139+ elif "cap" in metric :
140+ unit_str = " (fF)"
100141
101- # Diagonal line
142+ # Diagonal line
143+ if not x_data .empty and not y_data .empty :
102144 min_val = min (x_data .min (), y_data .min ())
103145 max_val = max (x_data .max (), y_data .max ())
104146 self .ax .plot ([min_val , max_val ], [min_val , max_val ], 'r--' )
105147
106- self .ax .set_xlabel (x_col )
107- self .ax .set_ylabel (y_col )
108- self .ax .grid (True )
109- self .ax .set_title (f"Correlation: { x_col } vs { y_col } " )
110- self .fig .tight_layout ()
111- self .canvas .draw ()
148+ self .ax .set_xlabel (f" { x_col } { unit_str } " )
149+ self .ax .set_ylabel (f" { y_col } { unit_str } " )
150+ self .ax .grid (True )
151+ self .ax .set_title (f"Correlation: { x_col } vs { y_col } " )
152+ self .fig .tight_layout ()
153+ self .canvas .draw ()
112154
113155def build_and_extract_data (pdk , design ):
114156 print (f"Building and extracting path data for { pdk } { design } ..." )
@@ -132,15 +174,26 @@ def build_and_extract_data(pdk, design):
132174 print (f"Error: Build failed for { pdk } { design } ." )
133175 sys .exit (1 )
134176
135- # Aggregate
177+ reports_dir = os . path . join ( cwd , "bazel-bin" , "flow" , "designs" , pdk , design , "reports" , pdk , design , "base" )
136178 try :
137- df3 = pd .read_csv (os .path .join (dump_dir , "3_place_timing_paths.csv" ))
138- df5 = pd .read_csv (os .path .join (dump_dir , "5_grt_timing_paths.csv" ))
139- df6 = pd .read_csv (os .path .join (dump_dir , "6_route_timing_paths.csv" ))
179+ df3 = pd .read_csv (os .path .join (reports_dir , "3_place_timing_paths.csv" ))
180+ df5 = pd .read_csv (os .path .join (reports_dir , "5_grt_timing_paths.csv" ))
181+ df6 = pd .read_csv (os .path .join (reports_dir , "6_route_timing_paths.csv" ))
140182 except Exception as e :
141183 print (f"Error reading CSVs: { e } " )
142184 sys .exit (1 )
143185
186+ def get_worst_paths (df , stage_prefix ):
187+ if f'{ stage_prefix } _min_clk_period' in df .columns :
188+ df = df .sort_values (f'{ stage_prefix } _min_clk_period' , ascending = False )
189+ elif f'{ stage_prefix } _slack' in df .columns :
190+ df = df .sort_values (f'{ stage_prefix } _slack' , ascending = True )
191+ return df .drop_duplicates (subset = ['startpoint' , 'endpoint' ], keep = 'first' )
192+
193+ df3 = get_worst_paths (df3 , "3_place" )
194+ df5 = get_worst_paths (df5 , "5_grt" )
195+ df6 = get_worst_paths (df6 , "6_route" )
196+
144197 df_merged = df3 .merge (df5 , on = ['startpoint' , 'endpoint' ], how = 'outer' )
145198 df_merged = df_merged .merge (df6 , on = ['startpoint' , 'endpoint' ], how = 'outer' )
146199
@@ -150,28 +203,44 @@ def build_and_extract_data(pdk, design):
150203 return out_csv
151204
152205if __name__ == "__main__" :
153- app = QApplication (sys .argv )
206+ import argparse
207+ parser = argparse .ArgumentParser (description = "QoR Correlation Plotter" )
208+ parser .add_argument ('csv_file' , nargs = '?' , help = 'Merged CSV file or design name' )
209+ parser .add_argument ('--design' , help = 'Design platform/variant name, e.g., sky130hd/gcd' )
210+
211+ args = parser .parse_args ()
154212
155- csv_file = None
156- if len (sys .argv ) < 2 :
157- # Build for both pdks
158- csv_sky130 = build_and_extract_data ("sky130hd" , "gcd" )
159- csv_asap7 = build_and_extract_data ("asap7" , "gcd" )
160-
161- # Combine them or just open sky130 by default and let user know
162- # For simplicity, let's open sky130 and asap7 in different windows
163- w1 = QoRPlotter (csv_sky130 )
164- w1 .resize (1000 , 800 )
165- w1 .show ()
166-
167- w2 = QoRPlotter (csv_asap7 )
168- w2 .resize (1000 , 800 )
169- w2 .show ()
170-
171- sys .exit (app .exec ())
172- else :
173- csv_file = sys .argv [1 ]
174- window = QoRPlotter (csv_file )
175- window .resize (1000 , 800 )
176- window .show ()
177- sys .exit (app .exec ())
213+ csv_file = args .csv_file
214+ if args .design :
215+ parts = args .design .strip ('/' ).split ('/' )
216+ if len (parts ) == 2 :
217+ pdk , design = parts
218+ else :
219+ pdk , design = "sky130hd" , parts [0 ]
220+ csv_file = build_and_extract_data (pdk , design )
221+ elif csv_file and '/' in csv_file and not csv_file .endswith ('.csv' ):
222+ parts = csv_file .strip ('/' ).split ('/' )
223+ if len (parts ) == 2 :
224+ pdk , design = parts
225+ else :
226+ pdk , design = "sky130hd" , parts [0 ]
227+ csv_file = build_and_extract_data (pdk , design )
228+ elif csv_file :
229+ build_dir = os .environ .get ("BUILD_WORKING_DIRECTORY" , os .getcwd ())
230+ if not os .path .isabs (csv_file ):
231+ if os .path .exists (csv_file ):
232+ csv_file = os .path .abspath (csv_file )
233+ elif os .path .exists (os .path .join (build_dir , csv_file )):
234+ csv_file = os .path .abspath (os .path .join (build_dir , csv_file ))
235+ elif not csv_file :
236+ csv_file = build_and_extract_data ("sky130hd" , "gcd" )
237+
238+ if not csv_file or not os .path .exists (csv_file ):
239+ print ("Error: Could not locate or build CSV data file." )
240+ sys .exit (1 )
241+
242+ app = QApplication (sys .argv )
243+ window = QoRPlotter (csv_file )
244+ window .resize (1000 , 800 )
245+ window .show ()
246+ sys .exit (app .exec ())
0 commit comments