Skip to content

refactor: Dynesty, BlackJAX NUTS, SMC onto run(ctx) (search-ext A5 PR 2/4) - #1690

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/search-ext-a5-nest-blackjax
Oct 15, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/search-ext-a5-nest-blackjax

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Search-extensibility phase A5 (library), PR 2 of 4 (stacked on #1689; merge in order): DynestyStatic, DynestyDynamic (pooled and single-core), BlackJAXNUTS and SMC move from _fit onto run(ctx). Part of #1688.

  • AbstractDynesty.run replaces _fit: the bridge builds the same Fitness (Dynesty already resolved it through execution_settings), ctx.pool.number_of_cores / ctx.pool.is_jax replace the per-fit factory reads, and mid-run updates go through ctx.update (Dynesty's resume state is its native savestate.save, so the update's save is a no-op). _sampler_kwargs() and the A4 rstate precedence are untouched.
  • Pooled Dynesty: the ForkPool now takes its workers from the fit's PoolFactory (ctx.pool(njobs, initializer=..., initargs=...)) instead of calling fork_context().Pool itself, so the JAX fork rule and the context's pool shutdown apply to it and PoolFactory is the only pool source. The RuntimeError-on-creation fallback to single core is unchanged. Decision flagged (_fork_pool_cls now takes the factory).
  • Dynesty keeps the search's own start_points helper for its live points: it needs the unit-cube points and no start-point plot, which ctx.start_points (frozen return shape) does not give. Decision flagged.
  • BlackJAXNUTS.run / SMC.run: start points from ctx.start_points, chunk sizes from ctx.schedule, updates through ctx.update; the per-chunk pickle archive (output_search_internal) stays; the JAX REQUIRED gate is the bridge's. backend_seed (legacy 42, grid child_seed) unchanged.
  • Test fix in this PR: test_fork_context.py builds the fork-pinned dynesty pool from a PoolFactory (779f64a).

API Changes

None — internal changes only (_fork_pool_cls(pools) is private).
See full details below.

Test Plan

  • Full suite, serial: 3787 passed, 1 skipped, 0 xfailed (first run 3786 + 1 failed: test_fork_context.py called _fork_pool_cls() without the factory; fixed in 779f64a, then re-run)
  • unittest-nojax emulation: 3470 passed, 180 skipped
  • python docs/_generate_searches.py --check: clean · Sphinx: 30 warnings (baseline 30)
  • 15-search invariants (identifier, hash_list, to_dict, constructor-argument set, __identifier_fields__, MRO) vs main df6d218: byte-identical for all 15
  • Seeded byte-identity (seed=1, gaussian_x1, samples.csv vs main df6d218): DynestyStatic IDENTICAL (also with iterations_per_full_update=1000), DynestyDynamic IDENTICAL, BlackJAXNUTS IDENTICAL (also chunked, iterations_per_full_update=40), SMC IDENTICAL. Pooled DynestyStatic (number_of_cores=2) is not reproducible on main itself (two main runs differ); the branch's pooled runs complete through the PoolFactory-built pool.
  • autofit_workspace_test/scripts/searches/{DynestyStatic,DynestyDynamic,Dynesty_jax,BlackJAXNUTS,SMC}.py at PYAUTO_TEST_MODE=1 and =2: 4/5 pass on both modes, the same pass set as main (BlackJAXNUTS.py fails identically on main: its "unexpected divergences" assertion under the reduced budget)
  • pyauto-heart smoke autofit autolens on this head: rc 0, 53 PASS, 0 FAIL
Full API Changes (for automation & release notes)

Changed Behaviour

  • None intended. AbstractDynesty, BlackJAXNUTS, SMC no longer override _fit.
  • Pooled Dynesty logs one extra ...using pool INFO line per pool (the PoolFactory log).

Changed Signature (private)

  • autofit.non_linear.search.nest.dynesty.search.abstract._fork_pool_cls() → _fork_pool_cls(pools).

Companion changes required

None beyond the A5 consumers task (search_ext_a5_consumers.md). No public symbol changed.

Validation checklist (--auto run — plan was not pre-approved)

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits October 14, 2026 15:48
… PR 2)

DynestyStatic/DynestyDynamic (via AbstractDynesty), BlackJAXNUTS and SMC
replace their _fit overrides with run(ctx) on the A2 bridge: the Fitness
comes from the bridge (Dynesty's compile override was already resolved
through execution_settings), start points from ctx.start_points (Dynesty
keeps the search's start_points helper because it needs unit-cube live
points without a start-point plot), chunk sizes from
ctx.schedule.next_budget and mid-run updates through ctx.update. The
bridge runs the JAX REQUIRED gate for NUTS/SMC.

dynesty's ForkPool now takes its worker pool from the fit's PoolFactory
(ctx.pool(n, initializer=..., initargs=...)), so the JAX fork rule and the
context's pool shutdown apply to it; the pool-creation RuntimeError
fallback, _sampler_kwargs and the rstate precedence are unchanged. The
NUTS/SMC backend_seed (legacy 42, child_seed) is unchanged.

Seeded samples.csv byte-identical to main df6d218 for DynestyStatic,
DynestyDynamic, BlackJAXNUTS and SMC (also chunked).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_fork_pool_cls now takes the fit's PoolFactory; the worker-shape test
builds one and checks the pool came from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added pending-release PR queued for the next release build decision-taken labels Oct 14, 2026
Base automatically changed from feature/search-ext-a5-library to main October 15, 2026 12:21
@Jammy2211
Jammy2211 merged commit 850d773 into main Oct 15, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/search-ext-a5-nest-blackjax branch October 15, 2026 12:21
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant