Repository navigation
fix: raise on unsupported unconstrained space transform - #1886
Conversation
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.
| # 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 13366 +13
==========================================
+ Hits 11736 11749 +13
Misses 1617 1617
Flags with carried forward coverage won't be shown. Click here to find out more.
|
dgedon
left a comment
There was a problem hiding this comment.
Looks good. What about the mixed net or vector field net builders? Do they just raise these issues downstream when instantiating the flow or mdn?
We should also open an issue to actually solve the issue with your proposed long term solution.
thanks for the review @dgedon , for MNLE/MNPE it's okay because they just pass on the kwargs to the parent functions that handle it. Vector field net builders were missing though, fixed now. |
c2a367f to
f35b75f
Compare
see #1885 for details.
This PR makes sure we raise warning in all user paths.