joshspeagle / dynesty

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

tqdm example #462

Closed jiespinozar closed 9 months ago

jiespinozar commented 9 months ago

Hello, how should I call the function to print the progress bar using tqdm? I tried "sampler.run_nested(print_func=dynesty.utils.print_fn_tqdm)" but it is not working. Can you give me an example? Thanks in advance, Best, Juan Ignacio

segasai commented 9 months ago

Hi,

I am pretty certain if you have tqdm installed and specify print_progress=True tqdm will be used.

jiespinozar commented 9 months ago

Hi,

I am pretty certain if you have tqdm installed and specify print_progress=True tqdm will be used.

That's not working for me :( I'm currently using python 3.11.5 with dynesty 2.1.3 and tqdm 4.65.0. I created a simple function that works but the progress bar is still default.

def dynesty_fit(ndim=38,nlive=1000,bound="walk",sample="rwalk",nthreads=2): print("Running dynesty ... ") with contextlib.closing(Pool(processes= nthreads - 1)) as executor: sampler = DynamicNestedSampler(lnlike, lnprior, ndim, bound=bound, sample=sample , nlive = nlive, pool=executor, queue_size=nthreads) sampler.run_nested(print_progress=True) res = sampler.results weights = np.exp(res['logwt'] - res['logz'][-1]) postsamples = resample_equal(res.samples, weights) return postsamples

It shows this bar while running: dynesty

Can it be a problem with parallelization?

segasai commented 9 months ago

This bar is from tqdm I believe. (there is no progress bar in a classical sense since we don't know how many iterations will be needed, so it's just an updated message which should be updated in real time)

jiespinozar commented 9 months ago

This bar is from tqdm I believe. (there is no progress bar in a classical sense since we don't know how many iterations will be needed, so it's just an updated message which should be updated in real time)

Ohhh, I understand. Thank you!