Skip to content

Commit

Permalink
Merge pull request #488 from appukuttan-shailesh/issue_487
Browse files Browse the repository at this point in the history
Fixes issue #487: Updates _update_iclamp() for NEURON
  • Loading branch information
apdavison committed Jun 19, 2017
2 parents 9b5c68a + 46cfbea commit 08d325c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pyNN/neuron/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,17 @@ def _pre_run(self):
assert local_minimum_delay >= self.min_delay, \
"There are connections with delays (%g) shorter than the minimum delay (%g)" % (local_minimum_delay, self.min_delay)

def _update_current_sources(self):
def _update_current_sources(self, tstop):
for source in self.current_sources:
for iclamp in source._devices:
source._update_iclamp(iclamp)
source._update_iclamp(iclamp, tstop)

def run(self, simtime):
"""Advance the simulation for a certain time."""
self.run_until(self.tstop + simtime)

def run_until(self, tstop):
self._update_current_sources()
self._update_current_sources(tstop)
self._pre_run()
self.tstop = tstop
#logger.info("Running the simulation until %g ms" % tstop)
Expand Down
16 changes: 13 additions & 3 deletions pyNN/neuron/standardmodels/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,28 @@ def _reset(self):
self._times = None
self._generate()
for iclamp in self._h_iclamps.values():
self._update_iclamp(iclamp)
self._update_iclamp(iclamp, 0.0) # send tstop = 0.0 on _reset()

def _update_iclamp(self, iclamp):
def _update_iclamp(self, iclamp, tstop):
if not self._is_playable:
iclamp.delay = max(0, self.start - simulator.state.t)
iclamp.delay = self.start
iclamp.dur = self.stop - self.start
iclamp.amp = self.amplitude

if self._is_playable:
iclamp.delay = 0.0
iclamp.dur = 1e12
iclamp.amp = 0.0

# check exists only for StepCurrentSource (_is_playable = True, _is_computed = False)
# t_stop should be part of the time sequence to handle repeated runs
if not self._is_computed and tstop not in self._h_times.to_python():
ind = self._h_times.indwhere(">=", tstop)
if ind == -1:
ind = self._h_times.size()
self._h_times.insrt(ind, tstop)
self._h_amplitudes.insrt(ind, self._h_amplitudes.x[int(ind)-1])

self._h_amplitudes.play(iclamp._ref_amp, self._h_times)

def set_native_parameters(self, parameters):
Expand Down
48 changes: 47 additions & 1 deletion test/system/scenarios/test_electrodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


from nose.tools import assert_equal, assert_true
from nose.tools import assert_equal, assert_true, assert_false
from numpy.testing import assert_array_equal
import quantities as pq
import numpy
Expand Down Expand Up @@ -311,6 +311,51 @@ def issue483(sim):
assert (len(v) == (int(simtime/dt) + 1))


@register()
def issue487(sim):
"""
Test to ensure that DCSource and StepCurrentSource work properly
for repeated runs. Problem existed under pyNN.neuron.
Three sub-tests performed:
1) DCSource active across two runs
2) StepCurrentSource active across two runs
3) DCSource active only during second run (earlier resulted in no current input)
"""
dt = 0.1
sim.setup(timestep=dt, min_delay=dt)

v_rest = -60.0
cells = sim.Population(3, sim.IF_curr_exp(v_thresh=-55.0, tau_refrac=5.0, v_rest=v_rest))
cells.initialize(v=v_rest)
cells.record('v')

dcsource = sim.DCSource(amplitude=0.15, start=25.0, stop=115.0)
cells[0].inject(dcsource)

step = sim.StepCurrentSource(times=[25.0, 75.0, 115.0], amplitudes=[0.05, 0.10, 0.20])
cells[1].inject(step)

dcsource_2 = sim.DCSource(amplitude=0.15, start=115.0, stop=145.0)
cells[2].inject(dcsource_2)

simtime = 100.0
sim.run(simtime)
sim.run(simtime)

v = cells.get_data().segments[0].filter(name="v")[0]
sim.end()
v_dc = v[:, 0]
v_step = v[:, 1]
v_dc_2 = v[:, 2]

# check that membrane potential does not fall after end of first run
assert_true (v_dc[int(simtime/dt)] < v_dc[int(simtime/dt)+1])
assert_true (v_step[int(simtime/dt)] < v_step[int(simtime/dt)+1])
# check that membrane potential of cell undergoes a change
v_dc_2_arr = numpy.squeeze(numpy.array(v_dc_2))
assert_false (numpy.isclose(v_dc_2_arr, v_rest).all())


if __name__ == '__main__':
from pyNN.utility import get_simulator
sim, args = get_simulator()
Expand All @@ -323,3 +368,4 @@ def issue483(sim):
issue445(sim)
issue451(sim)
issue483(sim)
issue487(sim)

0 comments on commit 08d325c

Please sign in to comment.