Skip to content

Commit f74d947

Browse files
committed
update CI
1 parent 35059a9 commit f74d947

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

codeflash/benchmarking/function_ranker.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from pathlib import Path
43
from typing import TYPE_CHECKING
54

65
from codeflash.cli_cmds.console import console, logger
@@ -83,13 +82,17 @@ def load_function_stats(self) -> None:
8382
self._function_stats = {}
8483

8584
def _get_function_stats(self, function_to_optimize: FunctionToOptimize) -> dict | None:
86-
# First try qualified_name, then function_name, avoid allocating a list
87-
key1 = f"{function_to_optimize.file_path}:{function_to_optimize.qualified_name}"
88-
stats = self._function_stats.get(key1)
89-
if stats is not None:
90-
return stats
91-
key2 = f"{function_to_optimize.file_path}:{function_to_optimize.function_name}"
92-
return self._function_stats.get(key2, None)
85+
target_filename = function_to_optimize.file_path.name
86+
for key, stats in self._function_stats.items():
87+
if stats.get("function_name") == function_to_optimize.function_name and (
88+
key.endswith(f"/{target_filename}") or target_filename in key
89+
):
90+
return stats
91+
92+
logger.debug(
93+
f"Could not find stats for function {function_to_optimize.function_name} in file {target_filename}"
94+
)
95+
return None
9396

9497
def get_function_ttx_score(self, function_to_optimize: FunctionToOptimize) -> float:
9598
stats = self._get_function_stats(function_to_optimize)

tests/scripts/end_to_end_test_tracer_replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def run_test(expected_improvement_pct: int) -> bool:
88
config = TestConfig(
99
trace_mode=True,
1010
min_improvement_x=0.1,
11-
expected_unit_tests=7,
11+
expected_unit_tests=8,
1212
coverage_expectations=[
1313
CoverageExpectation(function_name="funcA", expected_coverage=100.0, expected_lines=[5, 6, 7, 8, 10, 13])
1414
],

tests/scripts/end_to_end_test_utilities.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,9 @@ def validate_stdout_in_candidate(stdout: str, expected_in_stdout: list[str]) ->
185185

186186

187187
def run_trace_test(cwd: pathlib.Path, config: TestConfig, expected_improvement_pct: int) -> bool:
188-
# First command: Run the tracer
189188
test_root = cwd / "tests" / (config.test_framework or "")
190189
clear_directory(test_root)
191-
command = ["python", "-m", "codeflash.tracer", "-o", "codeflash.trace", "workload.py"]
190+
command = ["python", "-m", "codeflash.main", "optimize", "workload.py"]
192191
process = subprocess.Popen(
193192
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=str(cwd), env=os.environ.copy()
194193
)
@@ -202,33 +201,20 @@ def run_trace_test(cwd: pathlib.Path, config: TestConfig, expected_improvement_p
202201
stdout = "".join(output)
203202

204203
if return_code != 0:
205-
logging.error(f"Tracer command returned exit code {return_code}")
204+
logging.error(f"Tracer with optimization command returned exit code {return_code}")
206205
return False
207206

208-
functions_traced = re.search(r"Traced (\d+) function calls successfully and replay test created at - (.*)$", stdout)
209-
if not functions_traced or int(functions_traced.group(1)) != 13:
210-
logging.error("Expected 13 traced functions")
207+
functions_traced = re.search(r"Traced (\d+) function calls successfully", stdout)
208+
logging.info(functions_traced.groups() if functions_traced else "No functions traced")
209+
if not functions_traced:
210+
logging.error("Failed to find traced functions in output")
211211
return False
212-
213-
replay_test_path = pathlib.Path(functions_traced.group(2))
214-
if not replay_test_path.exists():
215-
logging.error(f"Replay test file missing at {replay_test_path}")
212+
if int(functions_traced.group(1)) != 13:
213+
logging.error(functions_traced.groups())
214+
logging.error("Expected 13 traced functions")
216215
return False
217216

218-
# Second command: Run optimization
219-
command = ["python", "../../../codeflash/main.py", "--replay-test", str(replay_test_path), "--no-pr"]
220-
process = subprocess.Popen(
221-
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=str(cwd), env=os.environ.copy()
222-
)
223-
224-
output = []
225-
for line in process.stdout:
226-
logging.info(line.strip())
227-
output.append(line)
228-
229-
return_code = process.wait()
230-
stdout = "".join(output)
231-
217+
# Validate optimization results (from optimization phase)
232218
return validate_output(stdout, return_code, expected_improvement_pct, config)
233219

234220

0 commit comments

Comments
 (0)