Error numpy.ndarray size changed, may indicate binary incompatibility, Tutorial part 2

Hi and wish everybody being healthy.
Why I get error runnign an example from Tutorial part 2 synapse:

from brian2 import *
start_scope()

eqs = '''
dv/dt = (I-v)/tau : 1
I : 1
tau : second
'''
G = NeuronGroup(2, eqs, threshold='v>1', reset='v = 0', method='exact')
G.I = [2, 0]
G.tau = [10, 100]*ms

# Comment these two lines out to see what happens without Synapses
S = Synapses(G, G, on_pre='v_post += 0.2')
S.connect(i=0, j=1)

M = StateMonitor(G, 'v', record=True)

run(100*ms)
File "t1.py", line 14, in <module>
    S = Synapses(G, G, on_pre='v_post += 0.2')
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/synapses/synapses.py", line 856, in __init__
    self._add_updater(argument, prepost, delay=pathway_delay,
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/synapses/synapses.py", line 1032, in _add_updater
    updater = SynapticPathway(self, code, prepost, objname,
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/synapses/synapses.py", line 271, in __init__
    self.queue = get_device().spike_queue(self.source.start, self.source.stop)
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/devices/device.py", line 498, 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 88 from C header, got 80 from PyObject

I am using brian ‘2.4.2’.

This situtation can arise when you do non-default installations and update packages. From your error, it seems you have an installed version of Brian, and one in the directory where you run the code (brian2/synapses/...). Concretely, if I’m not mistaken, at some point our Cython implementation of the SpikeQueue mechanism was compiled (which happens automatically when you run pip install for example), and at a later point numpy was downgraded so that is no longer binary-compatible with the numpy version that was in place when the SpikeQueue was compiled. When we ship compiled packages (with conda, or in the upcoming version with wheels), we handle this by compiling against the oldest supported version, which is forward-compatible with all newer versions.
Long story short, the easiest solution would be probably to remove your Brian2 installation and install it again, or to upgrade numpy to a version at least as new as the one when you installed Brian2 originally. If you prefer a less “brute-force” solution and want to use locally downloaded Brian2 sources, running python setup.by build_ext --inplace in the Brian2 source directory should probably fix the issue as well.

1 Like