Repository navigation
Description
Overview
PR #1576 reports EP staleness per (factor, variable) and records reverted_variables in ep_history.csv, but the per-variable mask is a numerical difference test, not a rejection test. An accepted projection that lands on its own fixed point reproduces its message bit-for-bit, so a perfectly healthy update is counted as "reverted": EP restarted from its converged EPMeanField on an exact Gaussian graph emits STALE FACTORS for every factor and lists the variable in reverted_variables on every row, while every update is SUCCESS and the posterior is correct. Unchanged does not imply rejected. Found by an external review of #1574/#1576/#1578 and reproduced on main (68ff9bd57) on 2026-09-08.
Plan
- Make the per-variable
changedsignal mean "this update accepted this variable's projection", derived from projection validity rather than from numerical movement. - Leave the
updatedflag on the numerical comparison so fix(ep): a fully reverted projection counts as skipped, not updated #1574's "fully reverted counts as skipped" classification is unchanged. - No change to the optimiser stale-factor report or the diagnostics writer: they consume the mask, which now genuinely means "rejected".
- Rewrite the now-wrong docstring premise of the partial-revert history test; add a regression test that restarts EP from a converged mean field and asserts no stale warnings and an empty
reverted_variablescolumn. - Full
test_autofit/graphicalsuite must stay green (278 passed on main).
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main (68ff9bd, in sync with origin) | clean |
Suggested branch: feature/ep-stale-mask-fixed-point
Implementation Steps
autofit/graphical/mean_field.py, valid branch of the factor update (~L580-584): replacechanged = factor_dist.check_changed(last_dist) if last_dist is not None else Nonewith an all-TrueVariableData({v: True for v in factor_dist})— an accepted projection accepts every variable, and a fixed point is not a rejection. This also removes thelast_dist is Nonehole so first-sweep updates are counted.autofit/graphical/mean_field.py, invalid branch (~L545-560): build the mask from thecheck_valid()result already computed at ~L545, beforeupdate_invalidruns:{v: bool(np.all(ok)) for v, ok in valid.items()}. Unchanged-after-revert is no longer the signal.- Leave
updated(check_changed(last_dist)after the revert) as is: a fully invalid projection yields an all-False mask,changed.any()is still False, so fix(ep): a fully reverted projection counts as skipped, not updated #1574's skipped classification is preserved. A mixed projection whose valid variables happen to land bit-identically now reads asupdated, which is the correct reading. autofit/graphical/expectation_propagation/optimiser.py(~L403-406_variables_changedaccumulation, ~L498-514_stale_factor_warnings) andautofit/graphical/expectation_propagation/diagnostics.py(~L145-156reverted_variablescolumn): no code change expected; verify they readStatus.changedonly.- Tests,
test_autofit/graphical/functionality/test_factor_failure_recovery.py:test_partial_revert_is_recorded_in_ep_history_csv(~L499-508): rewrite the docstring premise ("on a converging graph a healthy factor's later rows list its variables too" is now false); assertions still hold.- Add
test_restart_from_fixed_point_is_not_stale: twoExactFactorFitGaussian factors on one variable (make_shared_variable_approxidiom), run EP to convergence, restart EP from the convergedEPMeanFieldfor several sweeps, assert_stale_factor_warnings() == [], every history row hasflag == SUCCESS, and thereverted_variablescolumn is empty on every row.
- Run
pytest test_autofit/graphical -qinside the worktree (activate.sh sourced); must be 279+ passed.
Key Files
autofit/graphical/mean_field.py—check_changed(~L373-391), valid/invalid update branches (~L545-584): the mask source.autofit/graphical/expectation_propagation/optimiser.py—_variables_changedaccumulation and_stale_factor_warnings.autofit/graphical/expectation_propagation/diagnostics.py—reverted_variableswriter.test_autofit/graphical/functionality/test_factor_failure_recovery.py— tests added by feat(ep): report staleness per (factor, variable) and record reverted variables in ep_history.csv #1576.
Original Prompt
Click to expand starting prompt
EP staleness mask flags valid fixed points as stale
Type: bug
Target: PyAutoFit
Repos:
- PyAutoFit
Difficulty: medium
Autonomy: safe
Priority: high
Status: formalised
Consequence: glance
Witness: EP restarted from its own converged EPMeanField on an exact two-factor Gaussian graph emits_stale_factor_warnings() == []and an emptyreverted_variablescolumn on every ep_history.csv row, while test_autofit/graphical stays green (278 passed).
Review-minutes: 3
Unattended: ready
EP staleness mask flags valid fixed points as stale
Type: bug
Target: PyAutoFit
Witness: EP restarted from its own converged EPMeanField on an exact two-factor Gaussian graph emits _stale_factor_warnings() == [] and an empty reverted_variables column on every ep_history.csv row, while test_autofit/graphical stays green (278 passed).
Reproduced (verified 2026-09-08 against an external review of PRs #1574/#1576/#1578): an exact Gaussian graph restarted from its converged EPMeanField emits STALE FACTORS for every factor and lists the variable in ep_history.csv reverted_variables on every row, although every update is SUCCESS and no projection was rejected.
Root cause: the valid branch of the mean-field update (autofit/graphical/mean_field.py) derives changed from check_changed, a bit-exact natural-parameter equality test, rather than from projection acceptance; the optimiser stale-factor report and the diagnostics reverted_variables writer consume that mask. Unchanged does not imply rejected.
Fix: valid branch marks every variable accepted; invalid branch builds the mask from the check_valid result already computed before update_invalid; leave updated on the numerical comparison so the #1574 fully-reverted=skipped classification is untouched.
Tests: rewrite the docstring premise of test_partial_revert_is_recorded_in_ep_history_csv (its assertions still hold); add a regression test restarting EP from a converged mean field asserting no stale warnings and empty reverted_variables.
Activity
Jammy2211 commentedon Sep 8, 2026
Library PR opened: #1580
API impact: none (internal — Status.changed semantics; no public signatures). Workspace impact: option (iii) no workspace change; merge via /prm once CI is green.
Jammy2211 commentedon Sep 8, 2026
Shipped
Merged in #1580.
Status.changednow tracks whether each variable's projection was accepted, rather than whether its message changed bit-exactly, so EP restarted from its own convergedEPMeanFieldno longer emitsSTALE FACTORSfor every factor or fills thereverted_variablescolumn ofep_history.csvwhile every update reportsSUCCESS; the numerical comparison stays onupdated, so the #1574 fully-reverted = skipped classification is unchanged. A regression test (test_restart_from_fixed_point_is_not_stale) covers the fixed-point restart and fails without the fix. Pending release.