sbi icon indicating copy to clipboard operation
sbi copied to clipboard

constrain the type of proposal in accep_reject_sample

Open janfb opened this issue 10 months ago • 0 comments

with #1370 we changed the type of the proposal argument to accept_reject_sample to be Callable instead of torch.Distribution to enable passing a sample function directly.

https://github.com/sbi-dev/sbi/pull/1370#discussion_r1959346595

However, it is not controlled whether this callable function behaves like a sample function, e.g., whether it takes a sample_shape as argument. Thus, we have to bypass the type checker here.

As a solution, I suggest defining a protocal that has a callable method with sample_shape-like input argument.

Note, this kind of approach could also apply to the way we handle potential_fns, i.e., using Python protocols instead of abstract base classes for controlling the types.

To be discussed.

janfb avatar Feb 20 '25 12:02 janfb