Skip to content

Commit 4c13bb9

Browse files
fixes
1 parent 79387c3 commit 4c13bb9

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

codeflash/models/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class TestDiffScope(str, Enum):
5252
RETURN_VALUE = "return_value"
5353
STDOUT = "stdout"
5454
DID_PASS = "did_pass" # noqa: S105
55-
TIMED_OUT = "timed_out"
5655

5756

5857
@dataclass

codeflash/optimization/function_optimizer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

codeflash/verification/equivalence.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def compare_test_results(original_results: TestResults, candidate_results: TestR
6565
test_src_code = original_test_result.id.get_src_code(original_test_result.file_name)
6666
test_diff = TestDiff(
6767
scope=TestDiffScope.RETURN_VALUE,
68-
original_value=f"{original_test_result.return_value!r}",
69-
candidate_value=f"{cdd_test_result.return_value!r}",
68+
original_value=repr(original_test_result.return_value),
69+
candidate_value=repr(cdd_test_result.return_value),
7070
test_src_code=test_src_code,
7171
candidate_pytest_error=cdd_pytest_error,
7272
original_pass=original_test_result.did_pass,
@@ -88,16 +88,15 @@ def compare_test_results(original_results: TestResults, candidate_results: TestR
8888
)
8989
except Exception as e:
9090
logger.error(e)
91-
break
92-
if (original_test_result.stdout and cdd_test_result.stdout) and not comparator(
91+
elif (original_test_result.stdout and cdd_test_result.stdout) and not comparator(
9392
original_test_result.stdout, cdd_test_result.stdout
9493
):
9594
test_diff.scope = TestDiffScope.STDOUT
9695
test_diff.original_value = str(original_test_result.stdout)
9796
test_diff.candidate_value = str(cdd_test_result.stdout)
9897
test_diffs.append(test_diff)
9998

100-
if original_test_result.test_type in {
99+
elif original_test_result.test_type in {
101100
TestType.EXISTING_UNIT_TEST,
102101
TestType.CONCOLIC_COVERAGE_TEST,
103102
TestType.GENERATED_REGRESSION,

0 commit comments

Comments
 (0)