You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documented init_method "prior" is not implemented in posterior.map() #2092
The map() method documents init_method as one of posterior or prior, but the value prior is never handled.
In _calculate_map (sbi/inference/posteriors/base_posterior.py, lines 276 to 283), only three cases are covered:
init_method == "posterior"
init_method == "proposal"
init_method is a Tensor
Any other value, including the documented prior, falls through to a bare raise ValueError on line 283 that carries no message.
As a result, the documented call post.map(init_method="prior") fails on every posterior with an empty ValueError. A search for init_method == "prior" across the package returns no matches, confirming the branch does not exist.
Initialising the MAP optimisation from prior samples is useful when the posterior is leaky or slow to sample from, so the documented behaviour is worth supporting.
I would be glad to open a pull request that adds the prior branch (drawing the initial samples from self.prior), corrects the docstrings, and gives the two bare ValueError raises informative messages.
The prior branch was missing from _calculate_map in base_posterior.py. So init_method="prior" fell through to the bare raise ValueError at the end. This change adds the branch. It draws starting points from self.potential_fn.prior. The ValueError now lists the valid values. Not tested: no existing test covers this code path. A pull request follows.
@alibb007 thanks for the work on this. @SahilKumar75 reported the bug in issue #2092 and offered the PR there, before this PR was opened. Please follow out Code of Conduct and our contribution guideline, e.g., in this case: respect each others work and wait for maintainer reply under an issue before opening a PR.
I will close PR #2093 and leave the fix to SahilKumar75.
@SahilKumar75 thanks for the clear report, and for the friendly note on the overlap. I closed PR #2093, so please go ahead with your PR.
I checked the history: "prior" is a stale docstring. In 2022 we renamed the option to "proposal" in the code and missed the docstrings. For MCMC, rejection and importance sampling posteriors, the proposal is the prior unless the user passes another one, so init_method="proposal" already does what the docstring promises. So we don't need a new "prior" option.
Please fix the docstrings of all map() methods, so each lists the options that posterior supports, and replace the bare errors with messages that list them. The direct, vector field and ensemble posteriors have no proposal, so "proposal" should fail there with such a message as well. Starting points from the prior still work everywhere by passing prior samples as a tensor; the docstring can say that.
Went with your approach, no new "prior" option: fixed each posterior's docstring to match what it supports, made "proposal" error clearly where there's no proposal (direct, vector field, ensemble), and noted prior samples work as a tensor. Tests added.
Activity
alibb007 commentedon Oct 26, 2026
The
priorbranch was missing from_calculate_mapinbase_posterior.py. Soinit_method="prior"fell through to the bareraise ValueErrorat the end. This change adds the branch. It draws starting points fromself.potential_fn.prior. TheValueErrornow lists the valid values. Not tested: no existing test covers this code path. A pull request follows.SahilKumar75 commentedon Oct 26, 2026
Hey, thanks for picking this up, @alibb007.
I mentioned back in #2092 that I'd open a PR for this and had one ready to go. Mine also covers a couple of things this one doesn't:
EnsemblePosterior.map, which is missing the same branchinit_method="prior"and for the invalid caseI'm happy to push mine or just review this one, whatever works best for you, @janfb and @michaeldeistler.
Just flagging two gaps in case this PR moves ahead:
EnsemblePosterior.mapstill raises an error.janfb commentedon Oct 27, 2026
@alibb007 thanks for the work on this. @SahilKumar75 reported the bug in issue #2092 and offered the PR there, before this PR was opened. Please follow out Code of Conduct and our contribution guideline, e.g., in this case: respect each others work and wait for maintainer reply under an issue before opening a PR.
I will close PR #2093 and leave the fix to SahilKumar75.
cheers, Jan
janfb commentedon Oct 27, 2026
@SahilKumar75 thanks for the clear report, and for the friendly note on the overlap. I closed PR #2093, so please go ahead with your PR.
I checked the history:
"prior"is a stale docstring. In 2022 we renamed the option to"proposal"in the code and missed the docstrings. For MCMC, rejection and importance sampling posteriors, the proposal is the prior unless the user passes another one, soinit_method="proposal"already does what the docstring promises. So we don't need a new"prior"option.Please fix the docstrings of all
map()methods, so each lists the options that posterior supports, and replace the bare errors with messages that list them. The direct, vector field and ensemble posteriors have no proposal, so"proposal"should fail there with such a message as well. Starting points from the prior still work everywhere by passing prior samples as a tensor; the docstring can say that.cheers, Jan
SahilKumar75 commentedon Oct 27, 2026
Went with your approach, no new "prior" option: fixed each posterior's docstring to match what it supports, made "proposal" error clearly where there's no proposal (direct, vector field, ensemble), and noted prior samples work as a tensor. Tests added.
test: test the issue's init_method='prior' call; shorten the VI hook …
fix: list each posterior's map() init_method options and raise clear …