Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make GP latent vs marginal test deterministic#8006

Merged
ricardoV94 merged 1 commit intopymc-devs:mainfrom
Jiya873:test-gp-seed-determinism
Jan 26, 2026
Merged

Make GP latent vs marginal test deterministic#8006
ricardoV94 merged 1 commit intopymc-devs:mainfrom
Jiya873:test-gp-seed-determinism

Conversation

@Jiya873
Copy link
Contributor

@Jiya873 Jiya873 commented Dec 16, 2025

Fixes #8000

@maresb
Copy link
Contributor

maresb commented Dec 20, 2025

Looks good @Jiya873 ! Could you please share the seed you found that makes this fail? That would be useful to note for reference.

@codecov
Copy link

codecov bot commented Dec 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.49%. Comparing base (cadb97a) to head (756e02b).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8006      +/-   ##
==========================================
+ Coverage   90.22%   91.49%   +1.27%     
==========================================
  Files         116      116              
  Lines       18972    18972              
==========================================
+ Hits        17117    17359     +242     
+ Misses       1855     1613     -242     

see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jiya873
Copy link
Contributor Author

Jiya873 commented Dec 20, 2025

First, I created a reproduction script and found that the assertion fails immediately at the first iteration.

import numpy as np
import pymc as pm
import pytensor.tensor as pt
import numpy.testing as npt
from tqdm import tqdm

def run_reproduction(seed):
    rng = np.random.RandomState(seed)
    n_outputs = 2
    X = rng.randn(20, 3)
    y = rng.randn(n_outputs, 20)
    Xnew = rng.randn(30, 3)
    pnew = rng.randn(n_outputs, 30)

    with pm.Model() as latent_model:
        cov_func = pm.gp.cov.ExpQuad(3, [0.1, 0.2, 0.3])
        mean_func = pm.gp.mean.Constant(0.5)
        latent_gp = pm.gp.Latent(mean_func=mean_func, cov_func=cov_func)
        latent_f = latent_gp.prior("f", X, n_outputs=n_outputs, reparameterize=True)
        latent_p = latent_gp.conditional("p", Xnew)

    with pm.Model() as marginal_model:
        cov_func = pm.gp.cov.ExpQuad(3, [0.1, 0.2, 0.3])
        mean_func = pm.gp.mean.Constant(0.5)
        marginal_gp = pm.gp.Marginal(mean_func=mean_func, cov_func=cov_func)

        marginal_f = marginal_gp.marginal_likelihood("f", X, y, sigma=0.0)
        marginal_p = marginal_gp.conditional("p", Xnew)

    lp_latent = latent_p.eval({latent_f: y})
    lp_marginal = marginal_p.eval()

    npt.assert_allclose(lp_latent, lp_marginal, rtol=1e-4)

if __name__ == "__main__":
    iterations = 500    
    for i in tqdm(range(iterations)):
        try:
            run_reproduction(seed=i)
        except AssertionError as e:
            print(f"\nCaught failure at seed: {i}")
            print(e)
            break

I reproduced the failure locally using seed 0.

@ricardoV94 ricardoV94 added tests no releasenotes Skipped in automatic release notes generation labels Jan 26, 2026
@ricardoV94 ricardoV94 merged commit 793362b into pymc-devs:main Jan 26, 2026
26 checks passed
@welcome
Copy link

welcome bot commented Jan 26, 2026

Congratulations Banner]
Congrats on merging your first pull request! 🎉 We here at PyMC are proud of you! 💖 Thank you so much for your contribution 🎁

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

Labels

no releasenotes Skipped in automatic release notes generation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: Strange flakiness in TestMarginalVsLatent GP test on Windows

3 participants

Comments