@@ -461,6 +461,13 @@ def optimize_function(self) -> Result[BestOptimization, str]:
461461 return Failure (f"No best optimizations found for function { self .function_to_optimize .qualified_name } " )
462462 return Success (best_optimization )
463463
464+ def reset_optimization_metrics_for_candidate (
465+ self , opt_id : str , speedup_ratios : dict , is_correct : dict , optimized_runtimes : dict
466+ ) -> None :
467+ speedup_ratios [opt_id ] = None
468+ is_correct [opt_id ] = False
469+ optimized_runtimes [opt_id ] = None
470+
464471 def was_candidate_tested_before (self , normalized_code : str ) -> bool :
465472 # check if this code has been evaluated before by checking the ast normalized code string
466473 return normalized_code in self .ast_code_to_id
@@ -602,6 +609,9 @@ def determine_best_candidate(
602609 "shorter_source_code" : candidate .source_code ,
603610 "diff_len" : diff_length (candidate .source_code .flat , code_context .read_writable_code .flat ),
604611 }
612+ self .reset_optimization_metrics_for_candidate (
613+ candidate .optimization_id , speedup_ratios , is_correct , optimized_runtimes
614+ )
605615 run_results , new_candidate = self .run_optimized_candidate (
606616 optimization_candidate_index = candidate_index ,
607617 baseline_results = original_code_baseline ,
@@ -617,9 +627,9 @@ def determine_best_candidate(
617627
618628 console .rule ()
619629 if not is_successful (run_results ):
620- optimized_runtimes [ candidate . optimization_id ] = None
621- is_correct [ candidate .optimization_id ] = False
622- speedup_ratios [ candidate . optimization_id ] = None
630+ self . reset_optimization_metrics_for_candidate (
631+ candidate .optimization_id , speedup_ratios , is_correct , optimized_runtimes
632+ )
623633 else :
624634 candidate_result : OptimizedCandidateResult = run_results .unwrap ()
625635 best_test_runtime = candidate_result .best_test_runtime
0 commit comments