bilby-dev / bilby

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

signal ValueError when using pymultinest sampler in API service #749

Closed bilby-bot closed 1 month ago

bilby-bot commented 1 year ago

In GitLab by @git.ligo:brian.healy on Jun 16, 2023, 21:34

When running code that calls bilby with pymultinest sampling using an API service (see this repo and PR: https://github.com/nuclear-multimessenger-astronomy/nmma/pull/99), I get the ValueError below. The error is not thrown when running the same code but avoiding the API service.

Traceback (most recent call last):
  File "/Users/bhealy/nmma/api/app.py", line 197, in run_nmma_model
    main(args=args)
  File "/Users/bhealy/nmma/nmma/em/analysis.py", line 608, in main
    result = bilby.run_sampler(
  File "/Users/bhealy/miniforge3/envs/nmma_api2/lib/python3.9/site-packages/bilby/core/sampler/__init__.py", line 234, in run_sampler
    result = sampler.run_sampler()
  File "/Users/bhealy/miniforge3/envs/nmma_api2/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 96, in wrapped
    output = method(self, *args, **kwargs)
  File "/Users/bhealy/miniforge3/envs/nmma_api2/lib/python3.9/site-packages/bilby/core/sampler/pymultinest.py", line 156, in run_sampler
    out = pymultinest.solve(
  File "/Users/bhealy/miniforge3/envs/nmma_api2/lib/python3.9/site-packages/pymultinest/solve.py", line 71, in solve
    run(**kwargs)
  File "/Users/bhealy/miniforge3/envs/nmma_api2/lib/python3.9/site-packages/pymultinest/run.py", line 237, in run
    prev_handler = signal.signal(signal.SIGINT, interrupt_handler)
  File "/Users/bhealy/miniforge3/envs/nmma_api2/lib/python3.9/signal.py", line 56, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread of the main interpreter
bilby-bot commented 1 year ago

In GitLab by @git.ligo:colm.talbot on Jun 19, 2023, 15:08

We do somewhat modify the pymultinest signal handling but this looks like an issue with pymultinest.

It looks like this was fixed on github, I'm not sure if it made it into a release as they don't put out releases very often.

I don't think there's anything we can fix on the bilby end.

bilby-bot commented 1 year ago

In GitLab by @git.ligo:brian.healy on Jun 20, 2023, 20:33

Thanks for the info about releases - installing pymultinest from the source solved this issue.