Skip to content

refactor: close the run(ctx) framework, new-search template (search-ext A5 PR 4/4) - #1692

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

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

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Search-extensibility phase A5 (library), PR 4 of 4 (stacked on PR 3; merge last): close the run(ctx) framework and ship the new-search template. Closes #1688.

  • Legacy pool shims deleted from execution.py: make_pool, make_sneaky_pool and their one-core decorator check_cores (runtime.py, plus its abstract_search re-export). PoolFactory is now the only pool source; SneakyPool stays, built only by PoolFactory.sneaky. An external search that still overrides _fit (the developer-tier nss / ultranest / pyswarms) keeps working and reaches the pools through self._pools(analysis). Nothing in PyAutoFit, PyAutoLens, PyAutoGalaxy, PyAutoCTI, PyAutoArray or the workspaces referenced the shims (grep).
  • Unknown-kwarg guard (warn, never raise): a keyword reaching NonLinearSearch.__init__ is logged as unknown only when no __init__ in the search's MRO names it (runtime.warn_unknown_kwargs).
  • SettingsSearch / use_jax_vmap: search_dict_for already filtered the knob; the remaining gap was **settings_search.search_dict (used by every autolens_workspace SLaM script), which handed use_jax_vmap=None to every search and logged it as unknown. The default None is now not reported for searches that do not accept it; a set value still is. Decision flagged: search_dict keeps its key (its shape is tested and consumed); the filter is in the guard.
  • Template: autofit/non_linear/search/_template/search.py — a complete, runnable search (a random-walk hill climber) whose module docstring states the run(ctx) contract and the six PyAutoFit touch points of a new search. Template smoke: test_autofit/non_linear/search/template_toy_search.py (the template renamed — a test asserts the sources match — 158 lines, ≤250) passes both A0a conformance layers through the very same test functions (test_template_search.py, 18 cases: layer (i) construction, family, identifier fields, golden identifier, constructor set, search.json round trip, config untouched; layer (ii) reduced test-mode run, output file set, completed-path resume without the backend, NullPaths result, samples fallbacks, restored-output samples, samples_info key set).
  • docs/design/run_ctx.md revision 4.
  • FitLifecycle: not introduced (D22). PRs 1–3 left no lifecycle code duplicated across searches that the mixins cannot host — the chores (Fitness, pools, start points, seed streams, schedule, update, cleanup) all live in the bridge and FitContext, and what remains in each run is its backend loop. The residual per-search idioms (Zeus/BFGS's own dill resume, Dynesty's unit-cube start points, MultiStart's _broad_starts) are backend-specific, not shared lifecycle.

Witness: grep -rn "def _fit(" autofit/non_linear/search → only abstract_search.py; grep make_pool|make_sneaky_pool|check_cores over PyAutoFit/PyAutoLens/PyAutoGalaxy/PyAutoCTI/PyAutoArray and the workspaces → no hits.

API Changes

Removed the deprecated legacy pool shims of the _fit contract (deprecated since A4, no known callers); unknown-kwarg warnings are narrower.
See full details below.

Test Plan

  • Full suite, serial: 3812 passed, 1 skipped, 0 xfailed
  • unittest-nojax emulation: 3495 passed, 180 skipped
  • python docs/_generate_searches.py --check: clean · Sphinx: 30 warnings
  • 15-search invariants vs main df6d218: byte-identical for all 15
  • Seeded byte-identity: every migrated search was checked in PRs 1–3 (this PR changes no backend loop)
  • autofit_workspace_test/scripts/searches/*.py (all 19) at PYAUTO_TEST_MODE=1 and =2: 14/19 pass at mode 1 and 13/19 at mode 2 — the identical pass set to main df6d218 (failing on both: BlackJAXNUTS, MultiStartAdam, MultiStartProdigy, MultiStartResumeNaNCounters, MultiStartResurrect, and NSS at mode 2 — script assertions/keys under the reduced test-mode budget, e.g. KeyError: 'n_resurrections', KeyError: 'log_evidence_error'; pre-existing)
  • pyauto-heart smoke autofit autolens on this head: rc 0, 53 PASS, 0 FAIL
  • Disk-backed old-output check (writable env; script old_outputs.py): outputs written by pre-A2 PyAutoFit (0dbf258) and by A4-era main (df6d218) — 11 completed fits (Emcee, Zeus, DynestyStatic, DynestyDynamic, Nautilus, BFGS, LBFGS, Drawer, MultiStartAdam, BlackJAXNUTS, SMC) and 3 interrupted fits (Emcee mid-HDF, DynestyStatic mid-savestate, Nautilus mid-checkpoint.hdf5) — loaded with this branch:
    • Aggregator (from_directory): all 11 completed outputs + interrupted Emcee/Nautilus load search, samples and summary (same SearchOutput.ids for both eras); the interrupted DynestyStatic output has no samples_summary yet (interrupted before its first update) — identical on a main control run;
    • rerunning each completed search: completed path, 0 backend calls, result loads, for both eras;
    • rerunning each interrupted search: resumes and completes for both eras (Emcee 220 samples / max logL −45.2691 and Nautilus 3500 / −45.2129 on the A4-era outputs, matching a main control run exactly).
Full API Changes (for automation & release notes)

Removed

  • NonLinearSearch.make_pool() — use ctx.pool (in run(ctx)) or self._pools(analysis)() (PoolFactory).
  • NonLinearSearch.make_sneaky_pool(fitness) — use ctx.pool.sneaky(fitness) / self._pools(analysis).sneaky(fitness).
  • autofit.non_linear.search.runtime.check_cores (and its re-export from abstract_search).

Added

  • autofit.non_linear.search._template.search.TemplateSearch — the template (not exported, not registered).
  • autofit.non_linear.search.runtime.warn_unknown_kwargs(search, kwargs, known=()).

Changed Behaviour

  • The unknown-constructor-keyword warning skips keys some __init__ in the MRO names, and use_jax_vmap=None.

Migration

  • Before: pool = self.make_sneaky_pool(fitness) in a custom _fit
  • After: pool = self._pools(fitness.analysis).sneaky(fitness), or move the search onto run(ctx) and use ctx.pool.sneaky(ctx.fitness) (see the template).

Companion changes required

None beyond the A5 consumers task (search_ext_a5_consumers.md), which should point the Brain sampler_pipeline/reference.md anatomy at search/_template/search.py. No caller of the removed shims exists in the workspaces or dependent libraries.

Gate evidence note: smoke, workspace and old-output checks ran on 81de70d; the follow-up review-fix commit 9c78451 changes only docstrings, removes the class-keyed lru_cache from _mro_init_parameters and inlines a test fixture — suites, docs check and Sphinx were re-run on the final head.

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

  • Effective level: safe (header: supervised, cap: refactor → safe); tier judge — merge stays human (/prm), merge last (after PR 3)
  • Plan: on the issue (refactor: A5 library — all searches onto run(ctx), delete legacy _fit/pool surface, template (search-extensibility) #1688), unmodified since
  • Gate: tests 3812 / 1 skipped full serial, nojax 3495 / 180 skipped · smoke pyauto-heart smoke autofit autolens rc 0 (53 PASS) + all 19 workspace_test search scripts = main · review: independent Opus reviewer FINDINGS (5, all low) → dispositions: (1) stale SettingsSearch.search_dict docstring — fixed; (2) NSS missing from the revision-4 list — fixed; (3) lru_cache keyed on classes keeps dynamic classes alive / stale on __init__ swap — fixed (cache removed); (4) the warning now logs from ...search.runtime — accepted, nothing filters on the logger name; (5) test used pytest's __wrapped__ on a fixture — fixed (inlined) · Heart STALE 85 within launch ack (reasons: "release validation incomplete: no rehearsal for current source")
  • Human: plan sound in hindsight?
  • Human: diff matches plan (no scope creep)?
  • Human: merge, amend, or reject — then log the outcome

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits October 14, 2026 16:11
…(search-ext A5 PR 4)

- Delete the legacy pool shims of the _fit contract (make_pool,
  make_sneaky_pool and their one-core decorator check_cores); PoolFactory
  is the only pool source (SneakyPool stays, via PoolFactory.sneaky). An
  external search that still overrides _fit keeps working through
  self._pools(analysis).
- Unknown-kwarg guard: warn (never raise) only for keywords no __init__
  in the MRO names; use_jax_vmap=None, which SettingsSearch.search_dict
  hands every search, is no longer reported for searches without it.
- autofit/non_linear/search/_template/search.py: a runnable template
  search whose module docstring states the run(ctx) contract and the six
  PyAutoFit touch points; test_template_search.py runs both conformance
  layers on a renamed copy (template_toy_search.ToyHillClimb, 158 lines).
- docs/design/run_ctx.md revision 4; FitLifecycle not introduced (D22).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ision 4, no class cache, inline config fixture

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-multistart to main October 15, 2026 12:21
@Jammy2211
Jammy2211 merged commit 3f4699b into main Oct 15, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/search-ext-a5-framework branch October 15, 2026 12:22
@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.

refactor: A5 library — all searches onto run(ctx), delete legacy _fit/pool surface, template (search-extensibility)

1 participant