Skip to content

Commit 86e1a72

Browse files
committed
line profiler only available for successful runs
1 parent 02ce034 commit 86e1a72

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -440,25 +440,20 @@ 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+
past_opt_id = ast_code_to_id[normalized_code]["optimization_id"]
443444
# update speedup ratio, is_correct, optimizations_post, optimized_line_profiler_results, optimized_runtimes
444-
speedup_ratios[candidate.optimization_id] = speedup_ratios[
445-
ast_code_to_id[normalized_code]["optimization_id"]
446-
]
447-
is_correct[candidate.optimization_id] = is_correct[
448-
ast_code_to_id[normalized_code]["optimization_id"]
449-
]
450-
optimized_runtimes[candidate.optimization_id] = optimized_runtimes[
451-
ast_code_to_id[normalized_code]["optimization_id"]
452-
]
453-
optimized_line_profiler_results[candidate.optimization_id] = optimized_line_profiler_results[
454-
ast_code_to_id[normalized_code]["optimization_id"]
455-
]
445+
speedup_ratios[candidate.optimization_id] = speedup_ratios[past_opt_id]
446+
is_correct[candidate.optimization_id] = is_correct[past_opt_id]
447+
optimized_runtimes[candidate.optimization_id] = optimized_runtimes[past_opt_id]
448+
# line profiler results only available for successful runs
449+
if past_opt_id in optimized_line_profiler_results:
450+
optimized_line_profiler_results[candidate.optimization_id] = optimized_line_profiler_results[
451+
past_opt_id
452+
]
456453
optimizations_post[candidate.optimization_id] = ast_code_to_id[normalized_code][
457454
"shorter_source_code"
458455
].markdown
459-
optimizations_post[ast_code_to_id[normalized_code]["optimization_id"]] = ast_code_to_id[
460-
normalized_code
461-
]["shorter_source_code"].markdown
456+
optimizations_post[past_opt_id] = ast_code_to_id[normalized_code]["shorter_source_code"].markdown
462457
new_diff_len = diff_length(candidate.source_code.flat, code_context.read_writable_code.flat)
463458
if new_diff_len < ast_code_to_id[normalized_code]["diff_len"]:
464459
ast_code_to_id[normalized_code]["shorter_source_code"] = candidate.source_code

0 commit comments

Comments
 (0)