SPB Git

spb/anomaly-atlas Public License

Systematic discovery & rigorous validation of statistical anomalies in open HF market data (hfmarketdata.io) — pre-registered, artifact-null-driven, fully reproducible. Live atlas: www.anomaly-atlas.io

Python 61.4% JavaScript 28.7% CSS 8.6% Shell 0.7% Makefile 0.5%
4.7 KB · 145 lines python
Raw Blame History
1#!/usr/bin/env python32# =============================================================================3#  Project   : anomaly-atlas4#  File      : benchmarks/hardware_manifest.py5#  Purpose   : macOS hardware/software fingerprint embedded in every result file6#  Author    : Simon-Pierre Boucher7#  Contact   : contact@spboucher.ai8#  Data src  : hfmarketdata.io (sole data source)9#  Created   : 2026-08-1210#  Modified  : 2026-08-1211#  Platform  : macOS / Apple Silicon (arm64)12#  License   : All rights reserved (research code)13# =============================================================================14"""Collect a reproducibility manifest for the current Mac.1516Records chip model, P/E core counts, GPU core count, unified memory size,17SSD model, macOS version, and versions of the key software stack (Python,18NumPy, pandas, polars, DuckDB, statsmodels, arch), plus the current git19commit. Every result JSON must embed this manifest plus the author/contact/20data-source attribution (CLAUDE.md §0.1, §0.2, §10).2122Usage:23    python3 benchmarks/hardware_manifest.py            # pretty-print JSON24    from hardware_manifest import collect_manifest     # programmatic use25"""2627from __future__ import annotations2829import json30import platform31import subprocess32import sys33from datetime import UTC, datetime343536def _run(cmd: list[str]) -> str:37    try:38        return subprocess.run(cmd, capture_output=True, text=True, timeout=30).stdout.strip()39    except (OSError, subprocess.TimeoutExpired):40        return ""414243def _sysctl(key: str) -> str:44    return _run(["sysctl", "-n", key])454647def _sysctl_int(key: str) -> int | None:48    val = _sysctl(key)49    try:50        return int(val)51    except ValueError:52        return None535455def _gpu_cores() -> int | None:56    """GPU core count via system_profiler (no sysctl key exposes it)."""57    out = _run(["system_profiler", "SPDisplaysDataType", "-json"])58    try:59        displays = json.loads(out)["SPDisplaysDataType"]60        for gpu in displays:61            cores = gpu.get("sppci_cores")62            if cores is not None:63                return int(cores)64    except (json.JSONDecodeError, KeyError, ValueError, TypeError):65        pass66    return None676869def _ssd_info() -> dict:70    out = _run(["system_profiler", "SPNVMeDataType", "-json"])71    try:72        items = json.loads(out)["SPNVMeDataType"]73        for controller in items:74            for dev in controller.get("_items", []):75                return {76                    "model": dev.get("device_model", "").strip(),77                    "size": dev.get("size", ""),78                    "smart_status": dev.get("smart_status", ""),79                }80    except (json.JSONDecodeError, KeyError, TypeError):81        pass82    return {"model": None, "size": None, "smart_status": None}838485def _pkg_version(module: str) -> str | None:86    try:87        from importlib.metadata import version8889        return version(module)90    except Exception:91        return None929394def _git_commit() -> dict:95    commit = _run(["git", "rev-parse", "HEAD"])96    dirty = bool(_run(["git", "status", "--porcelain"]))97    return {"commit": commit or None, "dirty_tree": dirty}9899100def collect_manifest() -> dict:101    """Return the full hardware/software manifest as a dict."""102    mem_bytes = _sysctl_int("hw.memsize") or 0103    manifest = {104        "author": "Simon-Pierre Boucher",105        "contact": "contact@spboucher.ai",106        "project": "anomaly-atlas",107        "data_source": "hfmarketdata.io",108        "collected_utc": datetime.now(UTC).isoformat(),109        "chip": {110            "brand": _sysctl("machdep.cpu.brand_string"),111            "arch": platform.machine(),112            "cores_total": _sysctl_int("hw.ncpu"),113            "cores_performance": _sysctl_int("hw.perflevel0.physicalcpu"),114            "cores_efficiency": _sysctl_int("hw.perflevel1.physicalcpu"),115            "gpu_cores": _gpu_cores(),116        },117        "memory": {118            "unified_bytes": mem_bytes,119            "unified_gb": round(mem_bytes / 2**30, 1),120            "pagesize": _sysctl_int("hw.pagesize"),121        },122        "ssd": _ssd_info(),123        "os": {124            "product": _run(["sw_vers", "-productName"]),125            "version": _run(["sw_vers", "-productVersion"]),126            "build": _run(["sw_vers", "-buildVersion"]),127            "kernel": platform.release(),128        },129        "software": {130            "python": sys.version.split()[0],131            "numpy": _pkg_version("numpy"),132            "pandas": _pkg_version("pandas"),133            "polars": _pkg_version("polars"),134            "duckdb": _pkg_version("duckdb"),135            "statsmodels": _pkg_version("statsmodels"),136            "arch": _pkg_version("arch"),137        },138        "git": _git_commit(),139    }140    return manifest141142143if __name__ == "__main__":144    print(json.dumps(collect_manifest(), indent=2))145