Repository navigation
Description
Context
The JAX-native posterior sampler wave validated a gradient SMC prototype on the autolens_workspace_developer branch feature/blackjax-smc-gradient-kernel (searches_minimal/blackjax_smc_grad.py, _warm_start.py, smc_gradient_findings.md). Warm-started it samples: acceptance 0.80 → 0.17 across the tempering path, einstein_radius 1.5998 against a truth of 1.6, and all three warm arms' log Z bracket the Nautilus bar within ±0.8 nats — a gradient sampler that also yields the evidence.
That prototype lives in a workspace script. It has to become a first-class PyAutoFit search (af.SMC) before the profiling workspace can build an SMC cell and put SMC runs on the A100.
Prompt: PyAutoMind/active/blackjax_smc_search.md. Rung 2 of the overflow-flood fix wave (rung 1 is #1543).
High-level plan
- Add
af.SMC, a BlackJAX adaptive tempered SMC search with a gradient inner kernel (MALA by default, HMC optional), sitting beside the existingaf.BlackJAXNUTSunderautofit/non_linear/search/mcmc/blackjax/. - Sample in a whitened space. Warm-started, whiten by the Cholesky factor of a previous result's full covariance (prior-whitening does not whiten the posterior — 269× anisotropy measured); cold, whiten by the prior's per-parameter quantile width.
- Keep SMC's free log-evidence valid under a warm start by tempering from a normalised Gaussian reference rather than dropping particles at the MLE: λ still starts at 0, and the bridge weight restores the true
log Z. - Scale the inner-kernel step to the posterior width, honouring MALA's squared-length
step_size. No per-temperature kernel adaptation in this wave — it collapses acceptance (phase-0 finding). - Record the λ schedule, per-step acceptance and ESS in
search_internalso a run is judged by the acceptance trace, never by "tempering reached λ=1". - Test the evidence against an analytic Gaussian target, plus warm/cold/test-mode shape contracts; add the docs autosummary entry and a release-notes feature entry.
Detailed plan
New package autofit/non_linear/search/mcmc/blackjax/smc/:
search.py—class SMC(AbstractMCMC),__identifier_fields__ = ("num_particles", "kernel", "num_mcmc_steps", "target_ess", "inverse_mass_matrix").__init__(num_particles=256, kernel="mala", num_mcmc_steps=5, num_integration_steps=8, target_ess=0.5, step_size=None, whiten_inflate=2.0, max_smc_steps=200, seed=42, initializer=None, inverse_mass_matrix=None, ...). Default initializer isInitializerPrior()(cold SMC's evidence requires particles drawn from the prior — theAbstractMCMCInitializerBalldefault would silently invalidate it)._fit: refuses a non-JAXAnalysis(same message shape asBlackJAXNUTS); buildsFitness(fom_is_log_likelihood=True); draws start points viainitializer.samples_from_model; resolves whitening viachains.resolve_inverse_mass_matrix; assemblesblackjax.adaptive_tempered_smcwith a MALA/HMC inner kernel; runs the tempering loop in Python, callingperform_updateon theiterations_per_full_updatechunk boundary and picklingsearch_internaleach step.- Cold path:
logprior_fn = Σ log_prior_from_value(x(z)),loglikelihood_fn = fitness.call(x(z));log Z = Σ log_likelihood_increment(the SMC estimator is a ratio, so the whitening Jacobian and the prior normalisation cancel). - Warm path (whitening spec given):
logprior_fn = log N(0, I)(z),loglikelihood_fn = log prior_normalised + log L − log g;log Z = Σ increments + log|det L|. apply_test_modeshrinks tonum_particles<=16,num_mcmc_steps=2,max_smc_steps=5.samples_info_from/samples_via_internal_frommirror the NUTS pattern; particles at λ=1 carry their normalised tempered weights.
samples.py—SamplesSMC(SamplesMCMC)overridinglog_evidenceto readsamples_info["log_evidence"](SamplesMCMC.log_evidenceisNone).
Shared/edited:
autofit/__init__.py—"SMC"in_LAZY_ATTRS.docs/api/searches.rst—SMC(andBlackJAXNUTS) under the MCMC autosummary.docs/release_notes.md(or the repo's notes file) — new-feature entry.
Tests — test_autofit/non_linear/search/mcmc/test_blackjax_smc.py, following test_blackjax_nuts.py's requires_blackjax skipif so the no-extras matrix leg stays green:
- explicit-params / identifier-fields / test-mode construction tests (no jax needed).
_build_search_internalshape contract (pure numpy).- End-to-end Gaussian target: uniform priors, a JAX-traceable Gaussian likelihood; assert the recovered
log_evidenceis within 0.1 nat of0.5·d·log(2π) + d·log σ − Σ log(b−a), for both a cold run and a warm run seeded with an explicit covariance.
Trade-offs / risks: no per-temperature step adaptation (measured to collapse acceptance); the cold auto step targets a fixed fraction of the prior width, matching the prototype default, and cold runs on a sharply peaked likelihood are documented as not the representative regime. The config/non_linear/mcmc/SMC.yaml item in the wave plan is dropped: PyAutoFit #1202 replaced per-search YAML with explicit Python defaults, and BlackJAXNUTS carries no YAML either.
Branch: feature/blackjax-smc-search
Activity
Jammy2211 commentedon Aug 29, 2026
Library PR Created
PR: #1546 (
feature/blackjax-smc-search, commitb1e3b02, labelpending-release)CI: all four legs green —
unittest (3.12)pass,unittest (3.13)pass,unittest-nojaxpass,docs / docs-buildpass.What landed
af.SMC— a BlackJAX adaptive tempered SMC search with a MALA (default) or HMC gradient inner kernel, plusSamplesSMC. Lazily exported via_LAZY_ATTRS, so nothing at import time pulls jax or blackjax.The evidence is asserted against a closed form (isotropic Gaussian likelihood under
Uniform(-5, 5)priors, analyticlog Z = −2.7673):All inside the 0.1-nat bar; the HMC arm reproduces the phase-0 finding that HMC holds acceptance where MALA's decays. Full suite 2336 passed / 3 skipped; Sphinx warning count 31, exactly the recorded baseline.
Deviation from the wave plan
The planned
config/non_linear/mcmc/SMC.yaml+search.yamlentry was dropped: that layout no longer exists — #1202 ("replace YAML config with explicit Python defaults in search classes") removed it, andBlackJAXNUTScarries no YAML either. Defaults are explicit Python arguments, mirroring the sibling search. Release-notes content is the PR's## API Changessection (PyAutoFit has no in-repo notes file).Downstream impact
Purely additive — no existing signature, default or behaviour changes, so no workspace migration is needed and no smoke test is implicated (nothing downstream calls
af.SMCyet). The workspace half is Wave B:build_smcinautolens_profiling's_samplers.py, thescripts/imaging/searches/smc/mge.pyleaf, and the A100 warmmala/hmcprobe — all gated on this merging and onHPCPullPyAutorefreshing the RAL stack.Ship gate
Heart readiness was YELLOW, not GREEN, on two pre-existing reasons unrelated to this change:
workspace validation not passing (0 failed, 1 timeout, cloud#33229145647: autolens_test scripts/multi_dataset/delaunay_mge.py)release validation incomplete: no rehearsal for current sourcePR-open only; merge is human (
/prm).Jammy2211 commentedon Aug 29, 2026
Shipped
Merged as PR #1546 (b70cf7f).
af.SMC— blackjax adaptive tempered SMC (mala/hmc inner kernel, no step adaptation by default, full-covariance whitening from a warm-start Result/Samples, prior-drawn cold start) withSamplesSMC(log_evidence, lambda/acceptance/ESS traces). Analytic Gaussian: cold −0.082 / warm −0.020 / hmc +0.014 nat. Profiling cell + A100 probe follow in autolens_profiling (Wave B).