Skip to content

fix(ep): fixed-point projections are not stale #1579

Closed

Description

@Jammy2211

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 changed signal mean "this update accepted this variable's projection", derived from projection validity rather than from numerical movement.
  • Leave the updated flag 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_variables column.
  • Full test_autofit/graphical suite 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

  1. autofit/graphical/mean_field.py, valid branch of the factor update (~L580-584): replace changed = factor_dist.check_changed(last_dist) if last_dist is not None else None with an all-True VariableData({v: True for v in factor_dist}) — an accepted projection accepts every variable, and a fixed point is not a rejection. This also removes the last_dist is None hole so first-sweep updates are counted.
  2. autofit/graphical/mean_field.py, invalid branch (~L545-560): build the mask from the check_valid() result already computed at ~L545, before update_invalid runs: {v: bool(np.all(ok)) for v, ok in valid.items()}. Unchanged-after-revert is no longer the signal.
  3. 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 as updated, which is the correct reading.
  4. autofit/graphical/expectation_propagation/optimiser.py (~L403-406 _variables_changed accumulation, ~L498-514 _stale_factor_warnings) and autofit/graphical/expectation_propagation/diagnostics.py (~L145-156 reverted_variables column): no code change expected; verify they read Status.changed only.
  5. 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: two ExactFactorFit Gaussian factors on one variable (make_shared_variable_approx idiom), run EP to convergence, restart EP from the converged EPMeanField for several sweeps, assert _stale_factor_warnings() == [], every history row has flag == SUCCESS, and the reverted_variables column is empty on every row.
  6. Run pytest test_autofit/graphical -q inside 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_changed accumulation and _stale_factor_warnings.
  • autofit/graphical/expectation_propagation/diagnostics.py — reverted_variables writer.
  • 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 empty reverted_variables column 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

  1. Jammy2211 commented on Sep 8, 2026

    @Jammy2211
    CollaboratorAuthor

    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.

  2. Jammy2211 commented on Sep 8, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged in #1580. Status.changed now tracks whether each variable's projection was accepted, rather than whether its message changed bit-exactly, so EP restarted from its own converged EPMeanField no longer emits STALE FACTORS for every factor or fills the reverted_variables column of ep_history.csv while every update reports SUCCESS; the numerical comparison stays on updated, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions