Skip to content

fix: raise on unsupported unconstrained space transform#1886

Open
janfb wants to merge 1 commit into
mainfrom
fix/transform-to-unconstrained-guard
Open

fix: raise on unsupported unconstrained space transform#1886
janfb wants to merge 1 commit into
mainfrom
fix/transform-to-unconstrained-guard

Conversation

@janfb

@janfb janfb commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

fixes #1885

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

* **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 (a7f115c) to head (c2a367f).
✅ 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    13365      +12     
==========================================
+ Hits        11736    11748      +12     
  Misses       1617     1617              
Flag Coverage Δ
fast 81.39% <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/utils/sbiutils.py 88.42% <100.00%> (+0.10%) ⬆️

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.

bug: transform_to_unconstrained z-scoring is a silent no-op for nflows flows

2 participants