Skip to content

Refactor vector field potentials: add init() setup and PosteriorBuilder#1802

Open
rogueslasher wants to merge 5 commits intosbi-dev:mainfrom
rogueslasher:refactor/posterior-builder-init
Open

Refactor vector field potentials: add init() setup and PosteriorBuilder#1802
rogueslasher wants to merge 5 commits intosbi-dev:mainfrom
rogueslasher:refactor/posterior-builder-init

Conversation

@rogueslasher
Copy link

Summary

Introduce an explicit init() method for potentials to allow one-time setup
instead of relying on runtime caching.

Changes

  • Added no-op init() to BasePotential
  • Implemented init() in VectorFieldBasedPotential to warm iid/guidance caches
  • Added PosteriorBuilder with with_iid() and with_guidance()
  • Updated VectorFieldPosterior to support builder pattern
  • Added tests for PosteriorBuilder and init() separation

Tests

All tests pass locally. One test is marked xfail intentionally because the
behavior is expected to fail by design.

Closes #1783

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 25.45455% with 41 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@7d66b89). Learn more about missing BASE report.
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sbi/inference/posteriors/vector_field_posterior.py 27.02% 27 Missing ⚠️
sbi/inference/potentials/vector_field_potential.py 6.66% 14 Missing ⚠️

❌ Your patch check has failed because the patch coverage (25.45%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1802   +/-   ##
=======================================
  Coverage        ?   86.70%           
=======================================
  Files           ?      142           
  Lines           ?    13125           
  Branches        ?        0           
=======================================
  Hits            ?    11380           
  Misses          ?     1745           
  Partials        ?        0           
Flag Coverage Δ
fast 82.47% <25.45%> (?)

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

Files with missing lines Coverage Δ
sbi/inference/potentials/base_potential.py 93.10% <100.00%> (ø)
sbi/inference/potentials/vector_field_potential.py 81.75% <6.66%> (ø)
sbi/inference/posteriors/vector_field_posterior.py 66.66% <27.02%> (ø)

@rogueslasher
Copy link
Author

The codecov patch failure is expected. The new code paths PosteriorBuilder.sample(), PosteriorBuilder.log_prob(), and VectorFieldBasedPotential.init() are all covered by the slow tests in tests/test_posterior_builder.py which require a trained NPSE model. These are marked @pytest.mark.slow and don't run in CI's fast test suite.The fast test test_base_potential_init_is_noop covers the BasePotential change (93.1%). Happy to add mock-based fast tests for the remaining lines if preferred.

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.

Improve vector field adaptors to not require caching

1 participant