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
API changesThis impacts the public API of the project (e.g. inference class).architectureInternal structure and design of the codebasebugSomething isn't workinghackathonFor our in-person hackathons with maintainers present, not a general up-for-grabs listposteriorsPosterior classes and their sampling interface
@janfb went through the current code and all four points still hold, though some have moved:
NeuralPosterior (base_posterior.py:39) is not an ABC. It uses abstractmethod on sample (:133) and sample_batched (:157) but does not inherit from abc.ABC, so the decorators are inert. I checked at runtime: instantiating it succeeds, and you only get a confusing error later when the method is actually called.
The class docstring (:40) advertises log_prob(), but the base class has no such method. Every concrete posterior implements it (Direct, MCMC, VI, Rejection, Importance, Ensemble, VectorField, FilteredDirect; NPE_A inherits Direct), so the base is simply lying about its interface.
sample and sample_batched still disagree on parameter order. Base declares sample(sample_shape, x=None, show_progress_bars=True, **kwargs), while DirectPosterior.sample (:146) inserts max_sampling_batch_size, reject_outside_prior, max_sampling_time, return_partial_on_timeout before show_progress_bars, and MCMCPosterior.sample (:237) inserts method, thin, warmup_steps, num_chains, ... So positional calls are not portable across posterior types.
x-handling still sits in the base (_x, set_default_x, get_default_x, _x_else_default_x, _assert_finite_x, potential()), mixing the abstract interface with concrete logic.
How I would fix it (incrementally, so nothing breaks):
Make it a real ABC: class NeuralPosterior(ABC) and add abstractmethod def log_prob(self, theta, x=None, track_gradients=False). Leave log_prob_batched non-abstract for now, since only Direct and FilteredDirect implement it; a default that raises NotImplementedError would keep the other subclasses working.
Keep the two abstract sampling methods, but document that subclasses must accept their extra arguments as keywords, not rely on a fixed positional order.
Move the x-handling into a small mixin or helper (e.g. a PosteriorObservationHandler) so the ABC stays interface-only and the logic is reusable. This keeps _x_else_default_x and friends available to subclasses without bloating the base.
Add tests: instantiating the base raises TypeError, and every concrete posterior exposes the abstract methods.
@BHARATH0153 thanks for checking these points against the current code. The clean-up of the posterior interface belongs to the posterior refactoring I am working on (PR #2104 for device handling, issue #1994 for binding observations), so this issue is not open for a PR.
API changesThis impacts the public API of the project (e.g. inference class).architectureInternal structure and design of the codebasebugSomething isn't workinghackathonFor our in-person hackathons with maintainers present, not a general up-for-grabs listposteriorsPosterior classes and their sampling interface
Activity
BHARATH0153 commentedon Oct 18, 2026
@janfb went through the current code and all four points still hold, though some have moved:
NeuralPosterior (base_posterior.py:39) is not an ABC. It uses abstractmethod on sample (:133) and sample_batched (:157) but does not inherit from abc.ABC, so the decorators are inert. I checked at runtime: instantiating it succeeds, and you only get a confusing error later when the method is actually called.
The class docstring (:40) advertises log_prob(), but the base class has no such method. Every concrete posterior implements it (Direct, MCMC, VI, Rejection, Importance, Ensemble, VectorField, FilteredDirect; NPE_A inherits Direct), so the base is simply lying about its interface.
sample and sample_batched still disagree on parameter order. Base declares sample(sample_shape, x=None, show_progress_bars=True, **kwargs), while DirectPosterior.sample (:146) inserts max_sampling_batch_size, reject_outside_prior, max_sampling_time, return_partial_on_timeout before show_progress_bars, and MCMCPosterior.sample (:237) inserts method, thin, warmup_steps, num_chains, ... So positional calls are not portable across posterior types.
x-handling still sits in the base (_x, set_default_x, get_default_x, _x_else_default_x, _assert_finite_x, potential()), mixing the abstract interface with concrete logic.
How I would fix it (incrementally, so nothing breaks):
Make it a real ABC: class NeuralPosterior(ABC) and add abstractmethod def log_prob(self, theta, x=None, track_gradients=False). Leave log_prob_batched non-abstract for now, since only Direct and FilteredDirect implement it; a default that raises NotImplementedError would keep the other subclasses working.
Keep the two abstract sampling methods, but document that subclasses must accept their extra arguments as keywords, not rely on a fixed positional order.
Move the x-handling into a small mixin or helper (e.g. a PosteriorObservationHandler) so the ABC stays interface-only and the logic is reusable. This keeps _x_else_default_x and friends available to subclasses without bloating the base.
Add tests: instantiating the base raises TypeError, and every concrete posterior exposes the abstract methods.
janfb commentedon Oct 29, 2026
@BHARATH0153 thanks for checking these points against the current code. The clean-up of the posterior interface belongs to the posterior refactoring I am working on (PR #2104 for device handling, issue #1994 for binding observations), so this issue is not open for a PR.
cheers, Jan