Skip to content

Commit 4856cce

Browse files
Merge pull request #742 from codeflash-ai/fix/reset-code-after-every-optimization
[FIX] Ensure cleanup after each candidate testing (CF-724)
2 parents 48e88b7 + b19c0b3 commit 4856cce

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,16 +649,14 @@ def determine_best_candidate(
649649
if self.args.benchmark and benchmark_tree:
650650
console.print(benchmark_tree)
651651
console.rule()
652-
653-
self.write_code_and_helpers(
654-
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
655-
)
656652
except KeyboardInterrupt as e:
653+
logger.exception(f"Optimization interrupted: {e}")
654+
raise
655+
finally:
656+
# reset for the next candidate
657657
self.write_code_and_helpers(
658658
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
659659
)
660-
logger.exception(f"Optimization interrupted: {e}")
661-
raise
662660
if not valid_optimizations:
663661
return None
664662
# need to figure out the best candidate here before we return best_optimization

0 commit comments

Comments
 (0)