fix: raise on unsupported unconstrained space transform#1886
Open
janfb wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent a silent misconfiguration where z_score_*="transform_to_unconstrained" is ignored by several non-Zuko builders, by introducing a shared guard that raises a clear error instead.
Changes:
- Added
assert_transform_to_unconstrained_supported()insbi.utils.sbiutilsand wired it into nflows flow builders, the MDN builder, ratio-classifier builders, and the unconditional Zuko flow builder. - Extended tests to assert that unsupported builders raise (instead of silently no-op-ing) and updated structured z-scoring tests accordingly.
- Documented the behavior change in the changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
sbi/utils/sbiutils.py |
Adds a shared guard to turn the silent no-op into a clear exception. |
sbi/neural_nets/net_builders/flow.py |
Calls the guard from nflows flow builders and the unconditional Zuko flow builder. |
sbi/neural_nets/net_builders/mdn.py |
Calls the guard from the MDN builder. |
sbi/neural_nets/net_builders/classifier.py |
Calls the guard from ratio-classifier builders. |
tests/sbiutils_test.py |
Adds/updates tests expecting an error for unsupported builder + option combinations. |
CHANGELOG.md |
Documents the new “raise instead of silent ignore” behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+498
to
+502
| # Unsupported combination: the modeled variable requests the unconstrained | ||
| # transform on a non-Zuko-conditional builder -> expect a clear ValueError. | ||
| if modeled_z == "transform_to_unconstrained" and not model.startswith("zuko"): | ||
| with pytest.raises(ValueError, match="transform_to_unconstrained"): | ||
| build_fun = build_fn(**kwargs) |
|
|
||
| * **Fix TARP z-scoring bug** ([#1832](https://github.com/sbi-dev/sbi/issues/1832)): Reference points are now z-scored alongside `thetas` and `posterior_samples` when `z_score_theta=True`, fixing incorrect distance calculations that masked bias detection. | ||
| * **Fix broken `biased_toy_gaussian` test helper**: Rewrote to create actual location bias (posterior mean shifted from truth) instead of the previous NaN-producing formula. | ||
| * **Raise on unsupported `transform_to_unconstrained` z-scoring**: `z_score_x="transform_to_unconstrained"` was silently ignored by the nflows builders (`maf`, `nsf`, `maf_rqs`, `made`), the MDN builder, the unconditional Zuko builder, and the ratio-based classifier builders (`linear`, `mlp`, `resnet`), producing a model with no reparametrization. These builders now raise a clear `ValueError`. The option remains supported by the conditional `zuko_*` models. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1886 +/- ##
==========================================
+ Coverage 87.89% 87.90% +0.01%
==========================================
Files 143 143
Lines 13353 13365 +12
==========================================
+ Hits 11736 11748 +12
Misses 1617 1617
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
fixes #1885