Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SWE-bench] Util: Compare files modified between gold patches and OpenDevin patches #2934

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add compare_patch_filename.py
  • Loading branch information
li-boxuan committed Jul 15, 2024
commit f70bba9a43b51184903cff4d0e411a5affbfc79a
55 changes: 55 additions & 0 deletions evaluation/swe_bench/scripts/setup/compare_patch_filename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
This script compares gold patches with OpenDevin-generated patches and check whether
OpenDevin found the right (set of) files to modify.
"""

import argparse
import json
import re


def extract_modified_files(patch):
modified_files = set()
file_pattern = re.compile(r'^diff --git a/(.*?) b/')

for line in patch.split('\n'):
match = file_pattern.match(line)
if match:
modified_files.add(match.group(1))

return modified_files


def process_report(od_output_file):
succ = 0
fail = 0
for line in open(od_output_file):
line = json.loads(line)
instance_id = line['instance_id']
gold_patch = line['swe_instance']['patch']
generated_patch = line['git_patch']
gold_modified_files = extract_modified_files(gold_patch)
# swe-bench lite only: a gold patch always contains exactly one file
assert len(gold_modified_files) == 1
generated_modified_files = extract_modified_files(generated_patch)

# Check if all files in gold_patch are also in generated_patch
all_files_in_generated = gold_modified_files.issubset(generated_modified_files)
if all_files_in_generated:
succ += 1
else:
fail += 1
print(
f'{instance_id}: file mismatch, gold = {gold_modified_files}, generated = {generated_modified_files}'
)
print(
f'\nSUMMARY: {succ} out of {succ + fail} instances found correct files to edit, success rate = {succ / float(succ + fail)}'
)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--od_output_file', help='Path to the OD output file')
args = parser.parse_args()

process_report(args.od_output_file)