I've recently discovered what appears to be a bug in Numexpr. Although I've already opened an issue on their Git hub, I figured I would avail myself of the collective wisdom here as well.
In a nutshell, evaluate
sometimes (unpredictably) returns incorrect results when doing a straightforward array operation. The bug, which can be reproduced by the Python code below, results in a zero array being returned rather than the correct result. Although the sample code shows a multiplication, this bug has manifested for us on addition and exponentiation as well. Notably, there are no errors or warnings that are raised by Numexpr, the computational load appears normal (i.e. the RAM and CPU are taxed as expected when monitoring task manager), and the correct shape array is returned. It was a rather insidious bug to isolate for those reasons! In our tests, this bug has only manifested in the following hardware builds:
- Windows Server 2012 r2, Intel Xeon 2680 v3, 2 processors, 48 logical cores
- Windows 8.1, Intel Xeon 2690, 1 processor, 24 logical cores
In all the many thousands of runs of our software completed on our Windows 7, 64 bit, Intel i7 machines, this has never manifested. Furthermore, we have run the attached code many times (with bigger arrays and more iterations) and have not seen the error on the Windows 7, i7 machines. The Xeon computers, though, manifest it regularly. Unfortunately we don't have any other builds on which to test.
Other items of note:
- We are running from the WinPython distribution 3.4.3.6.
- We have not invoked any supporting Numexpr functions, just
evaluate
... so we are using its default settings. - The version of Numexpr is 2.4.4, as included in WinPython 3.4.3.6
Sample Code:
import numpy as np
import numexpr as ne
x = np.ones(1e6)
y = np.ones(1e6)
for ii in range(1000):
rr = ne.evaluate('x * y')
test = np.all(rr == 0)
if test:
print('Gotcha! %d' % ii)
print('Complete!')