|
8 | 8 | from codeflash.code_utils.compat import SAFE_SYS_EXECUTABLE |
9 | 9 | from codeflash.discovery.functions_to_optimize import FunctionToOptimize |
10 | 10 | from codeflash.models.models import FunctionParent, TestFile, TestFiles, TestingMode, TestType, VerificationType |
11 | | -from codeflash.optimization.function_optimizer import FunctionOptimizer |
| 11 | +from codeflash.languages.python.function_optimizer import PythonFunctionOptimizer |
12 | 12 | from codeflash.verification.equivalence import compare_test_results |
13 | 13 | from codeflash.verification.instrument_codeflash_capture import instrument_codeflash_capture |
14 | 14 | from codeflash.verification.test_runner import execute_test_subprocess |
@@ -459,7 +459,7 @@ def __init__(self, x=2): |
459 | 459 | file_path=sample_code_path, |
460 | 460 | parents=[FunctionParent(name="MyClass", type="ClassDef")], |
461 | 461 | ) |
462 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 462 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
463 | 463 | func_optimizer.test_files = TestFiles( |
464 | 464 | test_files=[ |
465 | 465 | TestFile( |
@@ -582,7 +582,7 @@ def __init__(self, *args, **kwargs): |
582 | 582 | file_path=sample_code_path, |
583 | 583 | parents=[FunctionParent(name="MyClass", type="ClassDef")], |
584 | 584 | ) |
585 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 585 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
586 | 586 | func_optimizer.test_files = TestFiles( |
587 | 587 | test_files=[ |
588 | 588 | TestFile( |
@@ -709,7 +709,7 @@ def __init__(self, x=2): |
709 | 709 | file_path=sample_code_path, |
710 | 710 | parents=[FunctionParent(name="MyClass", type="ClassDef")], |
711 | 711 | ) |
712 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 712 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
713 | 713 | func_optimizer.test_files = TestFiles( |
714 | 714 | test_files=[ |
715 | 715 | TestFile( |
@@ -872,7 +872,7 @@ def another_helper(self): |
872 | 872 | file_path=fto_file_path, |
873 | 873 | parents=[FunctionParent(name="MyClass", type="ClassDef")], |
874 | 874 | ) |
875 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 875 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
876 | 876 | func_optimizer.test_files = TestFiles( |
877 | 877 | test_files=[ |
878 | 878 | TestFile( |
@@ -1021,7 +1021,7 @@ def another_helper(self): |
1021 | 1021 | test_framework="pytest", |
1022 | 1022 | pytest_cmd="pytest", |
1023 | 1023 | ) |
1024 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 1024 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
1025 | 1025 | func_optimizer.test_files = TestFiles( |
1026 | 1026 | test_files=[ |
1027 | 1027 | TestFile( |
@@ -1055,7 +1055,7 @@ def another_helper(self): |
1055 | 1055 | ) |
1056 | 1056 |
|
1057 | 1057 | # Remove instrumentation |
1058 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1058 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1059 | 1059 |
|
1060 | 1060 | assert len(test_results.test_results) == 4 |
1061 | 1061 | assert test_results[0].id.test_function_name == "test_helper_classes" |
@@ -1106,7 +1106,7 @@ def target_function(self): |
1106 | 1106 | testing_time=0.1, |
1107 | 1107 | ) |
1108 | 1108 | # Remove instrumentation |
1109 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1109 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1110 | 1110 |
|
1111 | 1111 | # Now, this fto_code mutates the instance so it should fail |
1112 | 1112 | mutated_fto_code = """ |
@@ -1145,7 +1145,7 @@ def target_function(self): |
1145 | 1145 | testing_time=0.1, |
1146 | 1146 | ) |
1147 | 1147 | # Remove instrumentation |
1148 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1148 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1149 | 1149 | match, _ = compare_test_results(test_results, mutated_test_results) |
1150 | 1150 | assert not match |
1151 | 1151 |
|
@@ -1184,7 +1184,7 @@ def target_function(self): |
1184 | 1184 | testing_time=0.1, |
1185 | 1185 | ) |
1186 | 1186 | # Remove instrumentation |
1187 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1187 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1188 | 1188 | match, _ = compare_test_results(test_results, no_helper1_test_results) |
1189 | 1189 | assert match |
1190 | 1190 |
|
@@ -1446,7 +1446,7 @@ def calculate_portfolio_metrics( |
1446 | 1446 | test_framework="pytest", |
1447 | 1447 | pytest_cmd="pytest", |
1448 | 1448 | ) |
1449 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 1449 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
1450 | 1450 | func_optimizer.test_files = TestFiles( |
1451 | 1451 | test_files=[ |
1452 | 1452 | TestFile( |
@@ -1477,7 +1477,7 @@ def calculate_portfolio_metrics( |
1477 | 1477 | ) |
1478 | 1478 |
|
1479 | 1479 | # Remove instrumentation |
1480 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1480 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1481 | 1481 |
|
1482 | 1482 | # Now, let's say we optimize the code and make changes. |
1483 | 1483 | new_fto_code = """import math |
@@ -1543,7 +1543,7 @@ def risk_adjusted_return(return_val, weight): |
1543 | 1543 | testing_time=0.1, |
1544 | 1544 | ) |
1545 | 1545 | # Remove instrumentation |
1546 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1546 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1547 | 1547 | matched, diffs = compare_test_results(test_results, modified_test_results) |
1548 | 1548 |
|
1549 | 1549 | assert not matched |
@@ -1606,7 +1606,7 @@ def calculate_portfolio_metrics( |
1606 | 1606 | testing_time=0.1, |
1607 | 1607 | ) |
1608 | 1608 | # Remove instrumentation |
1609 | | - FunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
| 1609 | + PythonFunctionOptimizer.write_code_and_helpers(candidate_fto_code, candidate_helper_code, fto.file_path) |
1610 | 1610 | matched, diffs = compare_test_results(test_results, modified_test_results_2) |
1611 | 1611 | # now the test should match and no diffs should be found |
1612 | 1612 | assert len(diffs) == 0 |
@@ -1671,7 +1671,7 @@ def __init__(self, x, y): |
1671 | 1671 | file_path=sample_code_path, |
1672 | 1672 | parents=[FunctionParent(name="SlotsClass", type="ClassDef")], |
1673 | 1673 | ) |
1674 | | - func_optimizer = FunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
| 1674 | + func_optimizer = PythonFunctionOptimizer(function_to_optimize=fto, test_cfg=test_config) |
1675 | 1675 | func_optimizer.test_files = TestFiles( |
1676 | 1676 | test_files=[ |
1677 | 1677 | TestFile( |
|
0 commit comments