bilby-dev / bilby

A unified framework for stochastic sampling packages and gravitational-wave inference in Python.
https://bilby-dev.github.io/bilby/
MIT License
68 stars 75 forks source link

Bilby freezes when invalid values are passed to prior constraints #817

Open bilby-bot opened 2 months ago

bilby-bot commented 2 months ago

In GitLab by @git.ligo:alexandresebastien.goettel on Sep 5, 2024, 16:44

Small thing but I noticed that the code will completely freeze when trying to sample from a prior with invalid constraints.

The following code can be used to reproduce the issue:

prior = bilby.gw.prior.BBHPriorDict("invalid.prior")`
parameters = prior.sample()

With an example of an "invalid prior":

mass_1 = Constraint(name='mass_1', minimum=1, maximum=10)
mass_2 = Constraint(name='mass_2', minimum=1, maximum=10)
mass_ratio = bilby.gw.prior.UniformInComponentsMassRatio(name='mass_ratio', minimum=0.8, maximum=1)
chirp_mass = bilby.gw.prior.UniformInComponentsChirpMass(name='chirp_mass', minimum=80, maximum=120)

Obviously the user is doing something wrong here, but I think that a better approach would be to raise an ValueError (or a custom InvalidPriorError) with a corresponding message? If so I'm of course happy to open an MR.

bilby-bot commented 2 months ago

In GitLab by @git.ligo:colm.talbot on Sep 19, 2024, 16:28

We should issue a warning if the efficiency is worse than some threshold, e.g., 1e-3. This is the spot.