joshspeagle / dynesty

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

TypeError: unsupported format string in results.py #167

Closed ajdittmann closed 4 years ago

ajdittmann commented 4 years ago

The following error occurs when trying to add a batch of live points. I have tried to follow the documentation when testing various features. The full report is as follows:

yorp5% python3 eggtest.py 
25559it [08:45, 48.59it/s, batch: 9 | bound: 107 | nc: 1 | ncall: 124103 | eff(%): 20.595 | loglstar: 238.073 < 242.999 < 242.695 | logz: 235.900 +/-  0.110 | stop:  0.894]       
0it [00:00, ?it/s]
Traceback (most recent call last):
  File "eggtest.py", line 15, in <module>
    dsampler.add_batch(nlive = 100, maxiter = 1000)
  File "/yorp5a/dittmann/anaconda3/lib/python3.7/site-packages/dynesty-1.0.0-py3.7.egg/dynesty/dynamicsampler.py", line 1768, in add_batch
  File "/yorp5a/dittmann/anaconda3/lib/python3.7/site-packages/dynesty-1.0.0-py3.7.egg/dynesty/results.py", line 83, in print_fn
  File "/yorp5a/dittmann/anaconda3/lib/python3.7/site-packages/dynesty-1.0.0-py3.7.egg/dynesty/results.py", line 151, in print_fn_tqdm
  File "/yorp5a/dittmann/anaconda3/lib/python3.7/site-packages/dynesty-1.0.0-py3.7.egg/dynesty/results.py", line 140, in get_print_fn_args
TypeError: unsupported format string passed to NoneType.__format__

The script I am running is

import numpy as np
import dynesty

ndim = 2
def prior(u):
    return u*10.0*np.pi
def loglike(x):
    return (2.0 + np.cos(x[0]/2)*np.cos(x[1]/2))**5

dsampler = dynesty.DynamicNestedSampler(loglike, prior, ndim=ndim)
dsampler.run_nested(dlogz_init=0.5, nlive_init=1000)
dsampler.add_batch(nlive=100, maxiter=1000)

I have been able to ameliorate this by adding a try/except statement in results.py, but I suspect there may be some deeper issue.

joshspeagle commented 4 years ago

Ah, I see what's going on. This was an issue that was inadvertently introduce in #152 when adding in support for an alternate printing function where the stopping value has to be nan not None. I'll patch in a quick hotfix now.

joshspeagle commented 4 years ago

Okay https://github.com/joshspeagle/dynesty/commit/63b6314f636cb79fdf13227ea55cf2f075b9cccc should fix this. Closing this for now.