Skip to content

Commit 98ec87e

Browse files
committed
Resolve the conflict
1 parent 5715928 commit 98ec87e

File tree

2 files changed

+93
-77
lines changed

2 files changed

+93
-77
lines changed

codeflash/api/cfapi.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ def create_pr(
183183
}
184184
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
185185

186+
186187
def create_staging(
187-
original_code: str,
188-
new_code: str,
188+
original_code: dict[Path, str],
189+
new_code: dict[Path, str],
189190
explanation: Explanation,
190191
existing_tests_source: str,
191192
generated_original_test_source: str,
@@ -194,15 +195,15 @@ def create_staging(
194195
) -> Response:
195196
"""Create a staging pull request, targeting the specified branch. (usually 'staging').
196197
197-
:param owner: The owner of the repository.
198-
:param repo: The name of the repository.
199-
:param base_branch: The base branch to target.
200-
:param file_changes: A dictionary of file changes.
201-
:param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc.
202-
:param generated_tests: The generated tests.
203-
:return: The response object.
198+
:param original_code: A mapping of file paths to original source code.
199+
:param new_code: A mapping of file paths to optimized source code.
200+
:param explanation: An Explanation object with optimization details.
201+
:param existing_tests_source: Existing test code.
202+
:param generated_original_test_source: Generated tests for the original function.
203+
:param function_trace_id: Unique identifier for this optimization trace.
204+
:param coverage_message: Coverage report or summary.
205+
:return: The response object from the backend.
204206
"""
205-
# convert Path objects to strings
206207
relative_path = explanation.file_path.relative_to(git_root_dir()).as_posix()
207208

208209
build_file_changes = {
@@ -211,6 +212,7 @@ def create_staging(
211212
)
212213
for p in original_code
213214
}
215+
214216
payload = {
215217
"baseBranch": get_current_branch(),
216218
"diffContents": build_file_changes,
@@ -222,7 +224,7 @@ def create_staging(
222224
relative_file_path=relative_path,
223225
speedup_x=explanation.speedup_x,
224226
speedup_pct=explanation.speedup_pct,
225-
winning_behavioral_test_results=explanation.winning_behavioral_test_results,
227+
winning_behavior_test_results=explanation.winning_behavior_test_results,
226228
winning_benchmarking_test_results=explanation.winning_benchmarking_test_results,
227229
benchmark_details=explanation.benchmark_details,
228230
).to_json(),
@@ -231,6 +233,7 @@ def create_staging(
231233
"traceId": function_trace_id,
232234
"coverage_message": coverage_message,
233235
}
236+
234237
return make_cfapi_request(endpoint="/create-staging", method="POST", payload=payload)
235238

236239

codeflash/optimization/function_optimizer.py

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,6 @@ def find_and_process_best_optimization(
998998
original_code_combined[explanation.file_path] = self.function_to_optimize_source_code
999999
new_code_combined = new_helper_code.copy()
10001000
new_code_combined[explanation.file_path] = new_code
1001-
<<<<<<< feat-staging
10021001
self.process_review(
10031002
original_code_baseline,
10041003
best_optimization,
@@ -1012,71 +1011,85 @@ def find_and_process_best_optimization(
10121011
exp_type,
10131012
original_helper_code,
10141013
)
1015-
=======
1016-
if not self.args.no_pr:
1017-
coverage_message = (
1018-
original_code_baseline.coverage_results.build_message()
1019-
if original_code_baseline.coverage_results
1020-
else "Coverage data not available"
1021-
)
1022-
generated_tests = remove_functions_from_generated_tests(
1023-
generated_tests=generated_tests, test_functions_to_remove=test_functions_to_remove
1024-
)
1025-
original_runtime_by_test = (
1026-
original_code_baseline.benchmarking_test_results.usable_runtime_data_by_test_case()
1027-
)
1028-
optimized_runtime_by_test = (
1029-
best_optimization.winning_benchmarking_test_results.usable_runtime_data_by_test_case()
1030-
)
1031-
qualified_name = self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root)
1032-
# Add runtime comments to generated tests before creating the PR
1033-
generated_tests = add_runtime_comments_to_generated_tests(
1034-
generated_tests, original_runtime_by_test, optimized_runtime_by_test
1035-
)
1036-
generated_tests_str = "\n\n".join(
1037-
[test.generated_original_test_source for test in generated_tests.generated_tests]
1038-
)
1039-
existing_tests = existing_tests_source_for(
1040-
qualified_name,
1041-
function_to_all_tests,
1042-
test_cfg=self.test_cfg,
1043-
original_runtimes_all=original_runtime_by_test,
1044-
optimized_runtimes_all=optimized_runtime_by_test,
1045-
)
1046-
if concolic_test_str:
1047-
generated_tests_str += "\n\n" + concolic_test_str
1048-
1049-
check_create_pr(
1050-
original_code=original_code_combined,
1051-
new_code=new_code_combined,
1052-
explanation=explanation,
1053-
existing_tests_source=existing_tests,
1054-
generated_original_test_source=generated_tests_str,
1055-
function_trace_id=self.function_trace_id[:-4] + exp_type
1056-
if self.experiment_id
1057-
else self.function_trace_id,
1058-
coverage_message=coverage_message,
1059-
git_remote=self.args.git_remote,
1060-
)
1061-
if (
1062-
self.args.all
1063-
or env_utils.get_pr_number()
1064-
or self.args.replay_test
1065-
or (self.args.file and not self.args.function)
1066-
):
1067-
self.write_code_and_helpers(
1068-
self.function_to_optimize_source_code,
1069-
original_helper_code,
1070-
self.function_to_optimize.file_path,
1071-
)
1072-
else:
1073-
# Mark optimization success since no PR will be created
1074-
mark_optimization_success(
1075-
trace_id=self.function_trace_id, is_optimization_found=best_optimization is not None
1076-
)
1077-
>>>>>>> main
1078-
self.log_successful_optimization(explanation, generated_tests, exp_type)
1079-
return best_optimization
1014+
self.log_successful_optimization(explanation, generated_tests, exp_type)
1015+
return best_optimization
1016+
1017+
def process_review(
1018+
self,
1019+
original_code_baseline: OriginalCodeBaseline,
1020+
best_optimization: BestOptimization,
1021+
generated_tests: GeneratedTestsList,
1022+
test_functions_to_remove: list[str],
1023+
concolic_test_str: str | None,
1024+
original_code_combined: dict[Path, str],
1025+
new_code_combined: dict[Path, str],
1026+
explanation: Explanation,
1027+
function_to_all_tests: dict[str, set[FunctionCalledInTest]],
1028+
exp_type: str,
1029+
original_helper_code: dict[Path, str],
1030+
) -> None:
1031+
coverage_message = (
1032+
original_code_baseline.coverage_results.build_message()
1033+
if original_code_baseline.coverage_results
1034+
else "Coverage data not available"
1035+
)
1036+
1037+
generated_tests = remove_functions_from_generated_tests(
1038+
generated_tests=generated_tests, test_functions_to_remove=test_functions_to_remove
1039+
)
1040+
1041+
original_runtime_by_test = original_code_baseline.benchmarking_test_results.usable_runtime_data_by_test_case()
1042+
optimized_runtime_by_test = (
1043+
best_optimization.winning_benchmarking_test_results.usable_runtime_data_by_test_case()
1044+
)
1045+
1046+
generated_tests = add_runtime_comments_to_generated_tests(
1047+
self.test_cfg, generated_tests, original_runtime_by_test, optimized_runtime_by_test
1048+
)
1049+
1050+
generated_tests_str = "\n\n".join(
1051+
[test.generated_original_test_source for test in generated_tests.generated_tests]
1052+
)
1053+
if concolic_test_str:
1054+
generated_tests_str += "\n\n" + concolic_test_str
1055+
1056+
existing_tests = existing_tests_source_for(
1057+
self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root),
1058+
function_to_all_tests,
1059+
test_cfg=self.test_cfg,
1060+
original_runtimes_all=original_runtime_by_test,
1061+
optimized_runtimes_all=optimized_runtime_by_test,
1062+
)
1063+
1064+
data = {
1065+
"original_code": original_code_combined,
1066+
"new_code": new_code_combined,
1067+
"explanation": explanation,
1068+
"existing_tests_source": existing_tests,
1069+
"generated_original_test_source": generated_tests_str,
1070+
"function_trace_id": self.function_trace_id[:-4] + exp_type
1071+
if self.experiment_id
1072+
else self.function_trace_id,
1073+
"coverage_message": coverage_message,
1074+
}
1075+
1076+
if not self.args.no_pr and not self.args.staging_review:
1077+
data["git_remote"] = self.args.git_remote
1078+
check_create_pr(**data)
1079+
elif self.args.staging_review:
1080+
create_staging(**data)
1081+
else:
1082+
# Mark optimization success since no PR will be created
1083+
mark_optimization_success(
1084+
trace_id=self.function_trace_id, is_optimization_found=best_optimization is not None
1085+
)
1086+
1087+
if ((not self.args.no_pr) or not self.args.staging_review) and (
1088+
self.args.all or env_utils.get_pr_number() or (self.args.file and not self.args.function)
1089+
):
1090+
self.write_code_and_helpers(
1091+
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
1092+
)
10801093

10811094
def establish_original_code_baseline(
10821095
self,

0 commit comments

Comments
 (0)