summaryrefslogtreecommitdiff
path: root/experiments/run.py
diff options
context:
space:
mode:
Diffstat (limited to 'experiments/run.py')
-rw-r--r--experiments/run.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/experiments/run.py b/experiments/run.py
index 153ca41..3ad0bdd 100644
--- a/experiments/run.py
+++ b/experiments/run.py
@@ -13,6 +13,7 @@ Everything is JSON-logged for later plotting.
import argparse
import json
import os
+import subprocess
import sys
import time
@@ -25,6 +26,21 @@ from sdil import probes
from sdil.data import get_dataset, onehot, make_hierarchical, make_teacher_student
+def code_provenance():
+ """Best-effort source revision metadata for reproducible result files."""
+ root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ try:
+ commit = subprocess.run(
+ ["git", "rev-parse", "HEAD"], cwd=root, check=True,
+ capture_output=True, text=True).stdout.strip()
+ dirty = bool(subprocess.run(
+ ["git", "status", "--porcelain", "--untracked-files=no"], cwd=root,
+ check=True, capture_output=True, text=True).stdout.strip())
+ return {"git_commit": commit, "git_dirty": dirty}
+ except (OSError, subprocess.CalledProcessError):
+ return {"git_commit": None, "git_dirty": None}
+
+
def build(args, device):
sizes = [args.n_in] + [args.width] * args.depth + [10]
if args.mode == "bp":
@@ -66,7 +82,7 @@ def train(args):
px, py = px[:args.probe_bs].to(device), py[:args.probe_bs].to(device)
poh = onehot(py, n_out, device=device)
- log = {"args": vars(args), "steps": [], "final": {}}
+ log = {"args": vars(args), "provenance": code_provenance(), "steps": [], "final": {}}
step = 0
prev_error = None
t0 = time.time()