Preserve bounded validation evidence and historical failures
This commit is contained in:
1 parent
cdbb9c42f6
commit
263f3b0c7a
239 files changed
+74191
No files matched your search
@@ -0,0 +1,74 @@
|
||||
"""Bounded execution recorder; refuses to overwrite evidence or repeat a run."""
|
||||
import datetime
|
||||
import hashlib
|
||||
import importlib.metadata
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import resource
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
evidence = Path(__file__).resolve().parent
|
||||
base = evidence.parent
|
||||
script = base / "shear_diagnostic_v0_2.py"
|
||||
reference = base / "cpu_reference.py"
|
||||
expected_env = {
|
||||
"OPENBLAS_NUM_THREADS": "1",
|
||||
"PYTHONDONTWRITEBYTECODE": "1",
|
||||
"PYTHONNOUSERSITE": "1",
|
||||
"PYTHONOPTIMIZE": "0",
|
||||
"PYTHONPATH": str(base),
|
||||
"CPU_REFERENCE_PATH": str(reference),
|
||||
}
|
||||
limits = {
|
||||
"address_space_bytes": (resource.RLIMIT_AS, 268435456),
|
||||
"output_file_bytes": (resource.RLIMIT_FSIZE, 2097152),
|
||||
"core_bytes": (resource.RLIMIT_CORE, 0),
|
||||
}
|
||||
assert all(os.environ.get(k) == v for k, v in expected_env.items())
|
||||
assert all(resource.getrlimit(key) == (value, value) for key, value in limits.values())
|
||||
assert sys.executable == "/home/frank14f/anaconda3/envs/pycuda_3_10/bin/python"
|
||||
assert hashlib.sha256(script.read_bytes()).hexdigest() == "a8b1cf2f7abd00efc4d068bbd27bb2317144a6ca4c545d9b2e0dcf421eadebc6"
|
||||
assert hashlib.sha256(reference.read_bytes()).hexdigest() == "bba2a06a9f6517b32079ffff15e4060d8c3b7ed35f16ca134e1877226c9e4e1e"
|
||||
log_path = evidence / "stdout_horsea.txt"
|
||||
result_path = evidence / "results_horsea.json"
|
||||
assert not log_path.exists() and not result_path.exists(), "Existing execution evidence; do not rerun"
|
||||
prefix = ["/usr/bin/prlimit", "--as=268435456", "--fsize=2097152", "--core=0", "--", sys.executable, "-B"]
|
||||
command = prefix + [str(script)]
|
||||
report = {
|
||||
"started_utc": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
||||
"cwd": str(base),
|
||||
"parent_command": ["env"] + [f"{k}={v}" for k, v in expected_env.items()] + prefix + [str(Path(__file__).resolve())],
|
||||
"script_command": command,
|
||||
"environment": expected_env,
|
||||
"python_version": sys.version,
|
||||
"numpy_version_from_installed_metadata": importlib.metadata.version("numpy"),
|
||||
"platform": platform.platform(),
|
||||
"hard_limits": {name: resource.getrlimit(key) for name, (key, _) in limits.items()},
|
||||
"planned_runs": 7,
|
||||
"coarse_steps_per_run": 32,
|
||||
"attempt": 1,
|
||||
}
|
||||
with log_path.open("xb", buffering=0) as log:
|
||||
log.write(("RECORDER " + json.dumps(report) + "\nCOMMAND " + shlex.join(command) + "\n").encode())
|
||||
start = time.monotonic()
|
||||
child = subprocess.run(command, cwd=base, stdout=log, stderr=subprocess.STDOUT, check=False)
|
||||
report.update(
|
||||
returncode=child.returncode,
|
||||
elapsed_seconds=time.monotonic() - start,
|
||||
child_peak_rss_MiB=resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss / 1024,
|
||||
parent_peak_rss_MiB=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024,
|
||||
completed_utc=datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
||||
)
|
||||
log.write(("\nRUN_RESULT " + json.dumps(report) + "\n").encode())
|
||||
report["stdout_bytes"] = log_path.stat().st_size
|
||||
with result_path.open("x") as result:
|
||||
json.dump(report, result, indent=2)
|
||||
result.write("\n")
|
||||
print(json.dumps(report, indent=2))
|
||||
assert report["stdout_bytes"] < 2097152
|
||||
sys.exit(child.returncode if child.returncode >= 0 else 1)
|
||||
Reference in new issue
Block a user