Skip to content

fix: raise on unsupported unconstrained space transform - #1886

Merged
janfb merged 2 commits into
mainfrom
fix/transform-to-unconstrained-guard
Jun 23, 2026
Merged

janfb merged 2 commits into
mainfrom
fix/transform-to-unconstrained-guard

Conversation

@janfb

@janfb janfb commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

see #1885 for details.

This PR makes sure we raise warning in all user paths.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in sbi.utils.sbiutils and 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 thread tests/sbiutils_test.py
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)
Comment thread CHANGELOG.md Outdated

* **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

codecov Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.90%. Comparing base (a5da86c) to head (f35b75f).
✅ All tests successful. No failed tests found.

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              
Flag Coverage Δ
fast 81.41% <100.00%> (?)

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

Files with missing lines Coverage Δ
sbi/neural_nets/net_builders/classifier.py 100.00% <100.00%> (ø)
sbi/neural_nets/net_builders/flow.py 96.84% <100.00%> (+0.07%) ⬆️
sbi/neural_nets/net_builders/mdn.py 100.00% <100.00%> (ø)
sbi/neural_nets/net_builders/vector_field_nets.py 94.02% <100.00%> (+0.01%) ⬆️
sbi/utils/sbiutils.py 88.42% <100.00%> (+0.10%) ⬆️

@dgedon dgedon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sbi/utils/sbiutils.py Resolved
@janfb

janfb commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

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.

@janfb
janfb requested a review from dgedon June 23, 2026 14:10
@janfb
janfb force-pushed the fix/transform-to-unconstrained-guard branch from c2a367f to f35b75f Compare June 23, 2026 14:11
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.

3 participants