joshspeagle / dynesty

Dynamic Nested Sampling package for computing Bayesian posteriors and evidences
https://dynesty.readthedocs.io/
MIT License
347 stars 76 forks source link

Running multi-threaded dynesty across nodes on a cluster #409

Closed shantanu9847 closed 1 year ago

shantanu9847 commented 1 year ago

This is a general question. Does anyone have a working example of running multithread dynesty across nodes ( on muliple nodes on a cluster using PBS or slurm or SGE), where the multiple nodes work in cohesion . note that I have successfully used dynesty to run intra-node parallel processing (using multiprocessing and multiprocess module but not inter-node). Does dynesty support this and what is needed to run dynesty in this way? (would mpi for example support this?) Sorry if this is already documented somewhere and I missed it. Thanks

segasai commented 1 year ago

Something like this should work under any mpi environmpent

I.e. mpirun -np X ... or srun

from schwimmbad import MPIPool
import numpy as np
import sys
import dynesty

def ptform(x):
    return 10 * x - 5

def func(x):
    return -0.5 * np.sum(x**2)

if __name__ == '__main__':
    pool = MPIPool()

    if not pool.is_master():
        pool.wait()
        sys.exit(0)
    dns = dynesty.DynamicNestedSampler(
        func,
        ptform,
        10,
        pool=pool,
    )
    dns.run_nested()
shantanu9847 commented 1 year ago

Thank you, will try this.

segasai commented 1 year ago

I've added the code snipped to FAQ. I'm closing the issue.