Skip to content

Standardize some common sampler functionality

Colm Talbot requested to merge standardize-pool-handling into master

This MR attempts to standardize a few common features we implement for external samplers.

I had hoped to keep them independent, but they became pretty intertwined, so I wanted to at least share them in this way.

  • saving results to a temporary directory. Several samplers (pymultinest, dnest4, ultranest) had pretty much equivalent definitions of a file transfer mechanism. I'm not entirely sure that they all need it. Originally pymultinest needed it due to a limitation of the underlying fortran code. This way any changes/fixes to one will be applied to the others.
  • opening and closing a pool. We manually set up/tear down the pool used for dynesty, ptemcee, and ptemcee. This typically involves defining some global objects that are then stored and called independently in different threads. I wrapped this in a little class to reduce the number of globals we have floating around. This should again cut down on maintenance. A side effect of this is that emcee, kombine, and zeus now support parallelization using multiprocessing.
  • signal catching. This hit most of the samplers as we set a catch for signals from the system. Currently, we just set the signals when the object is initialized and forget about it. This has lead to some weird behaviour if there is a significant amount of stuff that happens after the sampler finishes, e.g., reconstructing marginalized parameters. The new method just has a decorator that is applied to the run_sampler method if we want it that sets the signal before entering the method and resets them to the previous values when the sampling is done.

Edit (220126): Since this MR already essentially rewrote the entire directory I decided it was time to add this bilby.core.sampler directory to the pre-commits. This involved running, black, isort, and flynt.

Edit (220726): Six months since the last update... I made some slides to explain the different changes.

Edited by Colm Talbot

Merge request reports