Skip to content

Commit 9ae766f

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat-save-log-line-profiler-results
2 parents a4a0283 + cef8503 commit 9ae766f

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test
941941
command = ["codeflash", "--file", "bubble_sort.py", "--function", "sorter"]
942942
if args.no_pr:
943943
command.append("--no-pr")
944+
if args.verbose:
945+
command.append("--verbose")
944946

945947
logger.info("Running sample optimization…")
946948
console.rule()
@@ -953,7 +955,7 @@ def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test
953955
if process.stdout:
954956
for line in process.stdout:
955957
stripped = line.strip()
956-
console.print(stripped)
958+
console.out(stripped)
957959
output.append(stripped)
958960
process.wait()
959961
console.rule()

codeflash/optimization/function_optimizer.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,23 +1389,11 @@ def generate_and_instrument_tests(
13891389
]
13901390

13911391
def cleanup_generated_files(self) -> None:
1392-
paths_to_cleanup = (
1393-
[
1394-
test_file.instrumented_behavior_file_path
1395-
for test_type in [
1396-
TestType.GENERATED_REGRESSION,
1397-
TestType.EXISTING_UNIT_TEST,
1398-
TestType.CONCOLIC_COVERAGE_TEST,
1399-
]
1400-
for test_file in self.test_files.get_by_type(test_type).test_files
1401-
]
1402-
+ [
1403-
test_file.benchmarking_file_path
1404-
for test_type in [TestType.GENERATED_REGRESSION, TestType.EXISTING_UNIT_TEST]
1405-
for test_file in self.test_files.get_by_type(test_type).test_files
1406-
]
1407-
+ [self.test_cfg.concolic_test_root_dir]
1408-
)
1392+
paths_to_cleanup = [self.test_cfg.concolic_test_root_dir]
1393+
for test_file in self.test_files:
1394+
paths_to_cleanup.append(test_file.instrumented_behavior_file_path)
1395+
paths_to_cleanup.append(test_file.benchmarking_file_path)
1396+
14091397
cleanup_paths(paths_to_cleanup)
14101398
if hasattr(get_run_tmp_file, "tmpdir"):
14111399
get_run_tmp_file.tmpdir.cleanup()

codeflash/optimization/optimizer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self, args: Namespace) -> None:
4545
self.local_aiservice_client = LocalAiServiceClient() if self.experiment_id else None
4646
self.replay_tests_dir = None
4747
self.functions_checkpoint: CodeflashRunCheckpoint | None = None
48+
self.current_function_optimizer: FunctionOptimizer | None = None
4849

4950
def create_function_optimizer(
5051
self,
@@ -265,7 +266,9 @@ def run(self) -> None:
265266
function_to_tests,
266267
validated_original_code[original_module_path].source_code,
267268
)
268-
269+
self.current_function_optimizer = (
270+
function_optimizer # needed to clean up from the outside of this function
271+
)
269272
best_optimization = function_optimizer.optimize_function()
270273
if self.functions_checkpoint:
271274
self.functions_checkpoint.add_function_to_checkpoint(
@@ -293,6 +296,9 @@ def run(self) -> None:
293296
def cleanup_temporary_paths(self) -> None:
294297
from codeflash.code_utils.code_utils import cleanup_paths
295298

299+
if self.current_function_optimizer:
300+
self.current_function_optimizer.cleanup_generated_files()
301+
296302
cleanup_paths([self.test_cfg.concolic_test_root_dir, self.replay_tests_dir])
297303

298304

codeflash/telemetry/sentry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None: #
1212
if exclude_errors
1313
else logging.ERROR, # Otherwise, error logs will create sentry events
1414
)
15+
1516
sentry_sdk.init(
1617
dsn="https://4b9a1902f9361b48c04376df6483bc96@o4506833230561280.ingest.sentry.io/4506833262477312",
1718
integrations=[sentry_logging],
@@ -22,4 +23,5 @@ def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None: #
2223
# of sampled transactions.
2324
# We recommend adjusting this value in production.
2425
profiles_sample_rate=1.0,
26+
ignore_errors=[KeyboardInterrupt],
2527
)

codeflash/tracer.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from pathlib import Path
3030
from typing import TYPE_CHECKING, Any, Callable, ClassVar
3131

32-
import dill
3332
import isort
3433
from rich.align import Align
3534
from rich.panel import Panel
@@ -41,6 +40,7 @@
4140
from codeflash.code_utils.code_utils import module_name_from_file_path
4241
from codeflash.code_utils.config_parser import parse_config_file
4342
from codeflash.discovery.functions_to_optimize import filter_files_optimized
43+
from codeflash.picklepatch.pickle_patcher import PicklePatcher
4444
from codeflash.tracing.replay_test import create_trace_replay_test
4545
from codeflash.tracing.tracing_utils import FunctionModules
4646
from codeflash.verification.verification_utils import get_test_file_path
@@ -399,22 +399,12 @@ def tracer_logic(self, frame: FrameType, event: str) -> None: # noqa: PLR0911
399399
arguments_copy = dict(arguments.items()) # Use the local 'arguments' from frame.f_locals
400400
if class_name and code.co_name == "__init__" and "self" in arguments_copy:
401401
del arguments_copy["self"]
402-
local_vars = pickle.dumps(arguments_copy, protocol=pickle.HIGHEST_PROTOCOL)
402+
local_vars = PicklePatcher.dumps(arguments_copy, protocol=pickle.HIGHEST_PROTOCOL)
403403
sys.setrecursionlimit(original_recursion_limit)
404404
except Exception:
405-
# we retry with dill if pickle fails. It's slower but more comprehensive
406-
try:
407-
sys.setrecursionlimit(10000) # Ensure limit is high for dill too
408-
# arguments_copy should be used here as well if defined above
409-
local_vars = dill.dumps(
410-
arguments_copy if "arguments_copy" in locals() else dict(arguments.items()),
411-
protocol=dill.HIGHEST_PROTOCOL,
412-
)
413-
sys.setrecursionlimit(original_recursion_limit)
414-
415-
except Exception:
416-
self.function_count[function_qualified_name] -= 1
417-
return
405+
self.function_count[function_qualified_name] -= 1
406+
sys.setrecursionlimit(original_recursion_limit)
407+
return
418408

419409
cur.execute(
420410
"INSERT INTO function_calls VALUES(?, ?, ?, ?, ?, ?, ?, ?)",

codeflash/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# These version placeholders will be replaced by uv-dynamic-versioning during build.
2-
__version__ = "0.14.5"
3-
__version_tuple__ = (0, 14, 5)
2+
__version__ = "0.14.6"
3+
__version_tuple__ = (0, 14, 6)

0 commit comments

Comments
 (0)