Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions experiments/nautilus_30d_evidence_check/README.md
Original file line number Diff line number Diff line change
@@ -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).
224 changes: 224 additions & 0 deletions experiments/nautilus_30d_evidence_check/check.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading