Skip to content

Commit 2d62171

Browse files
committed
some refactor
1 parent d0f84f6 commit 2d62171

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

codeflash/discovery/functions_to_optimize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ def inspect_top_level_functions_or_methods(
419419
)
420420

421421

422-
def check_optimization_status(function_to_optimize: FunctionToOptimize, code_context: CodeOptimizationContext) -> bool:
422+
def was_function_previously_optimized(
423+
function_to_optimize: FunctionToOptimize, code_context: CodeOptimizationContext
424+
) -> bool:
423425
"""Check which functions have already been optimized and filter them out.
424426
425427
This function calls the optimization API to:

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
from codeflash.code_utils.time_utils import humanize_runtime
5757
from codeflash.context import code_context_extractor
5858
from codeflash.context.unused_definition_remover import detect_unused_helper_functions, revert_unused_helper_functions
59-
from codeflash.discovery.functions_to_optimize import check_optimization_status
59+
from codeflash.discovery.functions_to_optimize import was_function_previously_optimized
6060
from codeflash.either import Failure, Success, is_successful
6161
from codeflash.models.ExperimentMetadata import ExperimentMetadata
6262
from codeflash.models.models import (
@@ -166,9 +166,8 @@ def optimize_function(self) -> Result[BestOptimization, str]: # noqa: PLR0911
166166
# Random here means that we still attempt optimization with a fractional chance to see if
167167
# last time we could not find an optimization, maybe this time we do.
168168
# Random is before as a performance optimization, swapping the two 'and' statements has the same effect
169-
if (
170-
random.random() > REPEAT_OPTIMIZATION_PROBABILITY # noqa: S311
171-
and check_optimization_status(self.function_to_optimize, code_context)
169+
if random.random() > REPEAT_OPTIMIZATION_PROBABILITY and was_function_previously_optimized( # noqa: S311
170+
self.function_to_optimize, code_context
172171
):
173172
return Failure("Function optimization previously attempted, skipping.")
174173

codeflash/optimization/optimizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def run(self) -> None:
111111
from codeflash.benchmarking.trace_benchmarks import trace_benchmarks_pytest
112112
from codeflash.benchmarking.utils import print_benchmark_table, validate_and_format_benchmark_table
113113

114+
console.rule()
114115
with progress_bar(
115116
f"Running benchmarks in {self.args.benchmarks_root}",
116117
transient=True,

0 commit comments

Comments
 (0)