Skip to content

docs: added code examples in potential class docstring#1820

Open
Jocho-Smith wants to merge 1 commit intosbi-dev:mainfrom
Jocho-Smith:add-potential-docstring-examples
Open

docs: added code examples in potential class docstring#1820
Jocho-Smith wants to merge 1 commit intosbi-dev:mainfrom
Jocho-Smith:add-potential-docstring-examples

Conversation

@Jocho-Smith
Copy link
Contributor

@Jocho-Smith Jocho-Smith commented Mar 18, 2026

This PR is inspired by #1763

In preparation of GSoC Project Idea 3 I investigated into the potential functions and wrote minimal examples to try them out.

Is it appreciated if we add these examples in the class docstrings? In the same way it appeared in #1534, this would enhance API references on the docs website.

Pre-commit hooks and fast tests passed
(sbi) schmidt@node-63:~/gsoc2026/sbi$ pre-commit run --all-files
ruff.....................................................................Passed
ruff-format..............................................................Passed
check for added large files..............................................Passed
check for merge conflicts................................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
trim trailing whitespace.................................................Passed

(update: I just realized I could have just run pytest -m "not slow and not gpu", there was no need for --bm)

(sbi) schmidt@node-63:~/gsoc2026/sbi$ pytest --bm
....................                                     [100%]
====================== mini SBIBM results ======================
Amortized inference:
          gaussian_linear  linear_mvg_2d     slcp     two_moons  
-----------------------------------------------------------------
FMPE{}         0.608           0.525        0.950       0.799    
NLE_A{}        0.565           0.570        0.888       0.637    
NPE_C{}        0.558           0.637        0.950       0.789    
NPSE{}         0.635           0.512        0.904       0.733    
NRE_B{}        0.605           0.514        0.954       0.812    
20 passed in 844.00s (0:14:04)

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.86%. Comparing base (3c60a97) to head (7445561).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1820   +/-   ##
=======================================
  Coverage   87.86%   87.86%           
=======================================
  Files         140      140           
  Lines       12726    12726           
=======================================
  Hits        11182    11182           
  Misses       1544     1544           
Flag Coverage Δ
fast 82.72% <ø> (?)

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

Files with missing lines Coverage Δ
...inference/potentials/likelihood_based_potential.py 82.10% <ø> (ø)
.../inference/potentials/posterior_based_potential.py 90.90% <ø> (ø)
sbi/inference/potentials/ratio_based_potential.py 100.00% <ø> (ø)

@Jocho-Smith
Copy link
Contributor Author

I could also do that for the methods listed here: https://sbi.readthedocs.io/en/latest/api_reference/potentials.html

@dgedon dgedon self-requested a review March 19, 2026 15:39
Copy link
Collaborator

@dgedon dgedon left a comment

Choose a reason for hiding this comment

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

I believe this is a very good start for the GSoC 2026 project 3 to get an overview. However, there are some issues:

  • in the API reference we list the likelihood_estimator_based_potential function instead of the LikelihoodBasedPotential where your current examples are located. So they are never shown in the API reference
  • more critical: the potentials are mostly used internally and have limited user-facing interaction. So examples have limited value
  • With the re-design of the potential function, these examples would need a re-design as well.

Because of the second point, I think this PR is nice-to-have.

Changes that are necessary:

  • add examples to the right location
  • point out that the potentials can then be used for MCMC sampling, VI, ...

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.

2 participants