brian-team/brian2cuda

Circular eventspaces fail when source group runs on a different clock than synapses

denisalevi opened this issue · 0 comments

SpikeGeneratorClock(..., dt=2*defaultclock.dt) produces wrong results in the following test:

@attr('standalone-compatible')
@with_setup(teardown=reinit_and_delete)
def test_circular_eventspaces_different_clock():
# same test as test_circular_eventspaces_spikegenerator() but with a
# SpikeGeneratorGroup on a different clock (dt=2*defaultclock.dt)
default_dt = defaultclock.dt
# Neuron 0 spikes every second time step in first n_timesteps
clock_multiplier = 2 # factor by which SpikeGeneratorGroup clock is slower
n_timesteps = 12
indices = [0] * (n_timesteps // clock_multiplier)
times = arange(0, n_timesteps, clock_multiplier) * default_dt
inp = SpikeGeneratorGroup(1, indices, times, dt=2*default_dt)
G = NeuronGroup(5, 'v:1', threshold='v>1', reset='v=0')
# synapses with homogenous delays
S0 = Synapses(inp, G, on_pre='v+=1.1', delay=0*ms)
S0.connect(i=0, j=0)
S1 = Synapses(inp, G, on_pre='v+=1.1', delay=2*default_dt)
S1.connect(i=0, j=1)
S2 = Synapses(inp, G, on_pre='v+=1.1', delay=4*default_dt)
S2.connect(i=0, j=2)
# synapse with heterogeneous delays
S3 = Synapses(inp, G, on_pre='v+=1.1')
S3.connect(i=0, j=[3, 4]) # delays: 6, 8
S3.delay = '2*j*default_dt'
mon = SpikeMonitor(G)
run((n_timesteps + 9) * default_dt, profile=profile)
# neurons should spike in the timestep after effect application
assert_allclose(mon.t[mon.i[:] == 0], arange(1, n_timesteps + 1, clock_multiplier) * default_dt)
assert_allclose(mon.t[mon.i[:] == 1], arange(3, n_timesteps + 3, clock_multiplier) * default_dt)
assert_allclose(mon.t[mon.i[:] == 2], arange(5, n_timesteps + 5, clock_multiplier) * default_dt)
assert_allclose(mon.t[mon.i[:] == 3], arange(7, n_timesteps + 7, clock_multiplier) * default_dt)
assert_allclose(mon.t[mon.i[:] == 4], arange(9, n_timesteps + 9, clock_multiplier) * default_dt)

This could be a general issue of how we compute the circular eventspaces and might also apply to a normal thresholder running on a different clock (should be tested!).

EDIT:
This does also apply to NeuronGroup on a different clock. I renamed the test above to test_circular_evenstpace_different_clock_spikegenerator and added another test with NeuronGroup names test_circular_evenstpace_different_clock_neurongroup.