From 54120ce2f35466b5a66eb30f7d9845aab34f059b Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 24 Nov 2026 17:26:41 +0000 Subject: [PATCH 1/2] Resume and verify the three conditional 30D evidence streams --- .../nautilus_30d_evidence_check/check.py | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 experiments/nautilus_30d_evidence_check/check.py diff --git a/experiments/nautilus_30d_evidence_check/check.py b/experiments/nautilus_30d_evidence_check/check.py new file mode 100644 index 0000000..9d2ce3a --- /dev/null +++ b/experiments/nautilus_30d_evidence_check/check.py @@ -0,0 +1,224 @@ +"""Complete three conditional 30D evidence streams from the hash-pinned local archives.""" + +import argparse +import json +import os +import shutil +import subprocess +import sys +import time +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / "scripts" / "misc")) + +from profiling.nautilus_diagnostics import discard_saved_exploration, estimate, fresh_counts, sha256 +from profiling.nautilus_manifest import RunConfig, fingerprint +from profiling.nautilus_resources import atomic_json, supervise + +EVIDENCE = ROOT / "experiments/nautilus_30d_diagnostics/evidence" +STREAMS = ("saved", "seed1", "seed2") +THREADS = ("OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS", "NUMEXPR_NUM_THREADS") +TIMEOUT_S = 1800 +MEMORY_BYTES = 4096 * 1024**2 + + +def load(path): + return json.loads(path.read_text()) + + +def records(): + plan = load(EVIDENCE / "plan.json") + case = next(row for row in plan["cases"] if row["id"] == "evidence-d30-rsaved") + return plan, case, load(EVIDENCE / "partial-checkpoint.json") + + +def check_sources(original, partial): + _, case, prior = records() + if ( + sha256(original) != case["checkpoint_sha256"] + or sha256(partial) != prior["checkpoint_sha256"] + ): + raise ValueError("The input checkpoint differs from its published hash") + + +def run_stream(original, partial, output, stream): + import numpy as np + from autofit.non_linear.search.nest.nautilus.search import _large_attribute_hdf5 + from nautilus import Sampler + from profiling.nautilus_target import CorrelatedGaussianTarget + + _, case, prior = records() + target = CorrelatedGaussianTarget(30) + if fingerprint(target.truth()) != case["target_sha256"]: + raise ValueError("Analytic target changed") + checkpoint = output / "checkpoint.hdf5" + if checkpoint.exists(): + raise FileExistsError(checkpoint) + shutil.copyfile(partial if stream == "saved" else original, checkpoint) + config = RunConfig(dimension=30, n_live=400, trace=False).constructor() + + def reopen(): + return Sampler(target.prior, target, filepath=str(checkpoint), **config) + + with _large_attribute_hdf5(): + sampler = reopen() + if stream == "saved": + discard_saved_exploration(sampler) + previous = prior["estimate"] + expected_digest = previous["posterior_sha256"] + expected_calls = previous["n_like"] + else: + expected_digest = case["original_posterior_sha256"] + expected_calls = case["original_n_like"] + if any(fresh_counts(sampler)): + raise ValueError("Original checkpoint already has fresh samples") + start = estimate(sampler, target) + if start["posterior_sha256"] != expected_digest or start["n_like"] != expected_calls: + raise ValueError("Starting posterior or likelihood count differs") + if stream != "saved": + seed = int(stream.removeprefix("seed")) + sampler.rng.bit_generator.state = np.random.default_rng(seed).bit_generator.state + discard_saved_exploration(sampler) + cuts = sampler.shell_end_exp.copy() + num_bounds = len(sampler.bounds) + if (sampler.n_update, sampler.n_live, sampler.n_batch, sampler.n_networks) != ( + 400, + 400, + 100, + 4, + ): + raise ValueError("Unexpected native sampler settings") + sampler.write(str(checkpoint), overwrite=True) + last = 0.0 + update = sampler.write_shell_update + + def persist(*args, **kwargs): + nonlocal last + update(*args, **kwargs) + now = time.monotonic() + if now - last >= 30: + atomic_json( + output / "progress.json", + {"n_like": int(sampler.n_like), "ess": float(sampler.n_eff)}, + ) + last = now + + with ( + patch.object(sampler, "add_bound", side_effect=RuntimeError("Learned bounds changed")), + patch.object(sampler, "write_shell_update", persist), + ): + converged = sampler.run( + n_eff=10000, n_shell=100, discard_exploration=True, verbose=False + ) + if not converged or sampler.n_eff < 10000 or min(fresh_counts(sampler)) < 100: + raise ValueError("Fresh-only stopping conditions failed") + final = estimate(sampler, target) + native = reopen() + check = estimate(native, target) + if ( + not native.discard_exploration + or len(native.bounds) != num_bounds + or not np.array_equal(native.shell_end_exp, cuts) + ): + raise ValueError("Bound count, exploration boundary or exclusion mode changed") + if final != check or sum(fresh_counts(native)) != native.n_like - case["original_n_like"]: + raise ValueError("Native checkpoint failed posterior, evidence or count verification") + atomic_json( + output / "complete.json", + { + "stream": stream, + "target_logZ": target.log_evidence, + "source_posterior_sha256": expected_digest, + "starting_n_like": expected_calls, + "additional_calls_this_run": final["n_like"] - expected_calls, + "bounds": num_bounds, + "native_reopen_exact": True, + "final": final, + }, + ) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + for name in ("original", "partial", "output"): + parser.add_argument(name, type=Path) + parser.add_argument("--child", choices=STREAMS) + args = parser.parse_args() + original, partial, output = (p.resolve() for p in (args.original, args.partial, args.output)) + if args.child: + run_stream(original, partial, output, args.child) + return + from profiling.nautilus_baseline import provenance + from profiling.nautilus_campaign import environment_key + + check_sources(original, partial) + plan, case, previous = records() + actual = environment_key(provenance()) + expected = plan["environment"] + for key in ("nautilus_source_sha256", "packages", "python"): + if actual[key] != expected[key]: + raise ValueError(f"Phase 0b.2 runtime mismatch: {key}") + for source in ("PyAutoFit", "PyAutoNerves"): + if actual["sources"][source] != expected["sources"][source]: + raise ValueError(f"Phase 0b.2 source mismatch: {source}") + output.mkdir(parents=True, exist_ok=False) + + def launch(stream): + folder = output / stream + folder.mkdir() + cmd = [ + sys.executable, + __file__, + str(original), + str(partial), + str(folder), + "--child", + stream, + ] + start = time.monotonic() + with (folder / "run.log").open("w") as log: + child = subprocess.Popen( + cmd, + env={**os.environ, **dict.fromkeys(THREADS, "1")}, + stdout=log, + stderr=subprocess.STDOUT, + start_new_session=True, + ) + receipt = supervise(child, TIMEOUT_S, MEMORY_BYTES, interval=0.5) + receipt["elapsed_s"] = time.monotonic() - start + atomic_json(folder / "supervision.json", receipt) + result = folder / "complete.json" + return { + "stream": stream, + "supervision": receipt, + "result": load(result) if result.exists() else None, + } + + with ThreadPoolExecutor(max_workers=3) as executor: + runs = list(executor.map(launch, STREAMS)) + check_sources(original, partial) + complete = all(row["supervision"]["returncode"] == 0 and row["result"] for row in runs) + atomic_json( + output / "result.json", + { + "status": "complete" if complete else "incomplete", + "original_sha256": case["checkpoint_sha256"], + "partial_sha256": previous["checkpoint_sha256"], + "inputs_unchanged": True, + "environment": actual, + "original_logZ_error": case["original_logZ_error"], + "prior_partial": previous["estimate"], + "timeout_s": TIMEOUT_S, + "memory_limit_bytes_per_child": MEMORY_BYTES, + "runs": runs, + }, + ) + if not complete: + raise SystemExit(1) + + +if __name__ == "__main__": + main() From 10c951cae4c875321048c6ab7841bca10e85896c Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 24 Nov 2026 17:45:47 +0000 Subject: [PATCH 2/2] Record and independently verify completed 30D evidence estimates --- .../nautilus_30d_evidence_check/README.md | 32 ++ .../nautilus_30d_evidence_check/result.json | 430 ++++++++++++++++++ .../verification.json | 26 ++ .../nautilus_30d_evidence_check/verify.py | 83 ++++ 4 files changed, 571 insertions(+) create mode 100644 experiments/nautilus_30d_evidence_check/README.md create mode 100644 experiments/nautilus_30d_evidence_check/result.json create mode 100644 experiments/nautilus_30d_evidence_check/verification.json create mode 100644 experiments/nautilus_30d_evidence_check/verify.py diff --git a/experiments/nautilus_30d_evidence_check/README.md b/experiments/nautilus_30d_evidence_check/README.md new file mode 100644 index 0000000..9b7a086 --- /dev/null +++ b/experiments/nautilus_30d_evidence_check/README.md @@ -0,0 +1,32 @@ +# 30D conditional evidence check + +All three planned resampling streams on the seed-0 learned bounds reached fresh-sample ESS 10,000. The analytic log evidence is -36.767688153. The original exploration-inclusive estimate had signed error -0.908090. The three completed fresh-only errors range from -0.048116 to -0.027755. Their mean is -0.034966 and their sample standard deviation is 0.011406. This spread describes repetitions on the same exploration. [Phase issue](https://github.com/PyAutoLabs/autofit_profiling/issues/30). + +| Resampling stream | Log evidence | Signed error | Relative evidence error | Fresh ESS | Fresh likelihood calls | Calls in this follow-up | Min fresh count per shell | Max standardized mean error | Relative covariance error | +|---|---:|---:|---:|---:|---:|---:|---:|---:|---:| +| saved | -36.796714 | -0.029026 | -2.86% | 10,001.1 | 980,300 | 861,400 | 200 | 0.0201 | 0.0384 | +| seed1 | -36.815804 | -0.048116 | -4.70% | 10,000.7 | 636,100 | 636,100 | 1000 | 0.0282 | 0.0433 | +| seed2 | -36.795443 | -0.027755 | -2.74% | 10,001.7 | 835,600 | 835,600 | 900 | 0.0182 | 0.0445 | + +Relative evidence error is `exp(estimated logZ − analytic logZ) − 1`. The mean diagnostic is the largest component error in analytic posterior standard deviations. The covariance diagnostic is the Frobenius norm of the error divided by that of the analytic covariance. + +## What changed + +The original seed-0 fit finished exploration with 34,100 likelihood calls and no subsequently sampled points. The earlier fresh-only attempt timed out at 120 seconds. Its last persisted copy had 118,900 fresh calls, ESS 2,633.6 and log-evidence error −0.049803. For the saved stream this follow-up copied that file, restored the exclusion flag, matched its archived ordered posterior hash and then wrote the corrected mode to the copy with native Nautilus. It resumed at 153,000 total calls. The other two streams used copies of the same original exploration and changed the shared RNG state before drawing fresh samples. The source checkpoints retained their original SHA-256 hashes. [Earlier protocol and timeout](../nautilus_30d_diagnostics/README.md). + +Every run used Nautilus 1.0.5, 400 live points, native bound cadence 400, batch size 100 and four neural networks. Exploration stayed closed. All learned bounds and their exploration cutoffs were retained. Each run stopped at ESS ≥10,000 with at least 100 fresh samples per shell. Each final checkpoint reopened directly with native Nautilus, reproducing the full ordered posterior hash, log evidence, ESS, moments and counts exactly. The independent reader checked the analytic answer in a covariance eigenbasis, reconstructed log evidence and ESS from the post-exploration likelihood rows and stored shell volumes, and re-evaluated one fresh sample in each shell. [Numerical checks](verification.json) · [Per-stream results and supervision](result.json). + +## Interpretation + +All three fresh-only estimates were low by 2.74–4.70% on the evidence scale. The original exploration-inclusive estimate was low by 59.67%. The three conditional runs specified by phase 0b.2 are complete. The comparison changes both sample selection and sample count. It cannot assign the original discrepancy uniquely to exploration reuse. Independent full-search seeds are needed to quantify variability from learning the bounds and to assess evidence uncertainty calibration. The protocol specified a stopping condition and an analytic comparison. It set no numerical accuracy acceptance band. Wider phase 0b remains open. + +## Reproduction + +Use the PyAutoFit and PyAutoNerves revisions, Nautilus source hash and scientific package versions in the receipt. Place the two source checkouts on PYTHONPATH and include this repository's scripts/misc. Use the original direct 30D `case-719639ab504cacbebb25-attempt-001/checkpoint.hdf5` and the retained `evidence-d30-rsaved/checkpoint.hdf5` from the earlier timeout. Their exact checksums are verified before and after the run. Reproducing the saved stream requires the retained partial binary. Local raw checkpoints are outside git. + +```sh +python experiments/nautilus_30d_evidence_check/check.py ORIGINAL.hdf5 PARTIAL.hdf5 FRESH_OUTPUT_DIRECTORY +python experiments/nautilus_30d_evidence_check/verify.py FRESH_OUTPUT_DIRECTORY +``` + +The three single-process children ran concurrently on the local CPU with one numerical thread each, a 1,800-second cap and 4 GiB sampled process-group RSS limit per child. Elapsed times are supervision records for this accuracy check. [Domain profiling task](https://github.com/PyAutoLabs/PyAutoPulse/blob/main/tasks/autofit_profiling_bootstrap.md). diff --git a/experiments/nautilus_30d_evidence_check/result.json b/experiments/nautilus_30d_evidence_check/result.json new file mode 100644 index 0000000..752da9d --- /dev/null +++ b/experiments/nautilus_30d_evidence_check/result.json @@ -0,0 +1,430 @@ +{ + "status": "complete", + "original_sha256": "4ceaaa063547ebf9a03d3f16c8c7cf376b965cf079e4a228f91ad9a00846172c", + "partial_sha256": "935dd45bf0b76696bf10f7a6d7d1c1a6bd16c73cb83f595695a31ea9b3c4ac86", + "inputs_unchanged": true, + "environment": { + "sources": { + "PyAutoFit": { + "revision": "bdb7af0e9c339ad07850679fd6ac168aacc7d18c", + "code_sha256": "9e566e1b1a259e279d2eaa86319556a78561183b347ac8835793a315d980ad75" + }, + "PyAutoNerves": { + "revision": "9b204c90c2ce05c5bb0cf3e9800ed13f005c6c56", + "code_sha256": "560c9250eb0d7f8f56b3d4d21f22b9e556e93fd0eba92b5b33860b903a2f3f0b" + }, + "producer": { + "revision": "54120ce2f35466b5a66eb30f7d9845aab34f059b", + "code_sha256": "ff02e9f32dad5f2619dfd4fc6021a8b184a33f5e3472668da0e0fdcc599557a7" + } + }, + "nautilus_source_sha256": "61e91f8fb85cf4a38877cd1c65bb0b111589bde77f5f74acb22a90f3ff2ec45c", + "packages": { + "numpy": "2.5.4", + "scipy": "1.17.1", + "scikit-learn": "1.9.1", + "h5py": "3.16.0", + "nautilus-sampler": "1.0.5", + "jax": "0.11.2", + "jaxlib": "0.11.2", + "threadpoolctl": "3.8.0" + }, + "distribution_versions": { + "networkx": "3.1", + "jsonpickle": "4.1.4", + "dynesty": "2.1.5", + "array-api-compat": "1.16.0", + "pyparsing": "3.3.3", + "pillow": "13.0.0", + "psutil": "6.1.0", + "cycler": "0.12.1", + "emcee": "3.1.6", + "jaxlib": "0.11.2", + "pure_eval": "0.2.4", + "six": "1.17.0", + "imagesize": "2.0.1", + "mypy_extensions": "1.2.0", + "joblib": "1.6.0", + "snowballstemmer": "3.1.1", + "urllib3": "2.8.0", + "prompt_toolkit": "3.0.53", + "nautilus-sampler": "1.0.5", + "ml_dtypes": "0.6.0", + "autofit": "9999.0.0.dev0", + "Pygments": "2.21.0", + "babel": "2.18.0", + "pluggy": "1.7.0", + "MarkupSafe": "3.0.4", + "traitlets": "5.16.1", + "roman-numerals": "4.1.0", + "corner": "2.2.2", + "typing_extensions": "4.16.0", + "sphinxcontrib-devhelp": "2.0.0", + "dill": "0.4.1", + "asttokens": "3.0.2", + "sphinxcontrib-serializinghtml": "2.0.0", + "optax": "0.2.8", + "matplotlib-inline": "0.2.2", + "threadpoolctl": "3.8.0", + "ipython": "9.12.0", + "ruff": "0.17.4", + "Sphinx": "9.1.1", + "typing-inspect": "0.9.0", + "jedi": "0.20.1", + "certifi": "2026.10.23", + "wheel": "0.48.0", + "parso": "0.8.7", + "contourpy": "1.4.0", + "anesthetic": "2.16.0", + "alabaster": "1.0.0", + "pyvis": "0.3.2", + "charset-normalizer": "3.5.2", + "numpydoc": "1.11.0", + "gprof2dot": "2021.2.21", + "timeout-decorator": "0.5.0", + "absl-py": "2.5.1", + "ipython_pygments_lexers": "1.1.1", + "fonttools": "4.68.0", + "sphinxcontrib-qthelp": "2.0.0", + "PyYAML": "6.0.3", + "sphinxcontrib-applehelp": "2.0.0", + "iniconfig": "2.3.1", + "sphinxcontrib-jsmath": "2.0.0", + "executing": "2.3.0", + "numpy": "2.5.4", + "sphinxcontrib-htmlhelp": "2.1.0", + "decorator": "5.3.1", + "xxhash": "3.4.1", + "jax": "0.11.2", + "scipy": "1.17.1", + "Jinja2": "3.1.6", + "pandas": "3.0.6", + "stack-data": "0.6.3", + "kiwisolver": "1.5.1", + "python-dateutil": "4.0.0", + "packaging": "26.3", + "cloudpickle": "3.1.2", + "opt_einsum": "3.4.0", + "scikit-learn": "1.9.1", + "jaxnnls": "1.0.1", + "pexpect": "4.9.0", + "requests": "2.34.2", + "autonerves": "9999.0.0.dev0", + "h5py": "3.16.0", + "ptyprocess": "0.7.0", + "greenlet": "3.5.6", + "docutils": "0.22.4", + "tzdata": "2026.6", + "wcwidth": "0.9.4", + "idna": "3.20", + "astunparse": "1.6.3", + "SQLAlchemy": "2.0.57", + "pytest": "9.2.0", + "narwhals": "2.28.0", + "matplotlib": "3.11.2" + }, + "python": "3.12.10 (main, Apr 9 2025, 08:55:05) [GCC 11.4.0]", + "host": "DESKTOP-H143S82", + "platform": "Linux-6.18.58.1-microsoft-standard-WSL2-x86_64-with-glibc2.35", + "affinity": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7 + ], + "thread_env": { + "OMP_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1" + } + }, + "original_logZ_error": -0.9080901865173772, + "prior_partial": { + "logZ": -36.817490772406956, + "logZ_error": -0.04980261903283889, + "n_eff": 2633.629718188204, + "posterior_sha256": "778d78b9614d75e2ce4f54b8dc109f5edcf46ac99a512432626a17a97dd0a8dd", + "n_like": 153000, + "selected_samples": 118900, + "fresh_samples_per_shell": [ + 100, + 200, + 18900, + 10000, + 15400, + 13300, + 10300, + 16600, + 10300, + 6500, + 4800, + 4000, + 2500, + 2000, + 1500, + 800, + 700, + 400, + 400, + 200 + ], + "max_standardized_mean_error": 0.04554579910075302, + "covariance_relative_error": 0.08604457112325922, + "shell_log_v": [ + -0.7227059828014897, + -1.2672229609620693, + -2.009821707593512, + -2.6283702299670995, + -3.3526410725951354, + -4.184621500053613, + -5.121088625439482, + -5.71959489120084, + -6.573303509917508, + -7.388578439334169, + -8.20680979650924, + -8.987898113914534, + -9.704712340402258, + -10.474668635525695, + -11.340456174446215, + -12.294179333612558, + -12.860142434488953, + -13.887815466313267, + -14.516179179954015, + -15.124524124405045 + ] + }, + "timeout_s": 1800, + "memory_limit_bytes_per_child": 4294967296, + "runs": [ + { + "stream": "saved", + "supervision": { + "returncode": 0, + "termination_reason": null, + "sampled_group_peak_rss_bytes": 1532112896, + "memory_limit_bytes": 4294967296, + "rss_sample_interval_s": 0.5, + "rss_note": "process group sum; shared pages may repeat; sub-interval spikes may be missed", + "elapsed_s": 977.5011662169964 + }, + "result": { + "stream": "saved", + "target_logZ": -36.76768815337412, + "source_posterior_sha256": "778d78b9614d75e2ce4f54b8dc109f5edcf46ac99a512432626a17a97dd0a8dd", + "starting_n_like": 153000, + "additional_calls_this_run": 861400, + "bounds": 20, + "native_reopen_exact": true, + "final": { + "logZ": -36.79671384488542, + "logZ_error": -0.029025691511300522, + "n_eff": 10001.056881946595, + "posterior_sha256": "0ff2542651dee2e73a13a0823fe314b61079497958650c9b6e7b4121fc8e4319", + "n_like": 1014400, + "selected_samples": 980300, + "fresh_samples_per_shell": [ + 200, + 292200, + 102900, + 113700, + 84000, + 64800, + 70300, + 72700, + 44800, + 38100, + 24400, + 20900, + 15200, + 13900, + 9200, + 4400, + 3600, + 1900, + 1800, + 1300 + ], + "max_standardized_mean_error": 0.0200703775311588, + "covariance_relative_error": 0.03835819862386014, + "shell_log_v": [ + -0.826366024346168, + -1.2683695709563523, + -2.00306464010474, + -2.630145786075562, + -3.3501122383088267, + -4.182713120548886, + -5.118108371650493, + -5.719420324855379, + -6.565102563509238, + -7.397010529860874, + -8.189852391284411, + -8.993215282084934, + -9.70691218750088, + -10.480858431764707, + -11.341493875996264, + -12.276430297782676, + -12.877806926985311, + -13.888008709521548, + -14.51038701364547, + -15.12887579327575 + ] + } + } + }, + { + "stream": "seed1", + "supervision": { + "returncode": 0, + "termination_reason": null, + "sampled_group_peak_rss_bytes": 1110700032, + "memory_limit_bytes": 4294967296, + "rss_sample_interval_s": 0.5, + "rss_note": "process group sum; shared pages may repeat; sub-interval spikes may be missed", + "elapsed_s": 530.7156183279985 + }, + "result": { + "stream": "seed1", + "target_logZ": -36.76768815337412, + "source_posterior_sha256": "a4234203f31abb988319385b0a5d92f0f57fbc10dbf23e0715e5906e146d499a", + "starting_n_like": 34100, + "additional_calls_this_run": 636100, + "bounds": 20, + "native_reopen_exact": true, + "final": { + "logZ": -36.81580433753688, + "logZ_error": -0.04811618416276531, + "n_eff": 10000.659382573207, + "posterior_sha256": "f75840a4e0700e3b54242ab95cdb0073da971ee9d4ba465fb7026c07f573209b", + "n_like": 670200, + "selected_samples": 636100, + "fresh_samples_per_shell": [ + 2300, + 98400, + 70800, + 55000, + 90500, + 57200, + 62300, + 53700, + 31000, + 31600, + 27300, + 17100, + 12500, + 10100, + 5800, + 3700, + 3000, + 1500, + 1300, + 1000 + ], + "max_standardized_mean_error": 0.028190629369649223, + "covariance_relative_error": 0.04332322694384097, + "shell_log_v": [ + -0.7717172325017744, + -1.2679299371769015, + -1.9970261272420948, + -2.619287923063982, + -3.3467061314433177, + -4.191178335430563, + -5.111711241173207, + -5.723712973579185, + -6.561135075612958, + -7.389949488216993, + -8.18435506953628, + -8.977846094627601, + -9.699957627435419, + -10.476602990399849, + -11.342439175279113, + -12.279608543698322, + -12.858677943208644, + -13.893458678163611, + -14.545474257025328, + -15.132308483778296 + ] + } + } + }, + { + "stream": "seed2", + "supervision": { + "returncode": 0, + "termination_reason": null, + "sampled_group_peak_rss_bytes": 1534345216, + "memory_limit_bytes": 4294967296, + "rss_sample_interval_s": 0.5, + "rss_note": "process group sum; shared pages may repeat; sub-interval spikes may be missed", + "elapsed_s": 788.4374694579965 + }, + "result": { + "stream": "seed2", + "target_logZ": -36.76768815337412, + "source_posterior_sha256": "a4234203f31abb988319385b0a5d92f0f57fbc10dbf23e0715e5906e146d499a", + "starting_n_like": 34100, + "additional_calls_this_run": 835600, + "bounds": 20, + "native_reopen_exact": true, + "final": { + "logZ": -36.79544326077416, + "logZ_error": -0.027755107400039947, + "n_eff": 10001.728781632424, + "posterior_sha256": "ec8a9e486114794e984ce5c8db2410a609ba5343d4969b453dce18fbba3eaa30", + "n_like": 869700, + "selected_samples": 835600, + "fresh_samples_per_shell": [ + 900, + 86800, + 109300, + 123700, + 120400, + 85600, + 66900, + 70800, + 47900, + 33700, + 23800, + 19900, + 16100, + 11000, + 6500, + 4200, + 3700, + 1800, + 1600, + 1000 + ], + "max_standardized_mean_error": 0.01820233249815626, + "covariance_relative_error": 0.04448833925330114, + "shell_log_v": [ + -0.8000065723415075, + -1.270038772095655, + -2.0030269442274102, + -2.6359108289097226, + -3.3506538738296157, + -4.186330501532915, + -5.111740533229652, + -5.715702818737994, + -6.561507362763209, + -7.396060225922298, + -8.190058705387436, + -8.97213000253128, + -9.69325129358172, + -10.484519927778171, + -11.337065359897798, + -12.278642118890598, + -12.872779538818447, + -13.875615183893206, + -14.519853318471842, + -15.124200309219752 + ] + } + } + } + ] +} \ No newline at end of file diff --git a/experiments/nautilus_30d_evidence_check/verification.json b/experiments/nautilus_30d_evidence_check/verification.json new file mode 100644 index 0000000..e5581a7 --- /dev/null +++ b/experiments/nautilus_30d_evidence_check/verification.json @@ -0,0 +1,26 @@ +{ + "analytic_logZ_eigenbasis": -36.76768815337412, + "streams": [ + { + "stream": "saved", + "fresh_rows": 980300, + "logZ": -36.79671384488542, + "ess": 10001.056881946492, + "max_shell_probe_log_likelihood_difference": 1.0658141036401503e-14 + }, + { + "stream": "seed1", + "fresh_rows": 636100, + "logZ": -36.81580433753688, + "ess": 10000.65938257323, + "max_shell_probe_log_likelihood_difference": 2.1316282072803006e-14 + }, + { + "stream": "seed2", + "fresh_rows": 835600, + "logZ": -36.79544326077416, + "ess": 10001.72878163248, + "max_shell_probe_log_likelihood_difference": 2.1316282072803006e-14 + } + ] +} diff --git a/experiments/nautilus_30d_evidence_check/verify.py b/experiments/nautilus_30d_evidence_check/verify.py new file mode 100644 index 0000000..b1839da --- /dev/null +++ b/experiments/nautilus_30d_evidence_check/verify.py @@ -0,0 +1,83 @@ +"""Independently check evidence and ESS from the completed HDF5 shell likelihoods.""" + +import argparse +import json +from pathlib import Path + +import h5py +import numpy as np +from scipy.special import logsumexp, ndtri + + +def verify(directory): + receipt = json.loads((directory / "result.json").read_text()) + if receipt["status"] != "complete" or [r["stream"] for r in receipt["runs"]] != [ + "saved", + "seed1", + "seed2", + ]: + raise ValueError("All three conditional streams are required") + dimension = 30 + axis = np.arange(dimension) + covariance = 0.6 ** abs(axis[:, None] - axis) + mean = np.linspace(-0.5, 0.5, dimension) + eigenvalues, vectors = np.linalg.eigh(covariance) + rotated = vectors.T @ mean + normalizer = dimension * np.log(2 * np.pi) + truth = -0.5 * ( + normalizer + np.log1p(eigenvalues).sum() + (rotated**2 / (1 + eigenvalues)).sum() + ) + results = [] + for row in receipt["runs"]: + measured = row["result"]["final"] + weights, max_likelihood_difference = [], 0.0 + with h5py.File(directory / row["stream"] / "checkpoint.hdf5", "r") as file: + group = file["sampler"] + if not group.attrs["_discard_exploration"]: + raise ValueError("Checkpoint includes exploration") + for i, (cut, volume) in enumerate( + zip(group.attrs["shell_end_exp"], group.attrs["shell_log_v"], strict=True) + ): + ll = group[f"log_l_{i}"][cut:] + if len(ll) < 100 or len(ll) != measured["fresh_samples_per_shell"][i]: + raise ValueError("Wrong fresh shell count") + weights.append(volume + ll - np.log(len(ll))) + # Re-evaluate a deterministic interior point of each fresh shell in a separate basis. + j = len(ll) // 2 + delta = ndtri(group[f"points_{i}"][cut + j]) - mean + value = -0.5 * ( + normalizer + + np.log(eigenvalues).sum() + + ((vectors.T @ delta) ** 2 / eigenvalues).sum() + ) + difference = abs(value - ll[j]) + if not np.isfinite(difference): + raise ValueError("Non-finite likelihood comparison") + max_likelihood_difference = max(max_likelihood_difference, difference) + log_weights = np.concatenate(weights) + log_z = float(logsumexp(log_weights)) + ess = float(np.exp(2 * log_z - logsumexp(2 * log_weights))) + if ( + len(log_weights) != measured["selected_samples"] + or abs(truth - row["result"]["target_logZ"]) > 1e-12 + or abs(log_z - measured["logZ"]) > 1e-10 + or abs(ess - measured["n_eff"]) > 1e-5 + or max_likelihood_difference > 1e-9 + ): + raise ValueError(f"Independent check failed for {row['stream']}") + results.append( + { + "stream": row["stream"], + "fresh_rows": len(log_weights), + "logZ": log_z, + "ess": ess, + "max_shell_probe_log_likelihood_difference": float(max_likelihood_difference), + } + ) + return {"analytic_logZ_eigenbasis": float(truth), "streams": results} + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("directory", type=Path) + print(json.dumps(verify(parser.parse_args().directory), indent=2, allow_nan=False))