Tests fail to run after commit 6d6be7b1 on Python 3.6 (latest from repo for now, cpython commit fdad0c0). Tested on Gentoo (GCC 4.9.4) and Fedora (GCC 6.3.1). Cython version 0.25.2, Numpy 1.11.3, Scipy 0.18.1, OpenBLAS 0.2.15 and MKL 11.3.2.181 (both). Precise error message:
....virtualenvs/kwant_test_py36/lib/python3.6/site-packages/kwant/graph/tests/test_utils.py::test_make_undirected *** Error in `python': realloc(): invalid old size: 0x00007fd1959d07d0 ***======= Backtrace: =========/lib64/libc.so.6(+0x6f383)[0x7fd1aeab8383]...
Other logs are attached.
Steps to reproduce:
Install Python 3.6 from Git (./configure --prefix=~/.local && make && make install or similar)
Make virtual environment, based on it.
pip install cython nose pytest numpy scipy matplotlib
Install Tinyarray from master and any revision of Kwant starting from specified commit.
I'm not sure how 6d6be7b1 could have introduced this bug, but in any case we should probably remove all C-level memory allocations
from kwant.graph, following the reorganisation of kwant.graph.CGraph in 6d6be7b1.
The stated reasoning for use of C-level memory allocation (in comments at the start of graph/core.pyx) are:
There are no efficient arrays that allow appending
Cython extensions cannot have typed buffers as members
It seems that the answer to (1) was to use realloc, however I can't see how this is any better than using array.resize on an array.array. As for (2), we can just store an array.array, the same
way as we now do for the CGraph.
@jbweston, what array.resize do you refer to? The stdlib array module doesn’t seem to have such an operation. I don’t mind if the graph module gets modernized, but given that it is time-tested and we do not exactly know yet by what we will eventually replace it, I’m for concentrating our efforts on other parts of Kwant.
@jbweston, another thing: I noticed that ./setup.py test -a -s outputs a lot of zeros from the operator tests. Is this on purpose, or you just forgot to remove the call to print?
Commenting it out allows tests to run smoothly. I suppose it can occasionally appear to be statically allocated array, not dynamically. @cwg, can you check with more experienced eye?
OK, I see now, I missed the other realloc() in utils.pyx. So this is indeed a bug, introduced by Anton’s commit that uses array.array: there is no guarantee that array.array buffers can be realloced, and if they are, one would have to update the pointer as well.
@slavoutich, your fix looks good, except that nnz should not be multipied by the size of an integer. The argument to resize is the new size of the array in items, not in bytes.
@anton-akhmerov, I don’t see anything else that should be fixed. BTW, since when do you have a dash in your gitlab user name?