Repository navigation
fix(dynesty)+perf(ep): converged search runs once; ndtr in truncated-normal maths (#1642, PR 1 of 3) - #1643
Merged
Conversation
run_search_internal only treated a pass as final when it added zero likelihood calls, so every converged dynesty search ran an intermediate perform_update, a checkpoint restore and a second no-op run_nested. dynesty's per-run call counter resets on each run_nested and stops on the budget only once it is strictly above maxcall, while sum(results.ncall) grows by at least that counter. A pass that added no more calls than the budget it was handed therefore stopped on dynesty's own criterion. The finish test is now: NullPaths; global maxcall reached; dynesty stopped under budget; legacy no-progress. Finite iterations_per_full_update cadences still loop through perform_update. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… updates (#1642) - TruncatedNormalMessage.log_partition / kl / _normal_gradient_hessian_from use scipy.special.ndtr via _erf_helpers._norm_cdf instead of scipy.stats.norm.cdf: the same Cephes routine without the rv_continuous wrapper, bit-identical (test__ndtr_swap_bit_identical, incl. infinite limits). truncnorm.stats is untouched. _erf_helpers binds ndtr/ndtri once at module level for NumPy. - Fitness.manage_quick_update returns before any bookkeeping when iterations_per_quick_update is None or >= ITERATIONS_NEVER (the packaged 1e99 default); ITERATIONS_NEVER moves to fitness.py and is re-exported from abstract_search.py for existing importers. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Sep 24, 2026
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
PR 1 of 3 under #1642: cutting per-factor overhead in EP (expectation propagation) factor searches. PR 2 switches the EP visuals, and PR 3 follows with the mapper fast path.
0e2c09748). Under the defaultiterations_per_full_update = 1e99, a Dynesty search that converged on its firstrun_nestedpass was not recognised as finished. It then did an intermediateperform_update(during_analysis=True), a checkpoint restore and a secondrun_nestedthat made no likelihood calls.AbstractDynesty.run_search_internalnow recognises "dynesty stopped itself inside its call budget" as converged, so every converged run finishes in one pass. The docstring explains why this works: dynesty's per-run call counter resets on eachrun_nestedand it stops only when the counter is strictly abovemaxcall.16789050a).TruncatedNormalMessage.log_partition,kland_normal_gradient_hessian_fromnow callscipy.special.ndtrthrough the module-level bindings in_erf_helpers, instead ofscipy.stats.norm.cdf. The result is bit-identical but skips therv_continuousargument-checking overhead.Fitness.manage_quick_updatenow returns before any per-call bookkeeping when quick updates are disabled (cadence>= ITERATIONS_NEVER, which covers the packaged 1e99 default). This method runs once per likelihood evaluation.Harness: an
ep_toy_gaussiancopy with N=5, max_steps=3, nlive=100, rwalk, fully seeded. Baseline (a73684012) and modified runs were interleaved ABAB on the same laptop.run_nestedcalls (15 factor searches)perform_update(during_analysis=True)search.fit, mean)ep_historyflagsFull evidence, including the harness-determinism notes and the dynesty 2.1.5 semantics probe, is in #1642 (comment).
API Changes
There are no public signature changes. Three things behave differently:
pathsnow finishes after onerun_nestedpass. It no longer does the intermediateperform_update, checkpoint restore and secondrun_nested. Final results are unchanged; the difference is thatduring_analysis=Trueoutput is no longer written for converged runs. Finite-cadence chunking and the global-maxcallstop still work, and a globalmaxcallnow counts as reached whensum(ncall) >= maxcallrather than== maxcall.ITERATIONS_NEVERhas moved toautofit.non_linear.fitness. It is still re-exported fromautofit.non_linear.search.abstract_search, so existing imports keep working.Fitness.manage_quick_updatereturns before updating its running max-likelihood and quick-update counter.See full details below.
Test Plan
test_dynesty.pyhas 5 new tests (6 cases, since the real-dynesty test is parametrized over static and dynamic):maxcall;_fitloop (3 runs, 2 intermediate updates);run_nestedand noduring_analysis=Trueupdate.All of them fail on the old code.
test__ndtr_swap_bit_identicalchecks 72 grid cases, including infinite limits. It asserts exact equality againstscipy.stats.norm.cdffor_norm_cdf,log_partition,_normal_gradient_hessian_fromandkl.test__disabled_cadence_returns_before_any_bookkeeping(1e99 and 1e100) fails on the old code.Full suite, run serially (
pytest test_autofit -p no:xdist -x): 2881 passed, 2 skipped.EP harness: the answer is bit-for-bit identical to baseline, with 15 fewer
run_nestedcalls and about 18 % less wall time per search.Full API Changes (for automation & release notes)
Moved
ITERATIONS_NEVER(value1e90): moved fromautofit.non_linear.search.abstract_searchtoautofit.non_linear.fitness. It is re-exported fromabstract_search, sofrom autofit.non_linear.search.abstract_search import ITERATIONS_NEVERstill works.Changed Behaviour
AbstractDynesty.run_search_internal(search_internal, ...): the "finished" criteria are now checked in this order:NullPaths;maxcallset andsum(results.ncall) >= maxcall(previously== maxcall);iterations, meaning dynesty stopped itself ondlogz,maxiteror similar;In practice, a converged search with default config finishes in one pass, with no intermediate
perform_update(during_analysis=True), checkpoint restore or secondrun_nested. A pass that overruns a finiteiterations_per_full_updatechunk still loops throughperform_update.Fitness.manage_quick_update(parameters, log_likelihood): wheniterations_per_quick_update >= ITERATIONS_NEVER, it returns immediately without updatingquick_update_max_lhorquick_update_count(previously onlyNoneshort-circuited). Those values only ever fed the quick-update body, which cannot fire at that cadence.TruncatedNormalMessage.log_partition,.kl,._normal_gradient_hessian_from: these now usescipy.special.ndtrviaautofit.mapper.prior._erf_helpers._norm_cdfin place ofscipy.stats.norm.cdf. The output is bit-identical.autofit.mapper.prior._erf_helpers._norm_cdf/_norm_ppf(private): the NumPy branch now uses module-levelscipy.special.ndtr/ndtribindings.Migration
Heart RED override (development only)
This PR is opened under the
PyAutoBrain/AUTONOMY.md"Human override for Heart RED (development only)". It is a development-shipping override only. It does not claim to fix Heart, and Heart remains RED for release purposes. Merge still needs a separate explicit human/prmwith every required check green.pyauto-heart readiness --json, verdict red, score 45, ts 2026-09-24T15:11:12.973142+00:00):release validation FAILED (stage integrate)workspace validation not passing (4 failed, cloud#35579888156: autolens notebooks/cluster/modeling.ipynb, autolens notebooks/weak/a2744.ipynb, autolens scripts/cluster/modeling.py, +1 more)manifest drift: hub organism blurb (organs present) — 7 mismatch(es) vs PyAutoMind/repos.yamltest_autofit2881 passed / 2 skipped on head 1678905; autofit workspace smoke 8/8 scripts + 2/2 notebooks; PyAutoFit main CI green; downstream workspace impact (iii) none.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code