@@ -440,6 +440,9 @@ def determine_best_candidate(
440440 # check if this code has been evaluated before by checking the ast normalized code string
441441 normalized_code = ast .unparse (ast .parse (candidate .source_code .flat .strip ()))
442442 if normalized_code in ast_code_to_id :
443+ logger .warning (
444+ "Current candidate has been encountered before in testing, Skipping optimization candidate."
445+ )
443446 past_opt_id = ast_code_to_id [normalized_code ]["optimization_id" ]
444447 # update speedup ratio, is_correct, optimizations_post, optimized_line_profiler_results, optimized_runtimes
445448 speedup_ratios [candidate .optimization_id ] = speedup_ratios [past_opt_id ]
@@ -588,8 +591,10 @@ def determine_best_candidate(
588591 if len (possible_refinement ) > 0 : # if the api returns a valid response
589592 refinement_response .append (possible_refinement [0 ])
590593 candidates .extend (refinement_response )
591- logger .info (f"Added { len (refinement_response )} candidates from refinement" )
592594 original_len += len (refinement_response )
595+ logger .info (
596+ f"Added { len (refinement_response )} candidates from refinement, total candidates now: { original_len } "
597+ )
593598 refinement_done = True
594599 except KeyboardInterrupt as e :
595600 self .write_code_and_helpers (
@@ -1099,11 +1104,6 @@ def find_and_process_best_optimization(
10991104 if best_optimization :
11001105 logger .info ("Best candidate:" )
11011106 code_print (best_optimization .candidate .source_code .flat )
1102- console .print (
1103- Panel (
1104- best_optimization .candidate .explanation , title = "Best Candidate Explanation" , border_style = "blue"
1105- )
1106- )
11071107 processed_benchmark_info = None
11081108 if self .args .benchmark :
11091109 processed_benchmark_info = process_benchmark_data (
@@ -1227,6 +1227,7 @@ def process_review(
12271227 file_path = explanation .file_path ,
12281228 benchmark_details = explanation .benchmark_details ,
12291229 )
1230+ console .print (Panel (new_explanation_raw_str , title = "Best Candidate Explanation" , border_style = "blue" ))
12301231 data = {
12311232 "original_code" : original_code_combined ,
12321233 "new_code" : new_code_combined ,
@@ -1241,7 +1242,9 @@ def process_review(
12411242 "concolic_tests" : concolic_tests ,
12421243 }
12431244
1244- if not self .args .no_pr and not self .args .staging_review :
1245+ raise_pr = not self .args .no_pr
1246+
1247+ if raise_pr and not self .args .staging_review :
12451248 data ["git_remote" ] = self .args .git_remote
12461249 check_create_pr (** data )
12471250 elif self .args .staging_review :
@@ -1252,12 +1255,24 @@ def process_review(
12521255 trace_id = self .function_trace_id , is_optimization_found = best_optimization is not None
12531256 )
12541257
1255- if ((not self .args .no_pr ) or not self .args .staging_review ) and (
1256- self .args .all or env_utils .get_pr_number () or (self .args .file and not self .args .function )
1258+ if raise_pr and (
1259+ self .args .all
1260+ or env_utils .get_pr_number ()
1261+ or self .args .replay_test
1262+ or (self .args .file and not self .args .function )
12571263 ):
1258- self .write_code_and_helpers (
1259- self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
1260- )
1264+ self .revert_code_and_helpers (original_helper_code )
1265+ return
1266+
1267+ if self .args .staging_review :
1268+ # always revert code and helpers when staging review
1269+ self .revert_code_and_helpers (original_helper_code )
1270+ return
1271+
1272+ def revert_code_and_helpers (self , original_helper_code : dict [Path , str ]) -> None :
1273+ self .write_code_and_helpers (
1274+ self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
1275+ )
12611276
12621277 def establish_original_code_baseline (
12631278 self ,
0 commit comments