lmfit / lmfit-py

Non-Linear Least Squares Minimization, with flexible Parameter settings, based on scipy.optimize, and with many additional classes and methods for curve fitting.
https://lmfit.github.io/lmfit-py/
Other
1.07k stars 275 forks source link

[bug] Packaging for debian. #606

Closed alexmarie78 closed 4 years ago

alexmarie78 commented 4 years ago

Description

The lmfit-py package fails to build from source in Ubuntu focal, because Ubuntu has begun the transition to python3.8 and lmfit-py 0.9.14 is not source-compatible with python3.8.

Error message:
[...]
==================================== ERRORS ====================================
_________________ ERROR at setup of test_algebraic_constraints _________________

    @pytest.fixture
    def minimizer():
        """Return the Minimizer object."""
        def residual(pars, x, sigma=None, data=None):
            """Define objective function."""
            yg = gaussian(x, pars['amp_g'], pars['cen_g'], pars['wid_g'])
            yl = lorentzian(x, pars['amp_l'], pars['cen_l'], pars['wid_l'])

            model = yg + yl + pars['line_off'] + x * pars['line_slope']

            if data is None:
                return model
            if sigma is None:
                return model - data
            return (model-data) / sigma

        # generate synthetic data
        n = 601
        xmin = 0.
        xmax = 20.0
        x = np.linspace(xmin, xmax, n)

        data = (gaussian(x, 21, 8.1, 1.2) + lorentzian(x, 10, 9.6, 2.4) +
                np.random.normal(scale=0.23, size=n) + x*0.5)

        # create initial Parameters
        pars = Parameters()
        pars.add(name='amp_g', value=10)
        pars.add(name='cen_g', value=9)
        pars.add(name='wid_g', value=1)
        pars.add(name='amp_tot', value=20)
        pars.add(name='amp_l', expr='amp_tot - amp_g')
>       pars.add(name='cen_l', expr='1.5+cen_g')

tests/test_algebraic_constraint.py:41: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
lmfit/parameter.py:361: in add
    self.__setitem__(name, Parameter(value=value, name=name, vary=vary,
lmfit/parameter.py:132: in __setitem__
    self._asteval.symtable[key] = par.value
lmfit/parameter.py:823: in value
    return self._getval()
lmfit/parameter.py:805: in _getval
    check_ast_errors(self._expr_eval)
lmfit/parameter.py:25: in check_ast_errors
    expr_eval.raise_exception(None)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <asteval.asteval.Interpreter object at 0x7fe24279e190>, node = None
exc = <class 'NotImplementedError'>, msg = ''
expr = <_ast.Module object at 0x7fe2428fa4f0>, lineno = None

    def raise_exception(self, node, exc=None, msg='', expr=None,
                        lineno=None):
        """Add an exception."""
        if self.error is None:
            self.error = []
        if expr is None:
            expr = self.expr
        if len(self.error) > 0 and not isinstance(node, ast.Module):
            msg = '%s' % msg
        err = ExceptionHolder(node, exc=exc, msg=msg, expr=expr, lineno=lineno)
        self._interrupt = ast.Break()
        self.error.append(err)
        if self.error_msg is None:
            self.error_msg = "%s in expr='%s'" % (msg, self.expr)
        elif len(msg) > 0:
            self.error_msg = "%s\n %s" % (self.error_msg, msg)
        if exc is None:
            try:
                exc = self.error[0].exc
            except:
                exc = RuntimeError
>       raise exc(self.error_msg)
E       NotImplementedError: 'Constant' not supported in expr='<_ast.Module object at 0x7fe2428fa4f0>'

/usr/lib/python3/dist-packages/asteval/asteval.py:248: NotImplementedError
---------------------------- Captured stderr setup -----------------------------
NotImplementedError
   <_ast.Module object at 0x7fe2428fa4f0>
'Constant' not supported
[...]
Version information

lmfit: 0.9.11, scipy: 1.1.0, numpy: 1.16.2, asteval: 0.9.12, uncertainties: 3.0.2, six: 1.12.0

Link(s)

Here is the link of the discussion bug in debian.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=943786

reneeotten commented 4 years ago

@alexmarie78 indeed, you can see from the Trove classifiers that we dont' claim that that version is compatible with Python 3.8 yet. In fact it is, but the issue is with the asteval package; you will need to install asteval>=0.9.16 and it will all work. By the time Debian will actually transition to Python 3.8 we will likely have released a new version where this is all sorted out.