Download server/src/check_environment.py from lylybig8/mdm_coverage: direct link, hf CLI and curl.
- Browser
- Download file 3.37 kB
-
https://huggingface.co/datasets/lylybig8/mdm_coverage/resolve/main/server/src/check_environment.py
- Command line
-
hf download hf://datasets/lylybig8/mdm_coverage/server/src/check_environment.py
-
curl -L -o check_environment.py https://huggingface.co/datasets/lylybig8/mdm_coverage/resolve/main/server/src/check_environment.py
3.37 kB
| """CPU environment and finite regression smoke checks, not research results.""" | |
| import hashlib | |
| import json | |
| import os | |
| from pathlib import Path | |
| import platform | |
| import subprocess | |
| import sys | |
| for key in ("OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS"): | |
| os.environ[key] = "1" | |
| os.environ["MPLBACKEND"] = "Agg" | |
| import numpy as np | |
| import scipy | |
| from scipy.optimize import linprog | |
| from scipy.stats import binom | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| from matplotlib import pyplot as plt | |
| def main(): | |
| project = Path(__file__).resolve().parents[1] | |
| pmf = binom.pmf(np.arange(129), 128, 0.25) | |
| np.testing.assert_allclose(pmf.sum(), 1.0, atol=1e-12, rtol=0) | |
| np.testing.assert_allclose(pmf @ np.arange(129), 32.0, atol=1e-11, rtol=0) | |
| # Two allowed actions for one fair pair: serial mismatch mean 1/8, or | |
| # co-sampled mismatch mean 1/2. Hidden mixing can match target mean 1/4. | |
| # Variables: serial weight, co-sample weight, absolute discrepancy. | |
| lp = linprog( | |
| c=[0.0, 0.0, 1.0], | |
| A_ub=[[0.125, 0.5, -1.0], [-0.125, -0.5, -1.0]], | |
| b_ub=[0.25, -0.25], | |
| A_eq=[[1.0, 1.0, 0.0]], b_eq=[1.0], | |
| bounds=[(0, None), (0, None), (0, None)], method="highs", | |
| ) | |
| if not lp.success: | |
| raise RuntimeError(lp.message) | |
| np.testing.assert_allclose(lp.fun, 0.0, atol=1e-9, rtol=0) | |
| np.testing.assert_allclose(lp.x[:2], [2 / 3, 1 / 3], atol=1e-9, rtol=0) | |
| fig, ax = plt.subplots() | |
| ax.plot(np.arange(129), pmf) | |
| fig.canvas.draw() | |
| plt.close(fig) | |
| checker = project / "src" / "verify_main_examples.py" | |
| completed = subprocess.run( | |
| [sys.executable, str(checker)], check=True, capture_output=True, | |
| text=True, timeout=180, | |
| ) | |
| regression = json.loads(completed.stdout) | |
| if regression.get("status") != "PASS": | |
| raise RuntimeError(regression) | |
| record = { | |
| "status": "PASS", | |
| "scope": "CPU environment and finite regression checks only; no main experiments run", | |
| "python_executable": sys.executable, | |
| "python_version": platform.python_version(), | |
| "platform": platform.platform(), | |
| "hostname": platform.node(), | |
| "packages": {"numpy": np.__version__, "scipy": scipy.__version__, | |
| "matplotlib": matplotlib.__version__}, | |
| "environment_mode": "project venv sharing existing Conda base site-packages", | |
| "visible_cpu_count": os.cpu_count(), | |
| "gpu_used": False, | |
| "library_thread_settings": {key: os.environ[key] for key in | |
| ("OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS")}, | |
| "binomial_mass_residual": float(abs(pmf.sum() - 1)), | |
| "highs_randomization_smoke": { | |
| "objective": float(lp.fun), "weights": lp.x[:2].tolist(), | |
| "equality_residual": float(np.max(np.abs(lp.eqlin.residual))), | |
| "scope": "two-action LP only, not a general policy optimizer", | |
| }, | |
| "headless_plotting": "PASS (canvas only; no publication figure generated)", | |
| "finite_regression": regression, | |
| "finite_regression_sha256": hashlib.sha256(checker.read_bytes()).hexdigest(), | |
| } | |
| output = project / "logs" / "environment_check.json" | |
| output.write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(record, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |