neurophysik / jitcdde

Just-in-time compilation for delay differential equations
Other
56 stars 14 forks source link

Invalid pointer when importing matplotlib #35

Closed gwaterst closed 3 years ago

gwaterst commented 3 years ago

I have installed jitcdde, chspy, and jitcxde_common - all from git source in Arch Linux.

Using jitcdde works as expected. However importing pylab from matplotlib leads to an error "tcmalloc.cc:333] Attempt to free invalid pointer"

minimal working example:

In [1]: from jitcdde import y, t; import matplotlib.pyplot as plt
src/tcmalloc.cc:333] Attempt to free invalid pointer 0x560a54c4cb10 
Aborted (core dumped)

Installed versions of all(?) relevant packages: Kernel: 5.11.15-arch1-2 Python: Python 3.9.3 gcc 10.2.0-6 python-jinja 2.11.3-2 python-scipy 1.6.2-1 python-numpy 1.20.1-1 python-symengine 0.7.2-1 symengine 0.7.0-1 python-chspy-git 1.2.r0.gbd54f91-1 python-jitcdde-git 1.8.0.r4.ge732be5-2 python-jitcxde_common-git 1.5.2.r2.gced3d5d-1

Is there anything to do that would help me/us to locate the source of the error?

Wrzlprmft commented 3 years ago

My best guess is that this is the same problem as Issue #34, which was eventually caused by a problem in SymEngine that is fixed in its latest version. So my first recommendation would be to check whether importing SymEngine suffices to produce problem, i.e.:

import symengine
import matplotlib.pyplot as plt

If yes, updating SymEngine will likely solve the issue.

My second guess is that yet another module to be the culprit since only importing JiTCDDE doesn’t execute any compiled code I am responsible for (and only that can be the source of the error). Please check whether the following still produces the error:

import warnings, itertools, numpy, functools, sys, tempfile, os, inspect, setuptools, traceback, pickle, jinja2, importlib, bisect
import matplotlib.pyplot as plt

If yes, try to reduce the minimise the first import statement until you find the culprit.

That’s all the guesses I can provide for now, as I fail to reproduce this error on my machine. I may have access to an Arch machine later, if the above doesn’t help.

gwaterst commented 3 years ago

Wow, took me a moment.

The problem had indeed been symengine:

In [1]: import symengine.lib.symengine_wrapper as wrapper
In [2]: import matplotlib.pyplot as plt
src/tcmalloc.cc:333] Attempt to free invalid pointer 0x560eac5d7b10 
Aborted (core dumped)

Even re-building symengine and its python bindings from git did not resolve this issue.

However, I found a solution here: https://www.programmersought.com/article/46315702002/

adding export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4" to ~/.bashrc solved the issue! Maybe someone finds this helpful!

Wrzlprmft commented 3 years ago

If this still happens with the latest version of SymEngine, I suggest that you report this as a SymEngine issue. I would point you to the issue or commit referenced in Issue #34 as a starting point, but unfortunately I fail to find it. I thus suggest to open a new issue.