Skip to content

Set maximum time for rejection sampling #1699

@gmoss13

Description

@gmoss13

🚀 Feature Request

Is your request related to a problem?

Almost all posterior sample with accept_reject_sample. This raises a warning that sampling will be slow if the acceptance rate is too low, but does not stop trying to sample with rejection.

This is fine when running sbi locally, e.g. in a notebook, but means you have to work around it if sbi is part of a bigger loop (e.g. when optimizing over hyperparameters @swag2198 or running many sbi runs in parallel on a cluster). Then your job is stuck and does not output anything, as it just runs until you stop it or the job times out.

Describe the solution you'd like

We should add an argument, e.g. max_sampling_time, after which we give up on rejection sampling. We can then raise an Error, which should include instructions on how to catch the error to define custom behaviour in this case (e.g. sample posterior without restriction or return prior samples, i.e. what to do in a "failed" run).

...

Describe alternatives you've considered

We can leave the code as it is and add a tutorial/faq entry.

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions