Skip to content

docs: fix stale method names and defaults in inference docstrings - #2144

Open
aniketpandey05 wants to merge 5 commits into
sbi-dev:mainfrom
aniketpandey05:docs/fix-stale-docstrings
Open

aniketpandey05 wants to merge 5 commits into
sbi-dev:mainfrom
aniketpandey05:docs/fix-stale-docstrings

Conversation

@aniketpandey05

Copy link
Copy Markdown
Contributor

Fixes docstrings and an error message that refer to arguments, methods or defaults that no longer match the code.

  • BNRE.train() / NRE_C.train(): remove exclude_invalid_x from Args; neither method accepts it.
  • .map() error message (NeuralPosterior, VectorFieldPosterior): .self_default_x() -> .set_default_x().
  • MCMC init docs: the default num_candidate_samples is 10000 (not 1000), and resample is the default init strategy (not SIR).
  • ImportanceSamplingPosterior: SIR samples are drawn with .sample(method="sir"); .sir_sample() does not exist.
  • NeuralInference.__setstate__: __get_state__ -> __getstate__.

Found by checking docstrings against function signatures and defaults; each change verified by against the code.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This PR corrects posterior error guidance and documentation for SIR sampling, MCMC initialization, serialization, and trainer arguments. It also updates spacing and punctuation in error and warning messages. The summaries report no executable behavior or public signature changes.

Changes: Documentation and text corrections

Layer / File(s) Summary
Posterior API guidance
sbi/inference/posteriors/base_posterior.py, sbi/inference/posteriors/vector_field_posterior.py, sbi/inference/posteriors/importance_posterior.py
MAP error messages now direct callers to .set_default_x() and separate their sentences. SIR sampling documentation refers to sample(method="sir").
MCMC initialization documentation
sbi/inference/posteriors/mcmc_posterior.py, sbi/inference/posteriors/posterior_parameters.py, sbi/samplers/mcmc/init_strategy.py
The documented internal candidate-sample count is 10,000. The documentation identifies resample as the default strategy.
Trainer documentation
sbi/inference/trainers/base.py, sbi/inference/trainers/nre/bnre.py, sbi/inference/trainers/nre/nre_c.py
The serialization documentation names __getstate__(). The exclude_invalid_x descriptions were removed; the summaries report no signature or implementation changes.
Error and warning message text
sbi/analysis/tensorboard_output.py, sbi/inference/potentials/vector_field_potential.py, sbi/neural_nets/embedding_nets/causal_cnn.py, sbi/neural_nets/net_builders/flow.py, sbi/utils/torchutils.py
Spacing and punctuation were corrected in warning and error messages. The summaries report no changes to conditions or validation behavior.

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Other

Possibly related issues

  • sbi-dev/sbi#2121 — This PR corrects the .self_default_x() guidance in two posterior error messages. It does not address the issue’s separate EnsemblePosterior.map(individually=True) failure.

Suggested reviewers: janfb

Merge Risk: Minimal · up to e2075

This change corrects stale documentation and message wording, such as .set_default_x(), the SIR sampling method, and the MCMC initialization defaults. It does not change runtime behavior, so it is safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "docs: fix stale method names and defaults in inference docstrings" matches the main change. The PR corrects outdated method names (.self_default_x to .set_default_x, .sir_sample to sample(m…
Description check Passed The description states the purpose of the PR and lists each change with its file or method. It explains the verification method and gives the removed parameter, the corrected method names, and the cor…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "docs: fix stale method names and defaults in inference docstrings" matches the main change. The PR corrects outdated method names (.self_default_x to .set_default_x, .sir_sample to sample(method="sir"), get_state to getstate) and outdated defaults (num_candidate_samples 1000 to 10000, resample as default init strategy) in inference docstrings. The title also omits the spacing and grammar fixes in error messages, which is acceptable because the title does not need to cover every detail.

Full details: Description check

Explanation

The description states the purpose of the PR and lists each change with its file or method. It explains the verification method and gives the removed parameter, the corrected method names, and the corrected defaults. It does not fill the template's 'Does this close any issues?' section, and it does not complete the checklist or the AI-usage note. The 'checked against the code' sentence is missing the tool or verification detail ("verified by against the code" has a blank). The description covers the core content, so the check passes, but the author should fill the template sections and fix the blank word.

Resolution

Optionally: state whether any issues are closed (or write 'None'), complete the checklist items that apply (for example the pytest and pre-commit runs), and fix the blank in 'verified by against the code' so it names the verification method.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1fbd3ba3-e90d-4485-a7c8-712d4c60fdc3
Commits

Reviewing files that changed from the base of the PR and between 0365c22 and e207581.

Files selected for processing: 1

  • sbi/neural_nets/embedding_nets/causal_cnn.py
Files skipped from review as they are similar to previous changes: 1

  • sbi/neural_nets/embedding_nets/causal_cnn.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.06%. Comparing base (cd8f131) to head (e207581).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2144      +/-   ##
==========================================
- Coverage   90.69%   90.06%   -0.63%     
==========================================
  Files         142      142              
  Lines       14855    17733    +2878     
==========================================
+ Hits        13472    15971    +2499     
- Misses       1383     1762     +379     
Flag Coverage Δ
fast 87.49% <100.00%> (?)

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

Files with missing lines Coverage Δ
sbi/analysis/tensorboard_output.py 89.91% <ø> (ø)
sbi/inference/posteriors/base_posterior.py 94.73% <100.00%> (+1.58%) ⬆️
sbi/inference/posteriors/importance_posterior.py 89.18% <ø> (+5.85%) ⬆️
sbi/inference/posteriors/mcmc_posterior.py 88.91% <ø> (+1.32%) ⬆️
sbi/inference/posteriors/posterior_parameters.py 83.33% <ø> (ø)
sbi/inference/posteriors/vector_field_posterior.py 88.57% <ø> (+2.61%) ⬆️
sbi/inference/potentials/vector_field_potential.py 94.69% <ø> (-1.74%) ⬇️
sbi/inference/trainers/base.py 95.02% <ø> (+0.36%) ⬆️
sbi/inference/trainers/nre/bnre.py 97.29% <ø> (ø)
sbi/inference/trainers/nre/nre_c.py 98.00% <ø> (ø)
... and 4 more

... and 23 files with indirect coverage changes

@aniketpandey05

Copy link
Copy Markdown
Contributor Author

FAQ is out of date (docs/faq/question_01_leakage.md)

  • It recommends posterior.sample((num_samples,), x=x_o, sample_with_mcmc=True), but sample_with_mcmc no longer exists.
  • The quoted warning ("…switching to sample_with_mcmc=True") no longer matches the current one in rejection.py.

should i update that as well ?

another note a number of public docstring doesn't list all their args

@manuelgloeckler manuelgloeckler 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.

Thanks @aniketpandey05 — cleaning up stale docstring references is unglamorous but genuinely useful, and the self_default_x → set_default_x catch is one users would have hit.

Two notes, neither blocking. The spaces one is attached as an inline suggestion on both lines.

The .map() deprecation message still concatenates without a space

Since you're editing these exact lines anyway: the two adjacent string literals keep no space between them, so the emitted message reads ...has been deprecated.Use .set_default_x()to setx, ....

This appears in both copies:

  • sbi/inference/posteriors/base_posterior.py:392-393
  • sbi/inference/posteriors/vector_field_posterior.py:810-811

Pre-existing rather than introduced here, but it's a one-character fix in a spot you're already touching — see the two inline suggestions.

Stale MCMC guidance in the FAQ (follow-up, not this PR)

docs/faq/question_01_leakage.md:35 still shows:

samples = posterior((num_samples,), x=x_o, sample_with_mcmc=True)

sample_with_mcmc no longer exists anywhere under sbi/, so that snippet raises TypeError. Line 9 also quotes the old rejection-sampler warning, which sbi/samplers/rejection/rejection.py:430 has since rewritten to talk about leakage_correction_params / norm_posterior=False instead.

This file isn't in your diff and you already flagged it in the thread, so I'd leave it for a separate issue rather than widen this PR.

Nothing here needs to block the merge — happy to approve once you've had a look.

@manuelgloeckler manuelgloeckler 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.

Thanks @aniketpandey05 — this is the kind of cleanup that never gets prioritised, and stale docstrings are worse than missing ones because people trust them.

Two nits worth to incoperate, both non-blocking; the space one is attached as an inline suggestion on both occurrences.

  1. Missing space in the .map() deprecation message — base_posterior.py:392-393 and vector_field_posterior.py:810-811. The adjacent literals concatenate as ...has been deprecated.Use .set_default_x().... Pre-existing, but you're editing both lines anyway so it's a one-character fix.
  2. Stale MCMC guidance in the FAQ (follow-up, not this PR) — docs/faq/question_01_leakage.md:35 still shows posterior(..., sample_with_mcmc=True), which exists nowhere under sbi/, so the snippet raises TypeError. Line 9 also quotes the old rejection-sampler warning that sbi/samplers/rejection/rejection.py:430 has since rewritten to talk about leakage_correction_params / norm_posterior=False. You already flagged this yourself, so I'd file it separately rather than widen this diff.

aniketpandey05 and others added 3 commits November 12, 2026 22:09
docs: add missing space in .map() deprecation message

Co-authored-by: manuelgloeckler <38903899+manuelgloeckler@users.noreply.github.com>
docs: add missing space in .map() deprecation message

Co-authored-by: manuelgloeckler <38903899+manuelgloeckler@users.noreply.github.com>
@aniketpandey05

Copy link
Copy Markdown
Contributor Author

@manuelgloeckler thanks for the review, Applied both suggestions, While at it I checked the rest of sbi/ for the same issue and found it in 10 more error messages fixed them in one commit (0365c22), all one-space changes.

@aniketpandey05

Copy link
Copy Markdown
Contributor Author

@manuelgloeckler I also ran a spell check over sbi/ and found ~70 typos and small grammar slips in comments, docstrings and messages 'll open those as a separate PR, split by module so each stays small. thank you.

aniketpandey05 added a commit to aniketpandey05/sbi that referenced this pull request Nov 12, 2026

This branch has not been deployed

No deployments
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