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,84 @@
|
||||
"""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 / "local_stress_observable_v1.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() == "0e2777990359a7cf2bb29884173b7b01de37c49bcf49e1f29fc59fe83d62b456"
|
||||
assert hashlib.sha256(reference.read_bytes()).hexdigest() == "bba2a06a9f6517b32079ffff15e4060d8c3b7ed35f16ca134e1877226c9e4e1e"
|
||||
input_hashes = {'local_stress_observable_v1.py': '0e2777990359a7cf2bb29884173b7b01de37c49bcf49e1f29fc59fe83d62b456', 'stdout_local_stress_observable_v1.txt': '6a826e5ad729ce45af6879a07a1c659d8b4a21403fde5b9c6d9696cc6a5b09d4', 'TABLE_local_stress_observable_v1.md': 'd8ff0568d9c473a4bb09396a8948ddc8dc5af2f0f3a23ac84d238814fc779501', 'source_manifest.json': 'd2cf90b73458f493c665c9a281d06aef0c190cf0d143639fb77ab838c78f020c'}
|
||||
for name, digest in input_hashes.items():
|
||||
path = (base if name.endswith(".py") else evidence) / name
|
||||
assert hashlib.sha256(path.read_bytes()).hexdigest() == digest, name
|
||||
archive_path = Path("/tmp/celerislab-local-stress-input-20261013-0e277799.tar")
|
||||
archive_sha = "5834b23711496beb152188df5f47ff8175baf7e52543774401bd2c1183433eed"
|
||||
assert hashlib.sha256(archive_path.read_bytes()).hexdigest() == archive_sha
|
||||
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()},
|
||||
"input_hashes_verified_before_execution": input_hashes,
|
||||
"archive_sha256_verified_before_execution": archive_sha,
|
||||
"reference_sha256_verified_before_execution": hashlib.sha256(reference.read_bytes()).hexdigest(),
|
||||
"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