Fix numpyro wrongly conditioning on non-sample sites #58
Merged
aloctavodia merged 4 commits intoMay 26, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #58 +/- ##
==========================================
+ Coverage 94.63% 94.79% +0.15%
==========================================
Files 3 3
Lines 261 288 +27
==========================================
+ Hits 247 273 +26
- Misses 14 15 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes test
test_sbc_numpyro_fail_no_observed_variable. The expected behavior is to raise an ValueError since there is no actual observed variable to condition on.Factor sites in numpyro is classified as a observed site when the criterion is the existence of
is_observedattr.This means the prior predicitve draw will output Factor sites values for the model to condition on. This is however not only against the user's intention as the provided model function itself does not have the corresponding args, which would yield a TypeError, we also can't supply observed data to factor sites.
The previous test was failing silently as the try except block below catches the error raised in
_get_posterior_samples_numpyroon the first iteration, making theself.simulationsdict empty, in turn raising another error when attempting to stack an empty array in thefinallyblock, which is conveniently also an ValueError. And the negative test, see that an error is raised and interpreted the eerror handling as correct.simuk/simuk/sbc.py
Lines 316 to 333 in 6ed2d1c