Download scripts/verify_dataset.py from SupingSun/ReproBoundary-Execution-Trajectories: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/datasets/SupingSun/ReproBoundary-Execution-Trajectories/resolve/main/scripts/verify_dataset.py
- Command line
-
hf download hf://datasets/SupingSun/ReproBoundary-Execution-Trajectories/scripts/verify_dataset.py
-
curl -L -o verify_dataset.py https://huggingface.co/datasets/SupingSun/ReproBoundary-Execution-Trajectories/resolve/main/scripts/verify_dataset.py
3.88 kB
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import csv | |
| import gzip | |
| import hashlib | |
| import json | |
| import re | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def sha256(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for block in iter(lambda: handle.read(1024 * 1024), b""): | |
| digest.update(block) | |
| return digest.hexdigest() | |
| errors: list[str] = [] | |
| tasks = list( | |
| csv.DictReader( | |
| (ROOT / "task_pool/TASK_INVENTORY_47.csv").open(encoding="utf-8-sig") | |
| ) | |
| ) | |
| runs = list( | |
| csv.DictReader( | |
| (ROOT / "trajectories/TRAJECTORY_INDEX.csv").open(encoding="utf-8") | |
| ) | |
| ) | |
| project_ids = {row["project_id"] for row in tasks} | |
| task_ids = {row["task_id"] for row in runs} | |
| settings = {(row["base_model"], row["agent"]) for row in runs} | |
| if len(tasks) != 47 or len(project_ids) != 47: | |
| errors.append("task inventory is not 47 unique projects") | |
| if len(runs) != 423 or len(task_ids) != 423: | |
| errors.append("trajectory index is not 423 unique assignments") | |
| if len(settings) != 9: | |
| errors.append("trajectory index is not nine unique model-agent settings") | |
| if {row["project"] for row in runs} != project_ids: | |
| errors.append("trajectory projects do not match the task inventory") | |
| strong_patterns = { | |
| "local_path": re.compile(r"/Users/ssp|/lustre/prod_glm_volumes"), | |
| "api_key": re.compile(r"(?<![A-Za-z0-9])sk-(?:ant-)?[A-Za-z0-9_-]{12,}"), | |
| "service_token": re.compile( | |
| r"(?<![A-Za-z0-9])(?:ghp_[A-Za-z0-9]{20,}|" | |
| r"github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{20,}|" | |
| r"hf_[A-Za-z0-9]{30,})" | |
| ), | |
| "authorization": re.compile( | |
| r"(?i)authorization\s*[:=]\s*(?:bearer|basic)\s+" | |
| r"(?!<REDACTED>)[A-Za-z0-9][A-Za-z0-9._~+/-]{7,}" | |
| ), | |
| "private_key": re.compile(r"BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY"), | |
| } | |
| for row in runs: | |
| log = ROOT / row["trajectory_path"] | |
| if not log.is_file(): | |
| errors.append(f"missing trajectory: {row['task_id']}") | |
| continue | |
| if log.name != "agent.log.gz": | |
| errors.append(f"unexpected trajectory filename: {row['task_id']}") | |
| if sha256(log) != row["released_log_sha256"]: | |
| errors.append(f"trajectory hash mismatch: {row['task_id']}") | |
| continue | |
| try: | |
| with gzip.open(log, "rt", encoding="utf-8", errors="replace") as handle: | |
| for line_number, line in enumerate(handle, 1): | |
| matched = False | |
| for name, pattern in strong_patterns.items(): | |
| if pattern.search(line): | |
| errors.append( | |
| f"residual {name}: {row['task_id']}:{line_number}" | |
| ) | |
| matched = True | |
| break | |
| if matched: | |
| break | |
| except (OSError, EOFError) as exc: | |
| errors.append(f"unreadable gzip: {row['task_id']}: {exc}") | |
| manifest = json.loads((ROOT / "DATASET_MANIFEST.json").read_text(encoding="utf-8")) | |
| if manifest.get("task_count") != 47: | |
| errors.append("manifest task count is not 47") | |
| if manifest.get("model_agent_setting_count") != 9: | |
| errors.append("manifest setting count is not nine") | |
| if manifest.get("trajectory_file_count") != 423: | |
| errors.append("manifest trajectory count is not 423") | |
| checksum_file = ROOT / "DATASET_SHA256SUMS" | |
| for raw in checksum_file.read_text(encoding="utf-8").splitlines(): | |
| expected, relative = raw.split(" ", 1) | |
| path = ROOT / relative | |
| if not path.is_file() or sha256(path) != expected: | |
| errors.append(f"dataset checksum mismatch: {relative}") | |
| if errors: | |
| print("verification FAILED") | |
| for error in errors[:50]: | |
| print("-", error) | |
| raise SystemExit(1) | |
| print( | |
| "verification OK: " | |
| f"tasks={len(tasks)} settings={len(settings)} trajectories={len(runs)}" | |
| ) | |