Skip to content

fix(graphical): seed inherently-stochastic test_full_hierachical (#1352) - #1355

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/ep-hierarchical-regression
Jul 10, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/ep-hierarchical-regression

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Fixes the red Tests workflow on PyAutoFit main. test_autofit/graphical/hierarchical/test_hierarchical.py::test_full_hierachical is an inherently stochastic test that was failing deterministically at HEAD.

The test fits a marginal hierarchical EP model. The Laplace optimiser refines each factor with n_refine=3 stochastic samples drawn from the global np.random state (NormalMessage.sample → np.random.randn), so the recovered mu_logt hyperparameter converges to a good value or a sigma-collapsed one depending on the ambient RNG state left by whatever ran before the test. The test seeded np.random only before data generation, never before the fit.

When #1351 added test_autofit/graphical/functionality/test_ep_statistics_fixes.py (Monte-Carlo KL-direction tests that consume np.random), the ambient state going into the hierarchical fit shifted into a failing region — flipping the full-suite result from green (#1347, 2e33b175) to red (#1351/#1354). #1351's F1/F2/F4/F8 math is not implicated.

Fix

Seed np.random immediately before the fit so the test is reproducible. One line (+ explanatory comment); no library or API change.

API Changes

None — test-only change.

Validation

  • test_autofit/graphical/ — 216 passed, 0 failed
  • Full test_autofit/ — 1475 passed, 14 skipped, 0 failed (was 1474 passed / 1 failed at HEAD)

Notes

The underlying observation — EP/Laplace fits draw from global np.random, so results aren't fully reproducible across arbitrary process states (the fit also depends on variable-id ordering) — is documented on #1352. A controlled-RNG design was prototyped and reverted as out of proportion for a marginal stochastic test; seeding is the pragmatic fix per maintainer steer. Flagged there if reproducibility becomes a first-class requirement.

Closes #1352.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DgCFQoGUbVkspbCjRuKnHJ

test_full_hierachical fits a marginal hierarchical EP model whose Laplace
refinement (n_refine=3) draws samples from the global np.random state via
NormalMessage.sample, so its recovered mu_logt hyperparameter converges to a
good value or a sigma-collapsed one depending on the ambient RNG state left by
whatever ran before it. The test seeded np.random only before data generation,
not before the fit.

When #1351 added test_ep_statistics_fixes.py, its Monte-Carlo KL-direction
tests consumed np.random and shifted the ambient state into a failing region,
turning the Tests workflow red on main (green at #1347 -> red at #1351/#1354).
The fit's math is unchanged; this is a test-determinism fix. Seed np.random
immediately before the fit so the test is reproducible.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgCFQoGUbVkspbCjRuKnHJ
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Jul 10, 2026
@Jammy2211
Jammy2211 merged commit de6534d into main Jul 10, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/ep-hierarchical-regression branch August 25, 2026 18:13
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_full_hierachical flaky — hierarchical EP lands at wrong mu_logt

1 participant