CrossSWE-Bench / scripts /crossswe.py
Silin-Chen's picture
CrossSWE-Bench: current 171-instance release
0e239c6
Raw History Blame Contribute Delete
4.76 kB
"""Inspect task statements, evaluation entry points and pinned environments."""
from pathlib import Path
import argparse
import json
import re
import subprocess
from common import load_task
from statement_text import read_problem_statement
ROOT = Path(__file__).resolve().parents[1]
def entries():
return {entry['instance_id']: entry for entry in json.loads(
(ROOT / 'data/evaluation-entrypoints.json').read_text())['instances']}
def support(entry):
if entry['candidate_support'] == 'explicit_static_API_available':
return 'candidate_api_detected'
return 'instance_specific'
def task_row(instance_id):
with (ROOT / 'data/crossswe-bench.jsonl').open() as stream:
for line in stream:
row = json.loads(line)
if row['instance_id'] == instance_id:
return row
raise ValueError('Task is absent from the dataset table')
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('command', choices=['list', 'show', 'statement', 'image', 'pull', 'shell', 'evaluator'])
parser.add_argument('--instance-id')
parser.add_argument('--candidate-support', choices=['all', 'detected', 'manual'], default='all',
help='Filter list by statically detected API or instance-specific instructions')
parser.add_argument('--format', choices=['json', 'text'], default='json',
help='Output format for evaluator inspection; never executes an evaluator')
args = parser.parse_args()
records = [json.loads(line) for line in (ROOT / 'data/images.jsonl').read_text().splitlines()]
table = {row['instance_id']: row for row in records}
if args.command == 'list':
index = entries() if args.candidate_support != 'all' else None
for row in records:
if index is not None:
detected = support(index[row['instance_id']]) == 'candidate_api_detected'
if detected != (args.candidate_support == 'detected'):
continue
print(row['instance_id'])
return
if args.instance_id not in table:
parser.error('Provide a canonical --instance-id from the list command')
row = table[args.instance_id]
image = row['image_ref']
if not re.fullmatch(r'silinchen0617/crossrepo-bench@sha256:[0-9a-f]{64}', image):
raise ValueError('The image must use its pinned registry digest')
if args.command == 'image':
print(image)
elif args.command == 'statement':
print(read_problem_statement(load_task(args.instance_id)), end='')
elif args.command == 'evaluator':
entry = entries()[args.instance_id]
if args.format == 'json':
print(json.dumps(entry, indent=2))
else:
print('Instance: ' + args.instance_id)
print('Evaluation support: ' + support(entry))
if entry.get('candidate_entry'):
print('Candidate entry: ' + entry['candidate_entry'])
print('Interface detected by static inspection; runtime requirements still apply.')
else:
print('Use the instance contract and instructions; no verified candidate API is indexed.')
print('Contract: instances/' + args.instance_id + '/evaluation/contract.json')
for path in entry.get('documentation', []):
print('Documentation: ' + path)
if not entry.get('documentation'):
print('Environment metadata: ' + entry['image_json'])
if entry.get('candidate_required_runtime_inputs'):
print('Additional runtime inputs: ' + ', '.join(entry['candidate_required_runtime_inputs']))
print('Directory: docs/evaluators.md')
elif args.command == 'show':
task = load_task(args.instance_id)
record = task_row(args.instance_id)
print(json.dumps({**row, 'repositories': task['repositories'],
'statement_file': 'statements/' + args.instance_id + '.md',
'PASS_TO_PASS_count': record['PASS_TO_PASS_count'],
'FAIL_TO_PASS_count': record['FAIL_TO_PASS_count'],
'evaluation_support': record['evaluation_support'],
'evaluation_contract': 'instances/' + args.instance_id + '/' + task['evaluation']['path']}, indent=2))
elif args.command == 'pull':
subprocess.run(['docker', 'pull', '--platform', 'linux/amd64', image], check=True)
else:
subprocess.run(['docker', 'run', '--rm', '-it', '--platform', 'linux/amd64',
'--network=none', '--entrypoint=/bin/bash', image], check=True)
if __name__ == '__main__':
main()