Download tasks/pb-basic-018/tests/grade_task.py from HuggingFaceSwarms/IMO-ProofBench: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/datasets/HuggingFaceSwarms/IMO-ProofBench/resolve/main/tasks/pb-basic-018/tests/grade_task.py
- Command line
-
hf download hf://datasets/HuggingFaceSwarms/IMO-ProofBench/tasks/pb-basic-018/tests/grade_task.py
-
curl -L -o grade_task.py https://huggingface.co/datasets/HuggingFaceSwarms/IMO-ProofBench/resolve/main/tasks/pb-basic-018/tests/grade_task.py
2.67 kB
| """Offline structural validation only; external rubric judge assigns 0–7 points.""" | |
| import json, os, stat | |
| LIMIT = 200_000 | |
| def read_own(path): | |
| """Reject links, special files, multiple hard links, and oversized files.""" | |
| parts = os.path.abspath(path).split('/')[1:] | |
| folder = os.open('/', os.O_RDONLY | os.O_DIRECTORY) | |
| try: | |
| for part in parts[:-1]: | |
| inner = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=folder) | |
| os.close(folder) | |
| folder = inner | |
| fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=folder) | |
| finally: | |
| os.close(folder) | |
| with os.fdopen(fd, 'rb') as stream: | |
| info = os.fstat(stream.fileno()) | |
| if not stat.S_ISREG(info.st_mode) or info.st_nlink != 1: | |
| raise ValueError('not a regular file with one link') | |
| data = stream.read(LIMIT + 1) | |
| if len(data) > LIMIT: | |
| raise ValueError('file exceeds 200000 bytes') | |
| return data | |
| def write_new(path, data): | |
| try: os.unlink(path) | |
| except FileNotFoundError: pass | |
| fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o644) | |
| with os.fdopen(fd, 'wb') as f: f.write(data) | |
| def main(): | |
| out = os.environ['VERIFIER_DIR'] | |
| os.makedirs(out, exist_ok=True) | |
| write_new(os.path.join(out, 'reward.txt'), b'0\n') | |
| proof_path = os.path.join(out, 'proof.md') | |
| try: os.unlink(proof_path) | |
| except FileNotFoundError: pass | |
| reference = open(os.path.join(os.environ['TESTS_DIR'], 'reference.json'), 'rb').read() | |
| json.loads(reference) | |
| write_new(os.path.join(out, 'reference.json'), reference) | |
| status, count, reason = 'missing', 0, 'proof unavailable or invalid' | |
| try: | |
| raw = read_own(os.environ['PROOF']) | |
| proof = raw.decode('utf-8', 'strict') | |
| count = len(proof) | |
| write_new(proof_path, raw) | |
| if sum(not c.isspace() for c in proof) < 20: | |
| status, reason = 'empty', 'fewer than 20 non-whitespace characters' | |
| else: | |
| status, reason = 'submitted_for_judge', 'structurally valid submission' | |
| except (OSError, ValueError, UnicodeError) as e: | |
| reason = 'proof unavailable or invalid: ' + str(e)[:200] | |
| result = {'status': status, 'char_count': count, 'requires_llm_judge': True, 'max_score': 7, 'reason': reason} | |
| write_new(os.path.join(out, 'grade.json'), (json.dumps(result, ensure_ascii=False, indent=2)+'\n').encode()) | |
| if status == 'submitted_for_judge': write_new(os.path.join(out, 'reward.txt'), b'1\n') | |
| print(status, 'structural reward:', int(status == 'submitted_for_judge')) | |
| if __name__ == '__main__': main() | |