hpparvi / ldtk

Python toolkit for calculating stellar limb darkening profiles and model-specific coefficients using the stellar atmosphere spectrum library by Husser et al. (2013). Described in Parviainen & Aigrain, MNRAS 453, 3821–3826 (2015).
GNU General Public License v2.0
27 stars 18 forks source link

ps.coeffs_qd() leads to numba error #19

Closed vedad closed 4 years ago

vedad commented 4 years ago

Hi Hannu,

Following the basics notebook example, I run into an error when computing the limb darkening coefficients which I am not able to figure out.

numba v. 0.45.1

The snippet below produces the following error (with or without using MCMC):

from ldtk import LDPSetCreator
from ldtk.filters import tess

sc = LDPSetCreator(teff=(6500, 150), logg=(4.1, 0.09), z=(0,0.1), filters=[tess]) 

ps = sc.create_profiles(nsamples=2000) 
ps.resample_linear_z(300) 

qc, qe = ps.coeffs_qd()
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-49-534425f12e49> in <module>
----> 1 qc, qe = ps.coeffs_qd()

~/Software/anaconda3/lib/python3.7/site-packages/ldtk/ldtk.py in _coeffs(self, return_cm, do_mc, n_mc_samples, mc_thin, mc_burn, ldmodel, ngc)
    238         """
    239         npar = ldmodel.npar or ngc
--> 240         qcs = [fmin(lambda pv: -self._lnlike(pv, flt=iflt, ldmodel=ldmodel), 0.1 * ones(npar), disp=0) for iflt in range(self._nfilters)]
    241         covs = []
    242         for iflt, qc in enumerate(qcs):

~/Software/anaconda3/lib/python3.7/site-packages/ldtk/ldtk.py in <listcomp>(.0)
    238         """
    239         npar = ldmodel.npar or ngc
--> 240         qcs = [fmin(lambda pv: -self._lnlike(pv, flt=iflt, ldmodel=ldmodel), 0.1 * ones(npar), disp=0) for iflt in range(self._nfilters)]
    241         covs = []
    242         for iflt, qc in enumerate(qcs):

~/Software/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in fmin(func, x0, args, xtol, ftol, maxiter, maxfun, full_output, disp, retall, callback, initial_simplex)
    440             'initial_simplex': initial_simplex}
    441 
--> 442     res = _minimize_neldermead(func, x0, args, callback=callback, **opts)
    443     if full_output:
    444         retlist = res['x'], res['fun'], res['nit'], res['nfev'], res['status']

~/Software/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in _minimize_neldermead(func, x0, args, callback, maxiter, maxfev, disp, return_all, initial_simplex, xatol, fatol, adaptive, **unknown_options)
    583 
    584     for k in range(N + 1):
--> 585         fsim[k] = func(sim[k])
    586 
    587     ind = numpy.argsort(fsim)

~/Software/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in function_wrapper(*wrapper_args)
    324     def function_wrapper(*wrapper_args):
    325         ncalls[0] += 1
--> 326         return function(*(wrapper_args + args))
    327 
    328     return ncalls, function_wrapper

~/Software/anaconda3/lib/python3.7/site-packages/ldtk/ldtk.py in <lambda>(pv)
    238         """
    239         npar = ldmodel.npar or ngc
--> 240         qcs = [fmin(lambda pv: -self._lnlike(pv, flt=iflt, ldmodel=ldmodel), 0.1 * ones(npar), disp=0) for iflt in range(self._nfilters)]
    241         covs = []
    242         for iflt, qc in enumerate(qcs):

~/Software/anaconda3/lib/python3.7/site-packages/ldtk/ldtk.py in _lnlike(self, ldcs, joint, flt, ldmodel)
    289                 'Need to give the filter id `flt` if evaluating a single set of coefficients with multiple filters defined.')
    290 
--> 291         m = ldmodel.evaluate(self._mu, ldcs)
    292 
    293         if flt is not None:

~/Software/anaconda3/lib/python3.7/site-packages/ldtk/ldmodel.py in evaluate(cls, mu, pv)
    138     @classmethod
    139     def evaluate(cls, mu: ndarray, pv: ndarray) -> ndarray:
--> 140         return evaluate_ld(ld_quadratic, mu, pv)
    141 
    142 

~/Software/anaconda3/lib/python3.7/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)
    374                 e.patch_message(msg)
    375 
--> 376             error_rewrite(e, 'typing')
    377         except errors.UnsupportedError as e:
    378             # Something unsupported is present in the user code, add help info

~/Software/anaconda3/lib/python3.7/site-packages/numba/dispatcher.py in error_rewrite(e, issue_type)
    341                 raise e
    342             else:
--> 343                 reraise(type(e), e, None)
    344 
    345         argtypes = []

~/Software/anaconda3/lib/python3.7/site-packages/numba/six.py in reraise(tp, value, tb)
    656             value = tp()
    657         if value.__traceback__ is not tb:
--> 658             raise value.with_traceback(tb)
    659         raise value
    660 

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.typeinfer.StaticGetItemConstraint object at 0x134af19d0>.
tuple index out of range
[1] During: typing of static-get-item at /Users/vxh710/Software/anaconda3/lib/python3.7/site-packages/ldtk/ldmodel.py (33)
Enable logging at debug level for details.

File "../anaconda3/lib/python3.7/site-packages/ldtk/ldmodel.py", line 33:
def evaluate_ld(ldm, mu, pvo):
    <source elided>
    elif pvo.ndim == 2:
        pv = pvo.reshape((1, pvo.shape[0], pvo.shape[1]))
        ^

This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/latest/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/latest/reference/numpysupported.html

For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

If you think your code should work with Numba, please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/latest/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/latest/reference/numpysupported.html

For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

If you think your code should work with Numba, please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

Do you have an idea what might cause this?

vedad commented 4 years ago

Issue was fixed by upgrading numba (from 0.45.1 -> 0.51.2).