brinckmann / montepython_public

Public repository for the Monte Python Code
MIT License
93 stars 80 forks source link

Error with MultiNest: exception str() failed #320

Closed ash2223 closed 10 months ago

ash2223 commented 1 year ago

Hello!

I'm attempting to run MontePython with MultiNest, and I seem to be running into an error when trying to analyze the Planck lite likelihood:

Screen Shot 2023-04-04 at 1 01 41 PM

It seems that there is an "<exception str() failed>" error thrown by clik. I'm wondering if anyone has ever seen this issue before? If so, do you know how to address it? Thank you!

-Adam

ThomasTram commented 1 year ago

Hi Adam

We just got that as well. As far as I can tell, this is an error occurring inside the Planck likelihood. However, the actual error message from the Fortran code is lost, probably due to some decode error when the str type changed between Python2 and Python3.

My guess is that this is something that only occur far from the bestfit, so it will rarely show up in MCMC. My solution/hack is to catch the exception and set the likelihood to the boundary value. We can substitute line 776 in sampler.py by something like:

            import traceback
            try:
                value = likelihood.loglkl(cosmo, data)
            except:
                value = data.boundary_loglike
                var = traceback.format_exc()
                print(f'The following error occurred when calling {likelihood.name}: {var}')

Cheers, Thomas

ThomasTram commented 1 year ago

Ah, just found this as well -- it might be the same error: https://github.com/PolyChord/PolyChordLite/issues/42

davidcato commented 1 year ago

Hi all,

I can confirm is the same error. I was having the same issue as Adam. I switched from plc3.01 to plc3.1 and now I'm getting:

Exception ignored on calling ctypes callback function: <function run.<locals>.loglike at 0x2b46ab4bdc60>
Traceback (most recent call last):
  File "/users/dacato/.conda/envs/py3/lib/python3.10/site-packages/pymultinest-2.11-py3.10.egg/pymultinest/run.py", line 228, in loglike
    index = original.index('-N')
  File "/users/dacato/codes/montepython_public/montepython/MultiNest.py", line 272, in loglike
    lkl = sampler.compute_lkl(cosmo, data)
  File "/users/dacato/codes/montepython_public/montepython/sampler.py", line 1411, in compute_lkl
    value = likelihood.loglkl(cosmo, data)
  File "/users/dacato/codes/montepython_public/montepython/likelihood_class.py", line 1054, in loglkl
    lkl = self.clik(tot)[0]
  File "lkl.pyx", line 90, in clik.lkl.clik.__call__
clik.lkl.CError: clik_compute(../src/clik.c:391)::ForwardError
  distribution_lkl(../src/minipmc/distribution.c:219)::ForwardError
    lklbs_lkl(../src/lklbs.c:219)::ForwardError
      simall_lkl(../src/simall/clik_simall.c:48)::Error -1233 (multipole EE 3 too large (got 0.45101 expected <0.3))

As predicted by Thomas, the error occurs when you are far away from the best-fit and your model produces a "unreasonable" value for the EE power spectrum. Set the likelihood to the boundary value seems to be the best practical solution.