dfm / emcee

The Python ensemble sampling toolkit for affine-invariant MCMC
https://emcee.readthedocs.io
MIT License
1.47k stars 430 forks source link

Issue on page /tutorials/quickstart.html #417

Closed haricash closed 2 years ago

haricash commented 2 years ago

In the line sampler.run_mcmc(state, 10000), the state is a tuple, whose 1st element contains the required initial parameters for the run_mcmc to function. Being a first time user, I ran into this issue because of my naivety. It would be great if the documentation could be changed so that first time users can seamlessly work through the quick start section.

dfm commented 2 years ago

I'm not sure I understand your issue here, that tutorial is an ipynb that is executed from top to bottom - so it definitely runs! What was the missing piece for you?

haricash commented 2 years ago

Sorry, it did work in ipynb! I was running it on python from terminal, and got the following error :

/PATH/TO/lib/python3.9/site-packages/emcee/ensemble.py:190: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. p = np.array(p0) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/PATH/TO/lib/python3.9/site-packages/emcee/sampler.py", line 171, in run_mcmc for results in self.sample(pos0, lnprob0, rstate0, iterations=N, File "/PATH/TO/lib/python3.9/site-packages/emcee/ensemble.py", line 198, in sample lnprob, blobs = self._get_lnprob(p) File "/PATH/TO/lib/python3.9/site-packages/emcee/ensemble.py", line 364, in _get_lnprob if np.any(np.isinf(p)): TypeError: ufunc 'isinf' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I then only passed the information about the location of each walker for the parameters to the run_mcmc function, which then worked. At that time, I thought this was an error in the documentation. It did not strike me then that I had to run it as an ipynb. I hurriedly opened an issue.

It was much later, when I tried it out in an iPython notebook that I realised my mistake. I then closed the issue.

I apologize for my carelessness.

P.S. Why does this happen? I am quite new to ipynb, and have no idea how things work below the hood.

dfm commented 2 years ago

No problem - it's not that it needs to be run in a notebook. I was just saying that if you run the code in the order that it's listed, it will work, in a notebook or otherwise! I expect that you're either missing a step somewhere when running from the command line, or perhaps you have a version mismatch (line 190 of ensemble.py in the most recent version of emcee, would not throw that error...).