NotImplementedError: emcee version 3 is required

1,113 views
Skip to first unread message

Sahil

unread,
Jul 8, 2021, 12:57:17 PM7/8/21
to lmfit-py
Hello,

I am trying to use emcee for post-fitting parameter uncertainty estimates. My code is something like

!pip install emcee
import lmfit
import emcee
mc = lmfit.minimize(res, method='emcee', nan_policy='omit', burn=300, steps=1000, thin=20, params=fitted_params.params, is_weighted=False, progress=False)

I have installed emcee, and I can check that the version is 3.1.0. However, when running lmfit.minimize, I get a NotImplementedError. Could someone please let me know why this might be happening?

Thank you!

Renee Otten

unread,
Jul 8, 2021, 1:18:38 PM7/8/21
to lmfi...@googlegroups.com
Can you please provide the full Traceback? I assume you read / followed the example given in the documentation (https://lmfit.github.io/lmfit-py/fitting.html#minimizer-emcee-calculating-the-posterior-probability-distribution-of-parameters) ; it seems like that what you’re doing should work, but it’s not really a minimal example as we don’t know what “res” is… 

Best, 
Renee


--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/9b56128c-e99b-4871-b083-ca5cc7d9ceefn%40googlegroups.com.

Renee Otten

unread,
Jul 8, 2021, 1:21:57 PM7/8/21
to lmfi...@googlegroups.com
Sorry, I see that you probably pasted the full message in the subject line - my bad. Looking at the code that’s what’s happening when your “emcee” version is not above 3. Are you sure you don’t have an earlier version installed in the environment you’re using? 

To verify this please do the same thing as lmfit does to check this and post the output:

import emcee
HAS_EMCEE = int(emcee.__version__[0]) >= 3

print(f”HAS_EMCEE = {HAS_EMCEE}”)
print(f”emcee version = {emcee.__version__}”)

Renee


On Jul 8, 2021, at 12:57 PM, Sahil <sahil...@gmail.com> wrote:

Sahil

unread,
Jul 8, 2021, 1:27:16 PM7/8/21
to lmfit-py
Hi Renee,

Yes, I tried exactly that and get

HAS_EMCEE = True 
emcee version = 3.1.0

Renee Otten

unread,
Jul 8, 2021, 1:43:07 PM7/8/21
to lmfi...@googlegroups.com
well… then you shouldn’t get the NotImplementedError…. can you please provide a minimal example and include the full Traceback when the error occurs.



Sahil

unread,
Jul 8, 2021, 1:58:41 PM7/8/21
to lmfit-py
Yeah, exactly why I'm confused. There is no problem with the residual function "res" or the fitting procedure. The full traceback is:

--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) <ipython-input-58-59465c766a68> in <module>() 3 import emcee 4 mc = lmfit.minimize(res, method='emcee', nan_policy='omit', burn=300, steps=1000, thin=20, ----> 5 params=fitted_params.params, is_weighted=False, progress=False)
2 frames
/usr/local/lib/python3.7/dist-packages/lmfit/minimizer.py in minimize(fcn, params, method, args, kws, iter_cb, scale_covar, nan_policy, reduce_fcn, calc_covar, max_nfev, **fit_kws) 2592 2593 """ -> 2594 fitter = Minimizer(fcn, params, fcn_args=args, fcn_kws=kws, 2595 iter_cb=iter_cb, scale_covar=scale_covar, 2596 nan_policy=nan_policy, reduce_fcn=reduce_fcn, 

/usr/local/lib/python3.7/dist-packages/lmfit/minimizer.py in minimize(self, method, params, **kws) 2361 else: 2362 function = self.scalar_minimize -> 2363 for key, val in SCALAR_METHODS.items(): 2364 if (key.lower().startswith(user_method) or 2365 val.lower().startswith(user_method)): 

/usr/local/lib/python3.7/dist-packages/lmfit/minimizer.py in emcee(self, params, steps, nwalkers, burn, thin, ntemps, pos, reuse_sampler, workers, float_behavior, is_weighted, seed, progress, run_mcmc_kwargs) 1321 ---------- 1322 .. [1] https://emcee.readthedocs.io -> 1323 1324 """ 1325 if not HAS_EMCEE: 

NotImplementedError: emcee version 3 is required.

Renee Otten

unread,
Jul 8, 2021, 2:17:04 PM7/8/21
to lmfi...@googlegroups.com
Are you 100% sure you’re using the same Python version when checking this.. Can you please try using a Python interpreter directly without using IPython - not sure whether there is somehow a mixup of packages somewhere…



On Jul 8, 2021, at 1:58 PM, Sahil <sahil...@gmail.com> wrote:

Yeah, exactly why I'm confused. There is no problem with the residual function "res" or the fitting procedure. The full traceback is:

Sahil P

unread,
Jul 10, 2021, 4:11:53 PM7/10/21
to lmfi...@googlegroups.com
Thank you, it works in the Python interpreter (when I run a Python script directly from the command line). Is there any way I can diagnose why it doesn't work in an interactive environment?

Renee Otten

unread,
Jul 10, 2021, 4:31:34 PM7/10/21
to lmfi...@googlegroups.com
Try to run the code below both in your IPython environment and after starting a Python interpreter from the command-line to check whether you are actually using the same packages.

import sys, lmfit, numpy, scipy, asteval, emcee, uncertainties
print(f"Python: {sys.version}\n\nlmfit: {lmfit.__version__}, scipy: {scipy.__version__}, numpy: {numpy.__version__}, asteval: {asteval.__version__}, uncertainties: {uncertainties.__version__}, emcee: {emcee.__version__}")

If not then you’ll have to check whether you have things like PYTHONPATH set and or find out why your IPython environment is different. Since I don’t use IPython I cannot really give much useful advice on this.





Reply all
Reply to author
Forward
0 new messages