SPB Git

spb/wp32_uqo

Public
1.9 KB · 63 lines python
1"""Path setup shared by all scripts in code/: makes the run root the working2directory, puts the workspace-local dependency directory (.pydeps) and code/3on sys.path, and provides small provenance helpers."""4import datetime5import hashlib6import json7import os8import resource9import sys10import time1112ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))13sys.path.insert(0, os.path.join(ROOT, ".pydeps"))14sys.path.insert(0, os.path.join(ROOT, "code"))15os.chdir(ROOT)1617RESULTS = os.path.join(ROOT, "results")18# AUTOSCHOLAR_CERTS_DIR lets reproduce.sh write regenerated certificates next to, not over, the shipped ones19CERTS = os.environ.get("AUTOSCHOLAR_CERTS_DIR") or os.path.join(ROOT, "code", "proofs", "certificates")20os.makedirs(RESULTS, exist_ok=True)21os.makedirs(CERTS, exist_ok=True)222324def utcnow():25    return datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds")262728def sha256_file(path):29    h = hashlib.sha256()30    with open(path, "rb") as f:31        for chunk in iter(lambda: f.read(1 << 20), b""):32            h.update(chunk)33    return h.hexdigest()343536def peak_rss_mb():37    r = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss38    # macOS reports bytes, Linux kilobytes39    return r / (1 << 20) if sys.platform == "darwin" else r / 1024.0404142def cpu_time():43    r = resource.getrusage(resource.RUSAGE_SELF)44    return r.ru_utime + r.ru_stime454647def append_jsonl(path, obj):48    with open(path, "a") as f:49        f.write(json.dumps(obj, sort_keys=True) + "\n")505152def log_event(stage, event, **fields):53    rec = {"utc": utcnow(), "stage": stage, "event": event}54    rec.update(fields)55    append_jsonl(os.path.join(RESULTS, "experiment-log.jsonl"), rec)56    return rec575859def versions():60    import pysat61    return {"python": sys.version.split()[0], "python_sat": pysat.__version__,62            "platform": sys.platform, "worker": os.environ.get("AUTOSCHOLAR_WORKER", "M4M64c")}63
Files · main
Menu

Theme