2.5.0.2 wheel is incompatible with numpy versions < 1.22
kjohnsen opened this issue · 8 comments
I actually cloned the repo and ran the test suite and was surprised to find that the suite fails with a numpy size error, but only only on v2.5.0.2, not even on the current HEAD (b296895, from the "test latest dependencies run").
I'm running WSL Ubuntu 20.04, Python 3.8.12. I get the same thing on Python 3.9 and on Windows with Python 3.8. And on Ubuntu with Python 3.7 I get warnings about the numpy.ndarray size change.
I tried pip install brian2==2.5.0.1
and that ran with no problems.
Here's some minimal code that will trigger it:
import brian2
print("brian2 version", brian2.__version__)
print("numpy version", np.__version__)
prefs.codegen.target = "numpy"
ng = NeuronGroup(1, "v : 1", threshold='v>2', reset='v=0')
S = Synapses(ng, ng, on_pre='v+=1')
print('success')
Output:
brian2 version 2.5.0.2
numpy version 1.21.1
ERROR Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at <http://brian.discourse.group/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: /tmp/brian_debug_1q61eavh.log Additionally, you can also include a copy of the script that was run, available at: /tmp/brian_script_fvuzi593.py Thanks! [brian2]
Traceback (most recent call last):
File "/home/kyle/scratch/brian2_test.py", line 11, in <module>
S = Synapses(ng, ng, on_pre='v+=1')
File "/home/kyle/anaconda3/envs/sim/lib/python3.8/site-packages/brian2/synapses/synapses.py", line 866, in __init__
self._add_updater(argument, prepost, delay=pathway_delay,
File "/home/kyle/anaconda3/envs/sim/lib/python3.8/site-packages/brian2/synapses/synapses.py", line 1083, in _add_updater
updater = SynapticPathway(self, code, prepost, objname,
File "/home/kyle/anaconda3/envs/sim/lib/python3.8/site-packages/brian2/synapses/synapses.py", line 284, in __init__
self.queue = get_device().spike_queue(self.source.start, self.source.stop)
File "/home/kyle/anaconda3/envs/sim/lib/python3.8/site-packages/brian2/devices/device.py", line 494, in spike_queue
from brian2.synapses.cythonspikequeue import SpikeQueue
File "brian2/synapses/cythonspikequeue.pyx", line 1, in init brian2.synapses.cythonspikequeue
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
Hi @kjohnsen . Normally, this error message indicates a broken installation (see my comment on the forum). Something like an installation with pip
from source, which compiles the "spike queue" against the current numpy version, and then a downgrade of numpy to an earlier version. But with the most recent version, it should already download a pre-compiled wheel (when running pip
you should see something like "Downloading Brian2-2.5.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl") which is compiled against an old version of numpy to avoid this kind of issue. But if you can reproduce this with a fresh virtual environment that installs brian2
from scratch, then this indicates that there is something wrong with this mechanism. I cannot reproduce it on my (Ubuntu) machine, though. I created a new virtual environment with Python 3.8.12, used pip install brian2
, and everything works with this slightly adapted script:
import brian2
from brian2 import *
import sys
print("Python version", sys.version)
print("brian2 version", brian2.__version__)
print("numpy version", np.__version__)
prefs.codegen.target = "numpy"
ng = NeuronGroup(1, "v : 1", threshold='v>2', reset='v=0')
S = Synapses(ng, ng, on_pre='v+=1')
print('success')
Output:
Python version 3.8.12 (default, Jan 26 2022, 11:03:12)
[GCC 9.3.0]
brian2 version 2.5.0.2
numpy version 1.22.1
success
But with the most recent version, it should already download a pre-compiled wheel (when running
pip
you should see something like "Downloading Brian2-2.5.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl") which is compiled against an old version of numpy to avoid this kind of issue.
Hold on, I just realized that this is indeed not working correctly. Instead of building against numpy 1.17, it builds against the latest numpy version (1.22). This is why you were seeing an error with numpy 1.21.1. I'll fix this ASAP, but you can use either of the following workarounds until then:
- Upgrade numpy to version 1.22, or
- remove your Brian installation and install it again, but this time from source instead of from the binary wheel:
$ pip remove brian2
$ pip install --no-binary brian2 brian2
In case that you did not apply any of the above workarounds yet, could you please try testing the latest development version of Brian where I fixed this issue? To install it, use
pip install --upgrade --pre -i https://test.pypi.org/simple/ Brian2
I had the same problem trying to run Brian on Deepnote which uses virtual machines / cloud blah blah. The --no-binary
fixes the problem. For the second one I get
Looking in indexes: https://test.pypi.org/simple/
Collecting Brian2
Downloading https://test-files.pythonhosted.org/packages/58/2c/f2642b3105ac9facd2c098f1cecf7dc7d748ddc32433b216469d36091a3c/Brian2-2.5.0.2.post0.dev12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 7.0 MB/s
Requirement already satisfied, skipping upgrade: setuptools>=24.2 in /root/venv/lib/python3.7/site-packages (from Brian2) (47.1.0)
Requirement already satisfied, skipping upgrade: jinja2>=2.7 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from Brian2) (3.0.3)
Requirement already satisfied, skipping upgrade: numpy>=1.17 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from Brian2) (1.19.5)
ERROR: Could not find a version that satisfies the requirement cython>=0.29 (from Brian2) (from versions: 0.23.4)
ERROR: No matching distribution found for cython>=0.29 (from Brian2)
For the second one I get [...]
Ah, sorry, I wasn't very clear about this. The installation from the test server only works if all the dependencies are already installed, because otherwise it will look for them on the test server, and most likely not find them (as is your case for Cython). You'll therefore have to first install brian2
in the usual way to install its dependencies, and then upgrade it to the development version from the test server:
$ pip install brian2
$ pip install --upgrade --pre -i https://test.pypi.org/simple/ Brian2
Can confirm this works too!
Working for me too, still with NumPy 1.21.1