Repository navigation
Description
Overview
MeanField.update_factor_mean_field replaces every invalid parameter with last_dist's via
update_invalid, then sets updated = True when factor_dist.check_valid().any(). Because
check_valid runs after the revert, and reverted parameters come from a valid message, it is
true by construction: it measures validity, not change. So a projection that reverts every
parameter — returning the factor's starting distribution bit-identically — is reported as
updated=True. EPOptimiser.factor_step trusts the flag, so _stale_factor_warnings
((raised | skipped) - updated) never names the factor and the STALE FACTORS warning is
suppressed. A full EP run can return its unchanged starting distribution silently.
Finding 2 (P2), plus the phase-1 README prose carry-over, of the Codex review of the graphical-ep
phase-2 fixes (#1558, #1560, #1562), umbrella #1405. Reproduced on main at f6a9915 on
2026-09-07.
Plan
- Decide
updatedby comparing the post-revert message againstlast_distparameter by
parameter, instead of re-testing validity after the revert. - When nothing changed, say so in the status messages so the run log names the reason.
- Leave
successsemantics untouched; keep the two existing raising-optimiser stale tests, which
never reach this branch. - Add a test with a fixture optimiser that always fits over-wide, asserting the factor lands under
factors skippedand the STALE FACTORS line reachesep_diagnostics.results. - Fix the phase-1 wording error in
autofit/graphical/README.md§3.5 and note there that a fully
reverted projection now counts as skipped.
Detailed implementation plan
Work Classification
Library
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main (f6a9915) | clean |
Suggested branch: feature/ep-full-revert-not-updated
Worktree root: ~/Code/PyAutoLabs-wt/ep-phase2-review/ (shared bundle worktree, created by /start_library)
Implementation Steps
autofit/graphical/mean_field.py(~lines 513-543,MeanField.update_factor_mean_field, the
if not factor_dist.is_validbranch): line 525 reverts invalid parameters via
update_invalid; lines 528-530 then setupdated = Truefromfactor_dist.check_valid().any().
Replace that test with a per-variable "changed vslast_dist" comparison — a
MeanField.check_changed(other)over the message parameters, or inline — and set
updated = changed.any().- When nothing changed, append
"factor update skipped: every parameter reverted"tomessages.
successsemantics are unchanged. test_autofit/graphical/functionality/test_factor_failure_recovery.py: add a fixture optimiser
that always returns an over-wide fit; assert the factor appears infactors skipped, is absent
fromfactors updated, and that the STALE FACTORS line is present in
ep_diagnostics.results.autofit/graphical/README.md§3.5 (~lines 244-246): "reproduces the collapse under a Laplace
projection" → "reproduces the stale-factor state (every site update rejected, scatter returned
at its prior) under a Laplace projection". Add one sentence to the STALE FACTORS paragraph
(~line 189) recording that a fully reverted projection now counts as skipped.- Run
python -m pytest test_autofit/graphical -q; the two existing stale tests
(test_never_updating_factor_is_warned_about_loudly,
test_stale_factor_warning_is_written_to_the_diagnostics_file) must still pass unmodified.
Never modify code to make a test pass.
Scope
This prompt fixes the full revert only. The partial revert seen on the campaign graph
(N=2, TruncatedGaussianPrior(10, 0.5, 0, 100) on sigma, Laplace: the sigma message stays
[10.0, 0.7071] bit-identical while the factor's other variables update) needs per-variable
tracking and is filed separately as
draft/feature/autofit/ep_stale_tracking_per_variable.md.
Key Files
autofit/graphical/mean_field.py—update_factor_mean_field(~485-543): thesuccess=False
early return at ~485-497 (already correct),update_invalidat ~525, thecheck_valid().any()
test at ~528-530.autofit/graphical/expectation_propagation/optimiser.py—EPOptimiser.factor_step
(~399-403) and_stale_factor_warnings(~430).test_autofit/graphical/functionality/test_factor_failure_recovery.py— the new test's home.autofit/graphical/README.md— §3.5 (~244-246) and the STALE FACTORS paragraph (~189).
Trade-offs
An exact "changed" comparison on floats is the right test here because a full revert copies
last_dist's parameters bit-identically; no tolerance is needed and adding one would let a
near-zero real update read as skipped.
Original Prompt
Click to expand starting prompt
A fully reverted projection still reports updated=True, suppressing the STALE FACTORS warning
Type: bug
Target: PyAutoFit
Repos:
- PyAutoFit
Themes: - graphical-ep
Difficulty: small
Autonomy: safe
Priority: medium
Status: formalised
Consequence: glance
Witness: an EP run whose factor projection reverts every parameter each sweep lists that factor underfactors skipped, notfactors updated, andep_diagnostics.resultscarries the STALE FACTORS line; new test intest_autofit/graphical/functionality/test_factor_failure_recovery.py; the two raising-optimiser stale tests still pass;grep -n "reproduces the collapse" autofit/graphical/README.mdis empty
Review-minutes: 5
Unattended: ready
Epic: graphical-ep
Filed: 2026-09-07
Finding 2 (P2) plus the README prose carry-over of the Codex review of the graphical-ep phase-2
fixes (review text verbatim in the sibling ep_laplace_deterministic_hessian.md). Reproduced on
main (f6a9915) on 2026-09-07.
Reproduction (2026-09-07)
- Unit: a projection whose q* is wider than the cavity in every variable returns
flag=BAD_PROJECTION, success=False, updated=True, with the returned message bit-identical to
last_dist. - End-to-end
EPOptimiser(2-factor shared-variable graph, one factor fitted over-wide every
sweep): that factor's message ends[0., 10.]= its starting prior, yet it is listed under
factors updated,factors skippedis empty, and no STALE line is logged. - The campaign graph (N=2,
TruncatedGaussianPrior(10, 0.5, 0, 100)on sigma, Laplace): 4/4
hierarchical projectionsBAD_PROJECTIONwithupdated=True; the factor's sigma message stays
[10.0, 0.7071]bit-identical while its other variables update — no warning. That partial
revert needs per-variable tracking and is filed separately
(draft/feature/autofit/ep_stale_tracking_per_variable.md); this prompt fixes the full revert.
Mechanism
autofit/graphical/mean_field.py:513-543 (MeanField.update_factor_mean_field, the
if not factor_dist.is_valid branch): line 525 replaces the invalid parameters with last_dist's
via update_invalid; lines 528-530 then set updated = True when factor_dist.check_valid().any().
check_valid is evaluated after the revert, and reverted parameters come from a valid message, so
it is true by construction: it measures validity, not change. EPOptimiser.factor_step
(expectation_propagation/optimiser.py:399-403) trusts the flag, so
_stale_factor_warnings (line 430, (raised | skipped) - updated) never names the factor. Only
the success=False early return (mean_field.py:485-497) sets updated=False, which is why the
#1562 tests pass.
Fix
Replace the post-revert check_valid().any() test with a per-variable "changed vs last_dist"
comparison (a MeanField.check_changed(other) over the message parameters, or inline);
updated = changed.any(), and when nothing changed append
"factor update skipped: every parameter reverted" to messages. success semantics unchanged.
Test: a fixture optimiser that always returns an over-wide fit; assert the factor is in
factors skipped, absent from factors updated, and the STALE FACTORS line is in
ep_diagnostics.results. The existing stale tests
(test_never_updating_factor_is_warned_about_loudly,
test_stale_factor_warning_is_written_to_the_diagnostics_file) use a raising optimiser and never
reach the status.updated branch; keep them.
Docs: autofit/graphical/README.md §3.5 lines 244-246 — "reproduces the collapse under a Laplace
projection" → "reproduces the stale-factor state (every site update rejected, scatter returned at
its prior) under a Laplace projection" (the phase-1 wording error, already fixed in the workspace
by autofit_workspace_test#97). Add one sentence to the STALE FACTORS paragraph (~line 189) that a
fully reverted projection now counts as skipped.
Activity
Jammy2211 commentedon Sep 7, 2026
Library PR Created
feature/ep-full-revert-not-updated, labelpending-release)API changes: none to existing signatures.
MeanField.check_changed(other)is a new public helper;update_factor_mean_fieldkeeps its signature and itssuccesssemantics.Workspace impact: none — no API change. Verified on this branch from
autofit_workspace_test:scripts/graphical/analytic_gaussian_collapse.pyCOLLAPSE CONFIG: PASS (5/5 seeds), RECOVER 5/5, STALE 0/5, σ/μ identical to the phase-2 record. The per-factorep_history.csvflag tallies shift, because the flag now means "moved" rather than "valid after the revert" (seed 0 HierarchicalFactor BAD_PROJECTION 8 / FAILURE 1 / SUCCESS 1, was 9 / 0 / 5).Tests:
test_autofit/graphical268 passed (265 + 3 new; 270 with #1573 cherry-picked on top),test_autofit/messages93 passed, run in the task worktree. Control: the two new full-revert cases fail without the source fix, and the partial-revert case passes either way.Implementation note: the comparison is on
natural_parameters(), not the rawparametersthe prototype used —TransformedMessage(what the live EP path carries) has noparametersattribute, and natural parameters are the spaceupdate_invalidcopies from, so exact equality still holds.Worked as member B of the
ep-phase2-reviewbundle (siblings #1569, #1570).Jammy2211 commentedon Sep 7, 2026
Shipped
4e6a160dcceb6defae77ba02361908ee7fb8b6ad(head02763895)02763895):Tests [pull_request]run 34163175828 —unittest (3.12),unittest (3.13),unittest-nojaxall success;Docs [pull_request]run 34163175817 success. mergeStateStatus CLEAN.autofit/graphical/mean_field.py(+36/-9)autofit/graphical/README.md(+9/-5)test_autofit/graphical/functionality/test_factor_failure_recovery.py(+100/-0)MeanField.update_factor_mean_fieldre-evaluatedcheck_valid()afterupdate_invalid(last_dist)— true by construction — so a projection that reverted every parameter still returnedupdated=Trueand never reached_stale_factor_warnings. It now compares the reverted message tolast_distper variable on natural parameters (MeanField.check_changed, exact): nothing changed = skipped, with an explicit status message; partial reverts still count as updates. README §3.5 now says the minimal Laplace EP reaches the stale-factor state rather than a collapse, and the STALE FACTORS paragraph notes full reverts count as skipped.Verdict: two new tests fail without the fix (one pins the partial-revert half); graphical 268 pass (270 with #1573);
analytic_gaussian_collapse.pyRECOVER 5/5, STALE 0/5, σ/μ identical — per-factor flag tallies shift because the flag now means "moved".Remaining: partial reverts (the campaign graph's scatter reverting every sweep while other variables update) are still reported as updated — filed as
draft/feature/autofit/ep_stale_tracking_per_variable.md.