Skip to content

refactor: A4c family bases out of the MRO (deprecated thin subclasses, per-posterior_kind defaults and plotter) - #1687

Merged
Jammy2211 merged 5 commits into
mainfrom
feature/search-ext-a4-family-bases
Oct 14, 2026
Merged

Jammy2211 merged 5 commits into
mainfrom
feature/search-ext-a4-family-bases

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Search-extensibility phase A4c (PR 3 of 3, stacked on #1686, which is stacked on #1685). It applies decision D14:

  • AbstractMCMC / AbstractNest / AbstractMLE are no longer in any public search's MRO. Their modules still export them as distinct deprecated thin subclasses of NonLinearSearch. These keep the former defaults and plots, and warn (FutureWarning) via __init_subclass__ when subclassed. They will be removed one release later.
  • Initializer, clipper and auto-correlation defaults now live in per-posterior_kind default objects (autofit/non_linear/search/posterior_kind.py: CHAIN, WEIGHTED, POINT). Each concrete __init__ applies them; NonLinearSearch never does.
  • The plotter is chosen per posterior_kind: NonLinearSearch.plot_results dispatches on it, replacing the family plot_results.
  • SMC is a weighted search with evidence and drops auto_correlation_settings. An old search.json carrying it still loads. The module stays at mcmc/blackjax/smc/. AbstractDynesty stays as shared backend code.

Closes #1684

What changed, by sub-step

  1. Per-kind defaults and plotter (d92529b2a).
    • CHAIN: InitializerBall(0.49, 0.51), AutoCorrelationsSettings built at construction, the cornerpy corner plot once pdf_converged, plots_search.mcmc.
    • WEIGHTED: InitializerPrior, nested_initializer_for (still rejects InitializerParamBounds for nested samplers), the anesthetic corner plot, plots_search.nest.
    • POINT: InitializerBall, ClipperNone, the parameter / log-likelihood / figure-of-merit traces, plots_search.mle.
    • plot_results lives in search/updates.py. A search with no posterior_kind still raises NotImplementedError, as before.
  2. Deprecated thin family bases (0f2f1dbca). Each has the same constructor signature and defaults as before, plus its samples_cls (SamplesMCMC / SamplesNest) and its kind's plot. deprecated_family.warn_family_subclass emits the FutureWarning and points to the replacement.
  3. Re-parenting (756713ba7):
    • Emcee, Zeus and BlackJAXNUTS subclass NonLinearSearch with samples_cls = SamplesMCMC and CHAIN defaults.
    • AbstractDynesty and Nautilus use samples_cls = SamplesNest; they, NSS and SMC take WEIGHTED defaults, and Dynesty, Nautilus and NSS still reject bounded initializers.
    • AbstractBFGS, AbstractMultiStartGradient and Drawer take POINT defaults. BFGS and MultiStart keep "clipper" in __identifier_fields__.
  4. Tests (946835f2a).
    • test_family_bases.py.
    • The conformance test_family_base now asserts the public searches are not family subclasses and checks their posterior_kind.
    • The strict-xfailed test_default_auto_correlation_settings_follow_run_time_test_mode is repaired. Chain defaults are built at construction, so a run-time PYAUTO_TEST_MODE reaches check_size, and the Emcee stand-in constructor argument in layer (ii) is removed. SMC leaves that test because it is not a chain.

Invariants

# Invariant Evidence
1 Public names / af. exports unchanged. The family bases were never af. exports and are still importable from their modules
2 Identifier hashes golden table: all 15 identifiers, hash_lists and __identifier_fields__ byte-identical to PR 2 and therefore to main for default constructions (scripted dump + test_identifier_golden, test_seed.py)
3 search.json, serialized constructor-argument sets autonerves.dictable.get_arguments(cls) and af.to_dict(cls()) are identical to PR 2 for 14 of 15 searches. The exception is SMC, which loses auto_correlation_settings as the spec requires. test_search_json_round_trip passes for all 15. An old SMC search.json with auto_correlation_settings loads without an unknown-kwarg warning (test_old_smc_search_json_with_auto_correlation_settings_loads)
4 On-disk layout unchanged
5 samples_info["class_path"] every search's samples_cls path equals main's (test_samples_class_path_unchanged, all 15)
6 #1493 clipper tripwire test_nested_samplers_have_no_clipper, test_clipper_forks_mle_identifier, test_drawer_identifier_ignores_clipper pass. The clipper is applied by POINT in the point searches' __init__ only
7 NonLinearSearch is an AbstractFactorOptimiser unchanged (test_search_is_still_a_factor_optimiser)
8 External subclasses keep working one release the deprecated bases keep their defaults (test_deprecated_{mcmc,nest,mle}_keeps_its_defaults). The developer-tier searches import, construct and fit (see Witness)
9 Result one class untouched

Witness

  • Subclassing a deprecated family base warns: test_subclassing_a_deprecated_family_base_warns covers all three. Constructing any of the 15 public searches raises no FutureWarning.
  • Serialized constructor-argument sets (dictable.py) match PR 2, apart from SMC as above. search.json round-trips.
  • samples_info["class_path"] is unchanged for all 15 searches.
  • Developer-tier searches, run in a throwaway script against this branch, reading the canonical autofit_workspace_developer through the symlink without editing it. autofit_workspace_developer/searches/nss/ no longer exists (NSS was promoted into the library), so two external searches remain:
    • pyswarms/{abstract,globe,local}.py (AbstractPySwarms(AbstractMLE)): imports with the FutureWarning, constructs with InitializerBall + ClipperNone, and fits at PYAUTO_TEST_MODE=1 (real PySwarms run) and =2.
    • ultranest/search.py (UltraNest(AbstractNest)): imports with the FutureWarning, constructs with InitializerPrior + SamplesNest, and fits at PYAUTO_TEST_MODE=2. At =1 the UltraNest backend fails with ImportError: numpy.core.multiarray failed to import. This is an environment problem (the installed ultranest wheel is built against an older numpy) and fails identically on main 8437a3b.

Tests

  • Full suite, serial: 3750 passed, 1 skipped, 0 xfailed. All four former strict xfails are resolved: three repaired, and the SMC case removed because SMC is not a chain.
  • unittest-nojax emulation: 3438 passed, 175 skipped.
  • Sphinx: 30 warnings. The same set as before this stack. _generate_searches.py --check: up to date.
  • Workspace smoke (pyauto-heart smoke autofit autolens, worktree source, this branch includes PR 2's seed and initializer changes): autofit_workspace 8/8 scripts + 2/2 notebooks pass, and autolens_workspace 41/41 scripts + 2/2 notebooks pass.
  • autofit_workspace_test scripts/searches + scripts/graphical: 25/32 at PYAUTO_TEST_MODE=1, 23/32 at =2. The failing scripts are the same set as on main 8437a3b and PR 1: real-search assertions not meant for test mode.
    • graphical/ep_parity.py first failed at level 1 in this run. The cause was a stale level-2 bypass output left by an earlier run, which loaded as "Fit Already Completed". With its output folder cleared it passes.

Decisions taken

  • Drawer names clipper explicitly in its signature. It used to receive clipper from AbstractMLE, so search.json recorded it. Naming it keeps Drawer's serialized argument set and search.json identical. It is not an identifier field, so feat: put the clipper in the search identifier (MLE searches only) #1493 still holds. The conformance golden constructor_arguments for Drawer gains clipper, and SMC's loses auto_correlation_settings. These are the only two signature changes.
  • Chain auto-correlation defaults are None in the signatures (Emcee, Zeus, BlackJAXNUTS) and are built at construction. NUTS keeps check_for_convergence=False. Values and search.json are unchanged outside test mode. This is what repairs the run-time test-mode xfail.
  • SMC plots with the weighted (anesthetic) plotter under plots_search.nest. It used to use the cornerpy chain plot gated on pdf_converged.
  • Nested samplers take initializer from **kwargs. Their signatures never named it; it reached AbstractNest through kwargs. They pass it through WEIGHTED.nested_initializer_for, so InitializerParamBounds is still rejected.
  • The deprecation warning is a FutureWarning (visible to end users, like the deprecated JAX knobs) with stacklevel=3.
  • The family grouping (mcmc / nest / mle) remains as the registry's documentation field and the roster family.

Companion changes required

Shipped separately by the main session. None of these is required for this PR's tests.

  1. PyAutoBrain skills/sampler_pipeline/reference.md, lines 129–133. Replace "subclass of the group abstract (AbstractNest / AbstractMCMC / AbstractMLE) … an is_test_mode short-circuit" with: "subclass of autofit.NonLinearSearch. Declare the static capabilities (posterior_kind = PosteriorKind.WEIGHTED | CHAIN | POINT, test_mode_budget = {...}, …) and apply that kind's defaults in __init__ from autofit.non_linear.search.posterior_kind (initializer=WEIGHTED.nested_initializer_for(initializer), self.clipper = POINT.clipper_for(clipper), self.auto_correlation_settings = CHAIN.auto_correlation_settings_for(...)). Set samples_cls. Implement run(ctx) + raw_samples_from (docs/design/run_ctx.md) rather than _fit. The test-mode reduction comes from test_mode_budget through the post-init hook, so do not call apply_test_mode in __init__ and do not add an is_test_mode short-circuit. The search-level seed is inherited; do not add a seed kwarg unless the backend needs it as a static identifier field." Line 136 ("NSSamples(SamplesNest) … when the group abstract does the heavy lifting") should become "… ~25 lines on top of SamplesNest".
  2. autofit_workspace_developer/searches/ultranest/search.py:
    • Change the import from autofit.non_linear.search.nest import abstract_nest and class UltraNest(abstract_nest.AbstractNest) to from autofit.non_linear.search.abstract_search import NonLinearSearch, from autofit.non_linear.search.posterior_kind import WEIGHTED, from autofit.non_linear.search import capabilities as cap and class UltraNest(NonLinearSearch).
    • Add samples_cls = SamplesNest and posterior_kind = cap.PosteriorKind.WEIGHTED (and produces_evidence = True).
    • Pass initializer=WEIGHTED.nested_initializer_for(kwargs.pop("initializer", None)) to super().__init__.
    • Replace the if is_test_mode(): self.apply_test_mode() tail (:152) and the apply_test_mode override (:157) with a class attribute test_mode_budget = {"max_iters": 1, "max_ncalls": 1}. With the current code the reduction runs twice (tail + post-init hook), which is harmless but redundant.
  3. autofit_workspace_developer/searches/pyswarms/abstract.py:
    • Change from autofit.non_linear.search.mle.abstract_mle import AbstractMLE / class AbstractPySwarms(AbstractMLE) to NonLinearSearch + from autofit.non_linear.search.posterior_kind import POINT.
    • Add posterior_kind = cap.PosteriorKind.POINT.
    • In __init__, set self.clipper = POINT.clipper_for(kwargs.pop("clipper", None)) (or add an explicit clipper=None argument) and pass initializer=POINT.initializer_for(initializer).
    • Replace the is_test_mode() / apply_test_mode() tail (:123) and the apply_test_mode override (:297) with test_mode_budget = {"iters": 1}.
    • Optionally, pass rng=initializer_rng(self) (autofit.non_linear.search.seed) to its direct self.initializer.samples_from_model(...) call (~:171) so seed= reproduces its start points, or call self.start_points(...) instead.
    • globe.py / local.py need no change.
    • searches/nss/ no longer exists, so there is nothing to update there.

Adversary review 07 (Codex gpt-6-astra) — enacted

This branch is rebased onto the fixed PR 2 (175d91a58, which enacts findings 1–3; see #1686). The rebase was clean. Finding 4 is fixed in 09834b9c0.

# Finding Reproduced Fix Tests
4 (P2) Re-parenting added Drawer's clipper mid-signature and removed SMC's auto_correlation_settings mid-signature, so valid positional calls silently rebound. Yes. On main, Drawer(None, None, None, 50, None, 12, 34, True) gives full=12, quick=34, silence=True, clipper=ClipperNone. On the old PR 3 head it gave full=34, quick=1, silence=False, clipper=12. An old positional SMC call with AutoCorrelationsSettings raised TypeError: float() argument must be … not 'AutoCorrelationsSettings'. Drawer: clipper is now the last named argument (after session), so main's positional slots bind as before. Its serialized argument set (+clipper) and its identifier are unchanged. SMC: the arguments after inverse_mass_matrix are keyword-only, behind a deprecated *legacy_positional. An old positional call is bound to its former slots (auto_correlation_settings, iterations_per_quick_update, iterations_per_full_update, number_of_cores, silence, session), drops the auto-correlation settings and emits a FutureWarning. More positionals than the old arity raise a clear TypeError. Keyword construction is unchanged and does not warn. test_drawer_positional_slots_are_unchanged (the review's exact call), test_drawer_clipper_still_accepted_by_keyword_and_serialized, test_smc_old_positional_auto_correlation_slot_binds_as_before, test_smc_too_many_positional_arguments_raise, test_smc_keyword_construction_does_not_warn

Documented change to the conformance golden: SMC's inspect.signature parameter set gains legacy_positional, because the *args shim is a named parameter. The serialized constructor-argument set (autonerves.dictable.get_arguments, which search.json uses) is unchanged: SMC is still −auto_correlation_settings and Drawer still +clipper, as stated above.

Gates on this head (09834b9c0):

  • Full suite, serial: 3776 passed, 1 skipped, 0 xfailed. That is the previous 3750, plus PR 2's 21 review tests, plus 5 here.
  • unittest-nojax emulation: 3459 passed, 180 skipped.
  • _generate_searches.py --check: up to date.
  • Sphinx: 30 warnings, the same set as PR 2.
  • 15-search identifier, hash_list, to_dict and argument-set dump: identical to the previous PR 3 head. Against main it differs only by the declared seed additions, NUTS/SMC seed: 42 → null and SMC −auto_correlation_settings.
  • autofit_workspace_test graphical/analytic_gaussian.py (seeded Dynesty joint fit): PARITY: PASS (41/41), both unchanged and with the PR 2 companion edit applied in a scratch copy.

🤖 Generated with Claude Code

@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Oct 14, 2026
@Jammy2211
Jammy2211 force-pushed the feature/search-ext-a4-family-bases branch from 946835f to 09834b9 Compare October 14, 2026 12:51
Jammy2211 and others added 5 commits October 14, 2026 14:02
…, POINT)

NonLinearSearch.plot_results dispatches on the declared posterior_kind, replacing the
family plot_results; the chain/weighted/point defaults (initializer, clipper,
auto-correlation settings) are applied by each concrete __init__, never on
NonLinearSearch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…n subclasses

Distinct NonLinearSearch subclasses keeping the former defaults and plots; subclassing
one warns (FutureWarning via __init_subclass__); removed one release later.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… drops auto_correlation_settings

Emcee/Zeus/BlackJAXNUTS apply CHAIN defaults (auto-correlation settings now built at
construction, so a run-time PYAUTO_TEST_MODE reaches them), Dynesty/Nautilus/NSS/SMC
WEIGHTED (nested samplers still reject InitializerParamBounds), BFGS/LBFGS/MultiStart/
Drawer POINT. Drawer names clipper explicitly so search.json is unchanged. An old SMC
search.json carrying auto_correlation_settings still loads.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…kind defaults; repair the auto-correlation xfails

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Re-parenting gave Drawer an explicit `clipper` mid-signature and removed SMC's
`auto_correlation_settings` mid-signature, so valid positional calls silently
rebound: Drawer(None, None, None, 50, None, 12, 34, True) read full=34,
quick=1, silence=False, clipper=12; an old positional SMC call put the
AutoCorrelationsSettings in the quick-update slot (TypeError).

- Drawer: `clipper` is now the last named argument (after `session`); the
  serialized argument set (+clipper) and identifier are unchanged.
- SMC: the arguments after `inverse_mass_matrix` are keyword-only, behind a
  deprecated `*legacy_positional` that binds an old positional call to its
  former slots (auto-correlation settings dropped) with a FutureWarning, and
  raises a clear TypeError past the old arity. dictable's serialized argument
  set is unchanged; the conformance golden signature set for SMC records the
  new `legacy_positional` name.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Jammy2211
Jammy2211 force-pushed the feature/search-ext-a4-family-bases branch from 09834b9 to 4b86167 Compare October 14, 2026 13:10
Base automatically changed from feature/search-ext-a4-seed to main October 14, 2026 14:06
@Jammy2211
Jammy2211 merged commit df6d218 into main Oct 14, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/search-ext-a4-family-bases branch October 14, 2026 14:06
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: A4 decompose NonLinearSearch, search-level seed, delete family bases (search-extensibility)

1 participant