Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pyNN/nest/standardmodels/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ def _check_step_times(self, times, amplitudes, resolution):
raise ValueError("Step current timestamps should be monotonically increasing.")
# NEST specific: subtract min_delay from times (set to 0.0, if result is negative)
times = self._delay_correction(times)
# find the last element <= dt (we find >dt and then go one element back)
# find the last element <= biological_time + dt (we find >biological_time+dt and go one back)
# this corresponds to the first timestamp that can be used by NEST for current injection
ctr = np.searchsorted(times, resolution, side="right") - 1
min_time = state.t_kernel + resolution
ctr = np.searchsorted(times, min_time, side="right") - 1
if ctr >= 0:
times[ctr] = resolution
times[ctr] = min_time
times = times[ctr:]
amplitudes = amplitudes[ctr:]
# map timestamps to actual simulation time instants based on specified dt
Expand Down
30 changes: 30 additions & 0 deletions test/system/scenarios/test_electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,36 @@ def test_issue631(sim):
assert (np.all(i_step.magnitude[:int(200.0 / sim_dt) - 1:] == 0))


@run_with_simulators("nest")
def test_issue759(sim):
"""
Test that StepCurrentSource.set_parameters() correctly handles times set at the current
simulation time after a run. Previously, times at t=state.t would be sent to NEST as
t - min_delay, which is in the past, causing no current injection.
"""
dt = 0.1
sim.setup(timestep=dt, min_delay=dt)

cells = sim.Population(1, sim.IF_curr_exp(v_rest=-65.0, v_thresh=-55.0, tau_refrac=5.0))
cells.initialize(v=-65.0)
cells.record('spikes')

cs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0])
cs.inject_into(cells)

sim.run(50.0) # no current, no spikes expected

cs.set_parameters(times=[50.0], amplitudes=[1.0]) # 1.0 nA drives V above threshold

sim.run(50.0) # current active, spikes expected

spikes = cells.get_data().segments[0].spiketrains[0]
sim.end()

assert len(spikes) > 0, "Expected spikes in second run interval; current injection may have failed"
assert all(t >= 50.0 for t in spikes.magnitude), "Spikes occurred before current injection started"


if __name__ == '__main__':
from pyNN.utility import get_simulator
sim, args = get_simulator()
Expand Down
Loading