@@ -584,13 +584,34 @@ def determine_best_candidate(
584584 baseline_results = original_code_baseline ,
585585 original_helper_code = original_helper_code ,
586586 file_path_to_helper_classes = file_path_to_helper_classes ,
587- code_context = code_context ,
588587 )
589588 console .rule ()
590589 if not is_successful (run_results ):
591590 optimized_runtimes [candidate .optimization_id ] = None
592591 is_correct [candidate .optimization_id ] = False
593592 speedup_ratios [candidate .optimization_id ] = None
593+ fail_value = run_results .value
594+ if (
595+ fail_value != "Test results did not match the test results of the original code."
596+ and len (future_all_refinements ) <= 3
597+ and not candidate .optimization_id .endswith ("cdrp" )
598+ ):
599+ # # queue corresponding code repair optimization for best optimization
600+ future_all_refinements .append (
601+ self .code_repair_optimizations (
602+ original_source_code = candidate ,
603+ modified_source_code = code_context ,
604+ original_code_baseline = original_code_baseline ,
605+ test_details = "test_details" ,
606+ code_context = code_context ,
607+ trace_id = self .function_trace_id [:- 4 ] + exp_type
608+ if self .experiment_id
609+ else self .function_trace_id ,
610+ ai_service_client = ai_service_client ,
611+ executor = self .executor ,
612+ function_references = function_references ,
613+ )
614+ )
594615 else :
595616 candidate_result : OptimizedCandidateResult = run_results .unwrap ()
596617 best_test_runtime = candidate_result .best_test_runtime
@@ -1831,28 +1852,24 @@ def run_optimized_candidate(
18311852 diff_per_test_fn = {}
18321853 for diff in diffs :
18331854 try :
1834- diff_per_test_fn .setdefault (diff .test_src_code , []).append (
1835- f"Expected Value: { diff .original_value !s} \n Actual Value: { diff .candidate_value !s} \n Error String:{ diff .pytest_error } "
1855+ diff_per_test_fn [diff .test_src_code ] = (
1856+ diff_per_test_fn .setdefault (diff .test_src_code , "" )
1857+ + f"Expected Value: { diff .original_value !s} \n Actual Value: { diff .candidate_value !s} \n Error String:{ diff .pytest_error } \n "
18361858 )
1859+
18371860 except Exception as e :
18381861 sentry_sdk .capture_exception (e )
18391862 logger .exception (e )
1863+ return self .get_results_not_matched_error ()
18401864 try :
18411865 test_issues = "\n " .join (
18421866 f"{ test_fn_def } \n { value } " for test_fn_def , value in diff_per_test_fn .items ()
18431867 )
18441868 except Exception as e :
18451869 sentry_sdk .capture_exception (e )
18461870 logger .exception (e )
1847- print (type (diff_per_test_fn ), type (test_issues ))
1848- # with the parsed test results diff ask the llm to fix the candidate to match the test results of the original code, and run again
1849- # self.run_optimized_candidate(
1850- # optimization_candidate_index=optimization_candidate_index,
1851- # baseline_results=baseline_results,
1852- # original_helper_code=original_helper_code,
1853- # file_path_to_helper_classes=file_path_to_helper_classes,
1854- # )
1855- return self .get_results_not_matched_error ()
1871+ return self .get_results_not_matched_error ()
1872+ return Failure (test_issues )
18561873
18571874 logger .info (f"loading|Running performance tests for candidate { optimization_candidate_index } ..." )
18581875
0 commit comments