File size: 4,764 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""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()