Repository navigation
refactor: A4a decompose NonLinearSearch (TestModeBypass, EP adapter, runtime settings, paths capabilities) - #1685
Merged
Merged
Conversation
…paths_from Replace the isinstance(NullPaths/DatabasePaths) checks in the updater timer and the Dynesty/Nautilus checkpoint paths with paths capability flags; paths_from builds a search's paths from name/path_prefix/session. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ical/expectation_propagation Moves NonLinearSearch.optimise's body verbatim (release_search_internal, the per-step SubDirectoryPaths that invalidates the cached updater, the EP visual switches) and re-exports it from autofit.graphical.expectation_propagation. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ode hook, mixin modules)
- TestModeBypass (search/test_mode_bypass.py): the level 2/3 bypass and the level 1
rejected-sample repair; bypass and real fit share finalize_result(samples).
- Generic apply_test_mode from test_mode_budget, run once by a post-init hook
(_SearchMeta.__call__); the per-search tails and plain overrides are removed.
BFGS/LBFGS gain test_mode_budget={'maxiter': 10}.
- optimise delegates to SearchFactorOptimiser; __init__ uses paths_from and
SearchRuntimeSettings; the runtime gates move to preflight.check_runtime_gates.
- The run(ctx) bridge, Fitness, start points and pools (execution.py), the
archive/resume/samples path (internal_state.py) and the updater/schedule
(updates.py) move to __init__-less bases of NonLinearSearch.
- abstract_search.py: 2102 -> 584 lines.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Search-extensibility phase A4a (PR 1 of 3, stacked: this →
feature/search-ext-a4-seed→feature/search-ext-a4-family-bases). DecomposesNonLinearSearch:abstract_search.pygoes from 2,102 to 584 lines with no change to identifiers,search.json, serialized constructor-argument sets or the public API.FitLifecycleis deliberately not extracted (D22, deferred to A5). Issue #1684 is closed by PR 3.What changed, by sub-step
paths_from(d3835e50c).AbstractPaths.has_timer/supports_checkpointing(Null: False/False; Database: False/True; Directory and sub-directory paths: True/True) replace theisinstance(NullPaths/DatabasePaths)checks in the updater timer,start_resume_fit, and the Dynesty/Nautilus checkpoint and iteration paths.autofit.non_linear.paths.paths_from(name, path_prefix, unique_tag, session, paths)is the paths factory that__init__used inline.SearchFactorOptimiser(ee8d99139), inautofit/graphical/expectation_propagation/search_factor_optimiser.pyand re-exported fromautofit.graphical.expectation_propagation. It holds the oldoptimisebody unchanged: therelease_search_internalcall (RAL 342410 comment kept), the freshSubDirectoryPathsfor each step that makes the cached updater rebuild itself, the EP visual switches, thelog_normevidence, and thecheck_factor_search_coresrefusal.NonLinearSearch.optimiseis now a one-line delegate, andNonLinearSearchis still anAbstractFactorOptimiser.SearchRuntimeSettings(956e4958b,search/runtime.py). This is a frozen dataclass holding thegeneral.yamlreads made once at construction: update cadences, HPC override, background/live updates, the force-overwrite flags andsilence. It is applied as the same instance attributes as before, sosearch.jsonis unchanged. The module also holdswarn_if_threads_unpinned,configure_handler,check_cores,warn_deprecated_jax_knob,log_fit_startandquick_update_message;abstract_searchre-exports the old names.d37280e2b):TestModeBypass(search/test_mode_bypass.py) holds the level 2/3 bypass, the deterministic valid-point search, the level-1 rejected-sample repair (repair_reduced_samples) andbuild_fake_samples. The bypass and the real fit both end in the oneNonLinearSearch.finalize_result(samples, ...):make_result, thensave_results(_combined), unfreeze, then_complete_fit.apply_test_modeis driven by the declaredtest_mode_budget(dotted keys reach members, e.g.convergence.window). It runs once from a post-init hook,_SearchMeta.__call__→_post_init, after the outermost__init__returns. The eightif is_test_mode(): self.apply_test_mode()tails and the five plain-assignment overrides (Emcee, Zeus, Dynesty, Nautilus, NSS) are gone.BlackJAXNUTSandSMCkeep their overrides because they cap rather than assign (min(num_chains, 2),min(num_particles, 16)).test_mode_budget = {"maxiter": 10}. At level 1 they used to run the fullmaxiter=15000. The registry anddocs/searches/index.rstare regenerated to match.start_resume_fitintopreflight.check_runtime_gates. They still run after the bypass return.__init__-less bases ofNonLinearSearchin their own modules. These areexecution.py(therun(ctx)bridge_run_bridge,make_fitness, start points, pools,_SearchMeta),internal_state.py(archive/resume state, the samples-conversion path) andupdates.py(cachedSearchUpdater,perform_update/perform_visualization, the update schedule).make_pool,make_sneaky_pooland thenumber_of_coresaccessor stay, with docstrings marked deprecated until A5.SneakyPoolstays asPoolFactory.sneaky.Invariants (report §3.2)
af.exportsSearchFactorOptimiseradded toautofit.graphical.expectation_propagationtest_conformance.py::test_identifier_golden, all 15) passes; a scripted dump ofstr(Identifier(cls()))andhash_listfor all 15 is byte-identical to main 8437a3bsearch.json, serialized constructor-argument setsaf.to_dict(cls())andautonerves.dictable.get_arguments(cls)for all 15 identical to main (the new bases define no__init__, so the__bases__walk adds nothing);test_search_json_round_trippassessamples_info["class_path"]test_nested_samplers_have_no_clipper,test_clipper_forks_mle_identifierpassNonLinearSearchis anAbstractFactorOptimisertest_search_is_still_a_factor_optimiserperform_update,samples_via_internal_from,_fit, ... still resolve on the search)Resultone classWitness
wc -l autofit/non_linear/search/abstract_search.py: 2102 → 584 (guarded bytest_decomposition.py::test_abstract_search_is_at_most_600_lines).maxiter:test_bfgs_runs_a_reduced_maxiter_at_test_mode_1(maxiter == 10, BFGS and LBFGS), and 15000 outside test mode.test_autofit/graphical/test_search_factor_optimiser.py. Every factor getsoptimization_0andoptimization_1with fresh paths. The cached updater is rebuilt for each new paths object (updater._paths is search.paths). The visual switches are set for each step and restored afterwards.release_search_internalis called on every step's result.TestBypass*,test_updater.py,test_autofit/graphical/*pass.Tests
python -m pytest test_autofit -q): 3603 passed, 1 skipped, 4 xfailed (main baseline: 3579 passed / 1 skipped / 4 xfailed; +24 new tests).unittest-nojaxemulation (asitecustomizeblocking jax/jaxlib/blackjax/optax,find_spec → None): 3298 passed, 170 skipped, 2 xfailed.docs/_generate_searches.py --checkis clean after regenerating (BFGS/LBFGS budget column).pyauto-heart smoke autofit autolens, worktree source): autofit_workspace 8/8 scripts + 2/2 notebooks, autolens_workspace 41/41 scripts + 2/2 notebooks pass.autofit_workspace_testscripts/searches+scripts/graphical(32 scripts): 25/32 pass atPYAUTO_TEST_MODE=1, 23/32 at=2. Every failure also fails on main 8437a3b with the same harness. They are real-search assertions not meant for test mode (BlackJAXNUTS divergences, MultiStart accuracy/resurrect/NaN-counter checks,analytic_gaussian*parity, and at level 2 NSSlog_evidence_errorandep_parity), so none is a regression.non_linear/search+graphical+database/identifier) shows 5 order-dependent failures (graphical/info/test_output.py,test_global.py,test_identifiers.py::test_unique_tag). The same subset fails identically on main, and the full serial suite is green.Decisions taken
FitLifecycledeferred (D22), the lifecycle plus constructor alone is about 450 lines, so ≤600 needed the rest out of the file. The new bases keep the whole method surface on the search, so subclass overrides and tests that monkeypatchNonLinearSearch.<method>still work, and none defines__init__, sodictable.get_argumentsis unchanged (verified for all 15). The real collaborators areTestModeBypass,SearchFactorOptimiser,SearchRuntimeSettings,paths_fromandPoolFactory.fit,pre_fit_output,start_resume_fit,result_via_completed_fit). Content is kept and the verbose parameter blocks are trimmed._visualize_fit,_visualize_before_fit). The adapter sets and restores them. Tests and the updater read them there, andStaticSearchdoubles rely on the class defaults.BlackJAXNUTSandSMCkeepapply_test_modeoverrides for theirmin(...)caps, so a user's smallernum_chains/num_particlesis not raised.Drawerkeeps an empty budget, because its initializer already draws test-mode samples, and changingtotal_drawswould re-key its test-mode output.DatabasePaths.supports_checkpointing = True. This keeps the Dynesty/Nautilus checkpoint and iteration behaviour for database paths, where previously onlyNullPathswas excluded.has_timeris False for Null and Database, exactly as the two oldisinstancechecks.samples_fromfallback warning now logs underautofit.non_linear.search.internal_state;test_conformance_backend.pyfollows it. Tests patchingTEST_MODE_REPRESENTATIVE_MAX_ATTEMPTSnow patchsearch.test_mode_bypass.test_make_fitness.py's single-construction-site scan now namesexecution.py.search/runtime.py's logger.Companion changes required
None for this PR.
🤖 Generated with Claude Code