Skip to content

Commit 0a21509

Browse files
Jammy2211claude
authored andcommitted
fix(graphical): seed inherently-stochastic test_full_hierachical
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
1 parent ffc04d8 commit 0a21509

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test_autofit/graphical/hierarchical/test_hierarchical.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ def test_full_hierachical(data):
298298
},
299299
)
300300

301+
# This fits a *marginal* hierarchical EP model whose Laplace refinement draws
302+
# stochastic samples from the global np.random state (n_refine=3 via
303+
# NormalMessage.sample). The fit sits near a convergence boundary, so its
304+
# recovered fixed point (good vs sigma-collapse) depends on the ambient RNG
305+
# state left by whatever ran before — an inherently stochastic test. Seed here
306+
# so the fit is reproducible; this is the pragmatic fix (see PyAutoFit #1352).
307+
np.random.seed(0)
308+
301309
laplace = graph.LaplaceOptimiser()
302310
ep_opt = graph.EPOptimiser(model, default_optimiser=laplace)
303311
new_approx = ep_opt.run(model_approx, max_steps=10)

0 commit comments

Comments
 (0)