feat(autofit): multi-start gradient convergence results contract (phase 2)#1410
Merged
Jammy2211 merged 1 commit intoJul 21, 2026
Merged
Conversation
…ood index Phase 2 of the multi-start gradient auto-convergence work (phase 1: #1407). - samples_info now carries converged, stop_reason, the convergence settings, and the fom_history trace (JSON-round-trippable) so the auto-convergence outcome is inspectable downstream. - New figure_of_merit_vs_iteration MLE plotter draws the global-best figure-of- merit trace so the plateau can be seen; wired into plot_results behind a default-on, config-missing-tolerant gate (no-op for LBFGS/Drawer without a fom_history). - Fix Samples.max_log_likelihood_index / max_log_posterior_index to use np.nanargmax: plain argmax selected the zero-weight NaN diagnostic rows the multi-start searches write, returning the wrong index (inconsistent with max_log_likelihood_sample). Only changes results where a NaN was present. - Aggregator regression tests for variable-length + zero-weight/NaN rows. Refs #1409. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LSEf7D5urqPgvffKBqzPsF
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
Phase 2 of 2 of the multi-start gradient auto-convergence work (phase 1: PyAutoFit#1407). The results contract: make the auto-convergence outcome inspectable and keep the max-likelihood/aggregator path robust to the variable-length, zero-weight/NaN-diagnostic-row results that early-stopping produces.
API Changes
Additive, plus one shared-
Samplescorrectness fix. Added:converged/stop_reason/convergence/fom_historyto the multi-start gradientsamples_info; afigure_of_merit_vs_iterationMLE plotter (+plots_search.yamltoggle) drawing the global-best figure-of-merit trace so the plateau is visible. Fixed:Samples.max_log_likelihood_index/max_log_posterior_indexusednp.argmax, which selects aNaNsample (argmax([2.5, nan, nan]) == 1) — the multi-start searches write their non-best starts as zero-weightNaN-log-likelihood diagnostic rows, so these returned the wrong index (inconsistent withmax_log_likelihood_sample). Nownp.nanargmax; only changes results where aNaNwas present. No migration.See full details below.
Test Plan
python -m pytest test_autofit/→ 1525 passed, 1 skippedIndexErrorfigure_of_merit_vs_iterationrenders a PNG withfom_historyand no-ops without itautofit_workspace/scripts/searches/mle.pyruns end-to-end through the newsamples_infopath (exit 0)autofit_workspace_testJAX round-trip (converged/stop_reason/trace through the results DB) — workspace follow-up after mergeFull API Changes (for automation & release notes)
Added
samples_infoon multi-start gradient results now includes:converged: bool,stop_reason("converged"|"max_steps"|None),convergence({check_for_convergence, window, rtol, atol, min_steps}),fom_history(list of floats, the global-best figure-of-merit trace, orNonefor legacy runs).autofit.non_linear.plot.figure_of_merit_vs_iteration(samples, …)— MLE plotter drawing the global-best figure-of-merit vs step; readssamples.samples_info["fom_history"], no-op when absent (LBFGS/Drawer).config/visualize/plots_search.yaml→mle.figure_of_merit_vs_iterationtoggle (defaulttrue). Theplot_resultsgate is default-on and tolerant of a config predating the key, so it neverKeyErrors on an MLE fit in an older workspace.Changed Behaviour
Samples.max_log_likelihood_indexandSamples.max_log_posterior_indexnow usenp.nanargmax(wasnp.argmax), so aNaNsample is never selected as the best. This fixes wrong-index selection on any search withNaNsamples (the multi-start gradient searches' zero-weight diagnostic rows) and makes the properties consistent withmax_log_likelihood_sample. Behaviour is unchanged where no sample isNaN. Fully-NaNsample lists return index 0.Migration
Validation checklist (--auto run — plan was not pre-approved)
searches/mle.py) · review self-CLEAN (incl. the shared-Samplesnanargmaxfix, full suite green) · Heart RED — two pre-existing/unrelated reasons ("PyAutoFit: 2 commit(s) behind origin","PyAutoLens: 1 uncommitted source change(s)"), human-waived contemporaneously via AskUserQuestionGenerated by the PyAutoLabs agent workflow.