diff --git a/pymc_experimental/tests/distributions/test_discrete_markov_chain.py b/pymc_experimental/tests/distributions/test_discrete_markov_chain.py index c1458850..1056fbd5 100644 --- a/pymc_experimental/tests/distributions/test_discrete_markov_chain.py +++ b/pymc_experimental/tests/distributions/test_discrete_markov_chain.py @@ -18,7 +18,7 @@ def transition_probability_tests(steps, n_states, n_lags, n_draws, atol): P=pt.as_tensor_variable(P), init_dist=x0, steps=steps, n_lags=n_lags ) - draws = pm.draw(chain, n_draws) + draws = pm.draw(chain, n_draws, random_seed=172) # Test x0 is uniform over n_states for i in range(n_lags): diff --git a/pymc_experimental/tests/model_transform/test_conditioning.py b/pymc_experimental/tests/model_transform/test_conditioning.py index 9c5ff9b6..5d455e69 100644 --- a/pymc_experimental/tests/model_transform/test_conditioning.py +++ b/pymc_experimental/tests/model_transform/test_conditioning.py @@ -92,12 +92,13 @@ def test_observe_dims(): def test_do(): + rng = np.random.default_rng(seed=435) with pm.Model() as m_old: x = pm.Normal("x", 0, 1e-3) y = pm.Normal("y", x, 1e-3) z = pm.Normal("z", y + x, 1e-3) - assert -5 < pm.draw(z) < 5 + assert -5 < pm.draw(z, random_seed=rng) < 5 m_new = do(m_old, {y: x + 100}) @@ -106,7 +107,7 @@ def test_do(): assert m_new["y"] in m_new.deterministics assert m_new["z"] in m_new.free_RVs - assert 95 < pm.draw(m_new["z"]) < 105 + assert 95 < pm.draw(m_new["z"], random_seed=rng) < 105 # Test two substitutions with m_old: @@ -118,10 +119,10 @@ def test_do(): assert m_new["x"] not in m_new.deterministics assert m_new["z"] in m_new.free_RVs - assert 195 < pm.draw(m_new["z"]) < 205 + assert 195 < pm.draw(m_new["z"], random_seed=rng) < 205 with m_new: pm.set_data({"switch": 0}) - assert -5 < pm.draw(m_new["z"]) < 5 + assert -5 < pm.draw(m_new["z"], random_seed=rng) < 5 def test_do_posterior_predictive(): @@ -149,22 +150,24 @@ def test_do_posterior_predictive(): @pytest.mark.parametrize("mutable", (False, True)) def test_do_constant(mutable): + rng = np.random.default_rng(seed=122) with pm.Model() as m: x = pm.Data("x", 0, mutable=mutable) y = pm.Normal("y", x, 1e-3) do_m = do(m, {x: 105}) - assert pm.draw(do_m["y"]) > 100 + assert pm.draw(do_m["y"], random_seed=rng) > 100 def test_do_deterministic(): + rng = np.random.default_rng(seed=435) with pm.Model() as m: x = pm.Normal("x", 0, 1e-3) y = pm.Deterministic("y", x + 105) z = pm.Normal("z", y, 1e-3) do_m = do(m, {"z": x - 105}) - assert pm.draw(do_m["z"]) < 100 + assert pm.draw(do_m["z"], random_seed=rng) < 100 def test_do_dims(): diff --git a/pymc_experimental/tests/utils/test_model_fgraph.py b/pymc_experimental/tests/utils/test_model_fgraph.py index dcac53fa..0575a536 100644 --- a/pymc_experimental/tests/utils/test_model_fgraph.py +++ b/pymc_experimental/tests/utils/test_model_fgraph.py @@ -124,7 +124,7 @@ def test_data(inline_views): pm.set_data({"x": [100.0, 200.0]}, coords={"test_dim": range(2)}) assert m_new.dim_lengths["test_dim"].eval() == 2 - np.testing.assert_array_almost_equal(pm.draw(m_new["x"]), [100.0, 200.0]) + np.testing.assert_array_almost_equal(pm.draw(m_new["x"], random_seed=63), [100.0, 200.0]) @pytest.mark.parametrize("inline_views", (False, True))