glotaran/lmfit-varpro

Failing unit tests

jsnel opened this issue · 3 comments

jsnel commented

On commit 9eae07e tests are failing.

$ python setup.py test
running test
running egg_info
writing requirements to lmfit_varpro.egg-info\requires.txt
writing top-level names to lmfit_varpro.egg-info\top_level.txt
writing lmfit_varpro.egg-info\PKG-INFO
writing dependency_links to lmfit_varpro.egg-info\dependency_links.txt
reading manifest file 'lmfit_varpro.egg-info\SOURCES.txt'
writing manifest file 'lmfit_varpro.egg-info\SOURCES.txt'
running build_ext
test_multi_compartment_multi_channel_decay (test_simple_kinetic_model.TestSimpleKinetic) ... ERROR
test_one_compartment_decay (test_simple_kinetic_model.TestSimpleKinetic) ... C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\lmfit\minimizer.py:1016: RuntimeWarning: invalid value encountered in double_scalars
result.redchi = result.chisqr / result.nfree
C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\lmfit\minimizer.py:1018: RuntimeWarning: divide by zero encountered in log
_neg2_log_likel = result.ndata * np.log(result.chisqr / result.ndata)
FAIL
test_two_compartment_decay (test_simple_kinetic_model.TestSimpleKinetic) ... ERROR

======================================================================
ERROR: test_multi_compartment_multi_channel_decay (test_simple_kinetic_model.TestSimpleKinetic)

Traceback (most recent call last):
File "C:\src\lmfit-varpro\lmfit_varpro\test\test_simple_kinetic_model.py", line 147, in test_multi_compartment_multi_channel_decay
data = model.eval(real_params.valuesdict(), times)
File "C:\src\lmfit-varpro\lmfit_varpro\separable_model.py", line 19, in eval
e = self.e_matrix(parameter, **kwargs)
TypeError: e_matrix() takes 1 positional argument but 2 were given

======================================================================
ERROR: test_two_compartment_decay (test_simple_kinetic_model.TestSimpleKinetic)

Traceback (most recent call last):
File "C:\src\lmfit-varpro\lmfit_varpro\test\test_simple_kinetic_model.py", line 86, in test_two_compartment_decay
data = model.eval(real_params.valuesdict(), times)
File "C:\src\lmfit-varpro\lmfit_varpro\separable_model.py", line 19, in eval
e = self.e_matrix(parameter, **kwargs)
TypeError: e_matrix() takes 1 positional argument but 2 were given

======================================================================
FAIL: test_one_compartment_decay (test_simple_kinetic_model.TestSimpleKinetic)

Traceback (most recent call last):
File "C:\src\lmfit-varpro\lmfit_varpro\test\test_simple_kinetic_model.py", line 51, in test_one_compartment_decay
.value, 1e-6)
File "C:\src\lmfit-varpro\lmfit_varpro\test\test_simple_kinetic_model.py", line 10, in assertEpsilon
self.assertTrue(abs(number - value) < epsilon, msg='wrong number')
AssertionError: False is not true : wrong number
-------------------- >> begin captured stdout << ---------------------
Iteration Total nfev Cost Cost reduction Step norm Optimality
0 1 0.0000e+00 0.00e+00
gtol termination condition is satisfied.
Function evaluations 1, initial cost 0.0000e+00, final cost 0.0000e+00, first-order optimality 0.00e+00.

--------------------- >> end captured stdout << ----------------------


Ran 3 tests in 1.334s

FAILED (failures=1, errors=2)
Test failed: <unittest.runner.TextTestResult run=3 errors=2 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=3 errors=2 failures=1>

jsnel commented

Debugging the first error,
C:/WinPython-64bit-3.5.2.3Qt5/python-3.5.2.amd64/Lib/site-packages/lmfit/minimizer.py:1018
crashes because
_neg2_log_likel = result.ndata * np.log(result.chisqr / result.ndata)
result.chisqr = 0.0
perhaps because of bad input from our side.
(strange that no input sanitation is done on a call to np.log )

Ok, I took a quick glance at the code and I see several errors.

def e_matrix(self, **kwargs):
        raise NotImplementedError("'self.e_matrix' not defined in model.")

is the definition, but eval calls it with

e = self.e_matrix(parameter, **kwargs)

the parameter parameter is too much

If I correct it, I get a different error:
Traceback (most recent call last):
File "/home/yami/projects/lmfit-varpro/lmfit_varpro/test/test_simple_kinetic_model.py", line 147, in test_multi_compartment_multi_channel_decay
data = model.eval(real_params.valuesdict(), times)
File "/home/yami/projects/lmfit-varpro/lmfit_varpro/separable_model.py", line 25, in eval
res[x, t] = np.dot(c[x][t, :], e[t][x, :].T)
IndexError: too many indices for array, which is because you only return E instead of return [E]
Even with that the tests still fail, but that's a different issue