Repository navigation
Description
Overview
The nightly PyAutoHeart workspace-validation.yml run is RED on a single cell, run_scripts (3.12, autolens, guides), because autolens_workspace/scripts/guides/modeling/advanced/expectation_propagation.py crashes during expectation propagation with autofit.exc.MessageException: NormalMessage sigma cannot be negative. It is stochastic/unseeded (sigma=-0.016 on 2026-07-13, sigma=-0.17 on 2026-07-11), so the negative width is produced inside the EP message-passing algebra, not by a fixed model mistake. The fix belongs in the PyAutoFit library — the user-facing guide must keep exercising the real EP path (no seeding / no autoimmunity).
Plan
- Reproduce the crash locally with a fixed seed that forces the negative-variance EP branch; capture the exact frame constructing a strict
NormalMessagefrom a negative-precision/variance message. - Determine whether (a) the EP path should route that construction through
NaturalNormal/update_invalidso a transient negative-variance cavity is tolerated or damped, or (b) the projection/inversion feedingsigmahas a sign/validity bug. - Implement the minimal library fix in
autofit/graphical/expectation_propagationand/orautofit/messages/normal.py; keep the strictassert_sigma_non_negativeguard intact for the genuine prior-passing misuse it was added for. - Correct the now-misleading
RelativeWidthModifierhint in the exception text (that path alreadyabs()-guards and cannot emit a negative sigma). - Add a regression test under
test_autofit/graphical/driving an EP update through a negative-variance cavity without raising. - Validate: full
test_autofit/green (3.12/3.13), smoke the EP guide script, Heart readiness. The guide script is not modified.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: feature/ep-negative-sigma-crash
Root cause (grounded)
- The guard
assert_sigma_non_negative(autofit/messages/normal.py:45) rejectssigma < 0at strictNormalMessage.__init__(normal.py:110). It was added deliberately for the prior-passing misuse case and is load-bearing there — do not delete it. - Its error hint blames
RelativeWidthModifier, but that is stale for this path:RelativeWidthModifier.__call__already returnsvalue * abs(mean)(autofit/mapper/prior/width_modifier.py:110, Priors & messages: 9 confirmed bugs — guidance wanted on 5 decisions #1331 D5), so it cannot emit a negative sigma. - EP legitimately produces intermediate messages with negative/infinite variance (cavity division of Gaussians). The correct vehicle already exists:
NaturalNormal(normal.py:508), which permitseta2 in (-inf, 0)and bypasses the guard viaAbstractMessage.__init__. The bug is that somewhere on the EP/declarative path a strictNormalMessageis built from a negative-variance state where aNaturalNormalshould be used (or the projection/inversion that yields the passedsigmahas a sign/validity bug).
Implementation Steps
- Reproduce: run the EP guide (or a minimal EP factor-graph) under a seed forcing a negative-variance cavity; capture the traceback frame that calls strict
NormalMessage(mean, sigma). - Inspect
autofit/graphical/expectation_propagation/ep_mean_field.py(cavityprod/division ~L196-222,rescale~L447) andfactor_optimiser.py(calc_exact_update/calc_exact_projection). - Route the offending construction through
NaturalNormal/AbstractMessage.update_invalid(abstract.py:346), or correct the inversion sign — narrowest change that unblocks EP without weakening the prior-passing guard. - Fix the misleading
RelativeWidthModifierhint in the exception atnormal.py:48. - Add a regression test in
test_autofit/graphical/that drives an EP update through a negative-variance cavity without raising; keep an assertion that strictNormalMessage(sigma<0)still raises for the prior-passing case. - Run
python -m pytest test_autofit/(3.12 + 3.13); smoke the EP guide script; confirm Heart readiness.
Key Files
autofit/messages/normal.py— strictNormalMessageguard (L45/L110) vsNaturalNormal(L508); exception hint (L48).autofit/graphical/expectation_propagation/ep_mean_field.py— cavity build / division / rescale.autofit/graphical/expectation_propagation/factor_optimiser.py— exact update/projection.autofit/messages/abstract.py—update_invalid(L346),from_natural_parameters(L173),project(L266).test_autofit/graphical/— new regression test.
Trade-off
Preserve the strict sigma<0 guard for prior passing; only tolerate/damp negative-variance messages on the EP natural-parameter seam. Keep the change minimal.
Evidence
PyAutoHeart workspace-validation runs 29227574734 (2026-07-13) and 29153442364 (2026-07-11). Related history: #1331 / #1348 (sigma<=0 semantics, point-mass idiom).
Original Prompt
Click to expand starting prompt
Type: bug · Target: autofit · Repo: PyAutoFit · Difficulty: medium · Autonomy: safe
The nightly PyAutoHeart workspace-validation.yml run is RED on run_scripts (3.12, autolens, guides) because the EP guide script crashes with NormalMessage sigma cannot be negative (sigma=-0.016 on 2026-07-13, sigma=-0.17 on 2026-07-11 — stochastic/unseeded). Root cause: the sigma<0 guard (normal.py:45) is load-bearing for prior passing, but RelativeWidthModifier already abs()-guards, so the EP crash comes from the message-passing algebra producing a negative-variance message that is wrapped as a strict NormalMessage instead of NaturalNormal. Fix in the PyAutoFit library (graphical + messages/normal.py), not the workspace guide (no autoimmunity). Fix the stale RelativeWidthModifier hint; add an EP regression test.
Activity
Jammy2211 commentedon Jul 13, 2026
--autorun — parked at ship sign-off (supervised checkpoint)The fix is implemented and gated, but the effective autonomy level is supervised (the
bugwork-type cap overrides the prompt'ssafeheader:min(safe, supervised) = supervised), so the PR-open is a human checkpoint rather than an unattended ship.What was done — root cause pinned by deterministic reproduction: the EP guide's
HierarchicalFactordrawsmass.slopefromGaussianPrior(mean, sigma)whosesigmais a truncated hyper-prior (lower_limit=0). EP's factor optimiser evaluates at proposed scales that dip just below 0;Factor.__call__then builtGaussianPrior(sigma<0), tripping the strictNormalMessageguard and crashing. Fix (24 insertions, library-only):Factor.__call__catchesexc.MessageExceptionand returns-inf(an out-of-support distribution has zero density — correct EP semantics); the strict guard is untouched; the staleRelativeWidthModifierhint is corrected; a deterministic regression test is added. Committed locally asa6aae649fonfeature/ep-negative-sigma-crash(not pushed).Four-leg gate:
test_autofit/= 1473 passed, 1 skipped (in-worktree).test_full_hierachicalfails only in isolation (order/RNG-sensitive, pre-existing onmain— identical value with the fix stashed); passes in the in-order suite.smoke_tests.txtsubset (stated fact, not grown). As targeted validation the actual failing guide (guides/modeling/advanced/expectation_propagation.py) is being run end-to-end against the branch; it is past the former ~4.7s crash point and into the Nautilus EP factor fits with zeroMessageExceptionmarkers.except, correct zero-density semantics, no public-API change, guard intact, deterministic test.test_run NOT ready (3 failed)dated 2026-07-09 (stale evidence) + 58 stale parked scripts. Both are organism-scope and unrelated to this branch. Not acknowledged at launch.Fork — needs a human decision: Heart YELLOW's reason set was not acknowledged at launch, and the ship sign-off is a supervised checkpoint. To ship: (a) acknowledge the YELLOW reason set (stale
test_run+ stale parked scripts) as unrelated to this branch, and (b) authorize PR-open. On approval → pushfeature/ep-negative-sigma-crashand open the pending-release PR (merge still stays human). On hold → the branch stays committed-but-unpushed here.Recommendation: ship — legs 1 & 3 are clean, the YELLOW reasons are stale organism-scope evidence with no bearing on a localized EP fix, and the guide is validating the branch live.
Jammy2211 commentedon Jul 13, 2026
Correct-mode validation (the fast smoke) + confirmation it's not a test-mode-only artifact
Good catch on test mode. The nightly runs the guide with
PYAUTO_TEST_MODE=1 PYAUTO_SMALL_DATASETS=1 PYAUTO_FAST_PLOTS=1(reduced real sampler, 15×15 datasets) — fast, seconds-to-a-minute. My earlier full-mode run (no flags, hours) was the wrong mode and is moot; the proper smoke is the guide in the nightly's mode:NormalMessage sigma cannot be negative, got sigma=-0.0705…, raised fromautofit.graphical.laplace.newton— the Laplace/Newton optimiser for the hierarchical factor.MeanFieldoutput).Is it a test-mode trigger? Test-mode's reduced iterations make the Laplace optimiser's coarser steps overshoot the scale hyper-prior's
lower_limit=0more readily — so the crash is far more frequent there. But it is a genuine code path, not a test-mode-only artifact: the scale posterior sits atmean≈0.0005(hard against the boundary), so the optimiser probes negative scales; a real run whose scale posterior is near zero can hit the same path. Returning-inffor an out-of-support distribution scale is the correct EP semantics in every mode, and it does not weaken the strictNormalMessageguard. The fix is validated end-to-end (both directions) in the exact mode the failure occurs.Jammy2211 commentedon Jul 13, 2026
Library PR created — #1364 (pending-release)
Shipped behind the human ship sign-off at the supervised checkpoint. PR: #1364
Gate: tests 1473p/1s (full
test_autofit/) · smoke base-crashes-vs-fix-clean in the nightly test-mode · review CLEAN · Heart YELLOW acknowledged as unrelated (staletest_run+ stale parked scripts).Workspace impact: none (option iii).
HierarchicalFactor's public API is unchanged; the change is internal toFactor.__call__plus an exception-message correction. No workspace migration needed.Merge stays human. The next nightly
workspace-validationwill independently confirm theautolens/guidescell is green once this is onmain.Jammy2211 commentedon Jul 13, 2026
Shipped — merged in #1364
Merged to
main(squash) 2026-07-13. The EP hierarchical-factor out-of-support scale now returns-infinstead of crashing; validated base-crash/fix-clean in the nightly test-mode. The nextworkspace-validationrun will confirm theautolens/guidescell green. Closing.