| """ |
| generate_reproducibility.py |
| =========================== |
| Generates a reproducibility manifest for GomParam-v1. |
| """ |
|
|
| import datetime |
| import hashlib |
| import json |
| import subprocess |
| import sys |
| from pathlib import Path |
|
|
| OUT_DIR = Path("/mnt/data/projects/GomParam-v1/results") |
| OUT_DIR.mkdir(parents=True, exist_ok=True) |
| DATA_DIR = Path("/mnt/data/projects/GomParam-v1/data") |
|
|
| def get_git_commit(): |
| try: |
| return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip() |
| except Exception: |
| return "unknown" |
|
|
| def get_package_versions(): |
| try: |
| reqs = subprocess.check_output(["pip", "freeze"]).decode("utf-8").splitlines() |
| packages = ["transformers", "torch", "datasets", "numpy", "scipy", "accelerate"] |
| versions = {} |
| for r in reqs: |
| for p in packages: |
| if r.startswith(f"{p}=="): |
| versions[p] = r.split("==")[1] |
| return versions |
| except Exception: |
| return {} |
|
|
| def compute_dataset_hash(): |
| """Compute SHA256 of all JSON files combined.""" |
| hasher = hashlib.sha256() |
| for f in sorted(DATA_DIR.glob("*.json")): |
| with open(f, "rb") as bf: |
| hasher.update(bf.read()) |
| return hasher.hexdigest() |
|
|
| manifest = { |
| "dataset_name": "GomParam-v1", |
| "dataset_version": "1.0", |
| "dataset_sha256": compute_dataset_hash(), |
| "hf_dataset_revision": "main", |
| "evaluation_commit_hash": get_git_commit(), |
| "python_version": sys.version.split()[0], |
| "package_versions": get_package_versions(), |
| "evaluation_timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(), |
| "random_seeds": { |
| "bootstrap": 42, |
| "option_shuffle": 42 |
| } |
| } |
|
|
| out_file = OUT_DIR / "reproducibility.json" |
| with open(out_file, "w") as f: |
| json.dump(manifest, f, indent=2) |
|
|
| print(f"Reproducibility manifest generated: {out_file}") |
|
|