Skip to content

fix: reject out-of-prior proposals in the Gaussian mixture reference sampler - #2100

Merged
janfb merged 2 commits into
mainfrom
fix-gaussian-mixture-true-posterior
Oct 27, 2026
Merged

janfb merged 2 commits into
mainfrom
fix-gaussian-mixture-true-posterior

Conversation

@janfb

@janfb janfb commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

samples_true_posterior_gaussian_mixture_uniform_prior rejected proposals outside the prior via prior.log_prob(sample) == -inf. With torch argument validation on, log_prob raises instead, so the sampler crashed for observations near the prior bound (e.g. observation 2 in the L-C2ST tutorial). It now checks prior.support directly.

This also removes the validation workaround that #1987 added to the L-C2ST tutorial.

janfb added 2 commits October 26, 2026 11:43
…thout log_prob

samples_true_posterior_gaussian_mixture_uniform_prior used prior.log_prob to detect proposals outside the uniform prior. With torch argument validation on (the default), log_prob raises a ValueError for such values instead of returning -inf, so the sampler failed for observations near the prior bound.

The sampler now checks the prior's support directly.
The true-posterior sampler for the Gaussian mixture no longer raises for proposals outside the prior, so the tutorial no longer needs to turn off torch argument validation around it.
@janfb
janfb requested a review from satwiksps October 26, 2026 10:54
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd5cf924-8fc0-4db1-aa1b-5972e5a1c934
Commits

Reviewing files that changed from the base of the PR and between e1a652e and d35d6a2.

Files selected for processing: 2
  • docs/advanced_tutorials/13_diagnostics_lc2st.ipynb
  • sbi/simulators/gaussian_mixture.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Walkthrough

The changes update prior-support checking in Gaussian-mixture posterior rejection sampling and revise the diagnostics tutorial to call the true-posterior sampler directly for each observation.

Changes: Posterior sampling

Layer / File(s) Summary
Check prior support during rejection sampling
sbi/simulators/gaussian_mixture.py
The bounds check uses the prior distribution’s support check instead of summed prior log probability.
Call the true-posterior sampler in the tutorial
docs/advanced_tutorials/13_diagnostics_lc2st.ipynb
The reference-sample loop calls the true-posterior sampler directly for each observation. It no longer changes PyTorch’s global argument-validation setting.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: bharath0153

Merge Risk: Minimal · up to d35d6

No merge-blocking risk was identified in the sampler or tutorial changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description clearly explains the bug, the cause, and the fix. However, it omits the required issue status, additional notes, checklist, and AI-assistance disclosure sections. Add the template sections for issue linkage, additional information, and the checklist. Mark applicable checklist items and state whether the PR closes an issue. Include the required AI-assistance disclosure if applicable.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: rejecting Gaussian mixture sampler proposals that fall outside the prior support.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.24%. Comparing base (e1a652e) to head (d35d6a2).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sbi/simulators/gaussian_mixture.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2100   +/-   ##
=======================================
  Coverage   90.24%   90.24%           
=======================================
  Files         142      142           
  Lines       14799    14799           
=======================================
  Hits        13355    13355           
  Misses       1444     1444           
Flag Coverage Δ
fast 86.18% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sbi/simulators/gaussian_mixture.py 44.44% <0.00%> (ø)

@janfb
janfb merged commit 19b4fe1 into main Oct 27, 2026
20 of 21 checks passed
@janfb
janfb deleted the fix-gaussian-mixture-true-posterior branch October 27, 2026 05:08
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.

2 participants