NeuralEnsemble / PyNN

A Python package for simulator-independent specification of neuronal network models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistency when setting the amplitude times of StepCurrentSource after several simulation runs

RCagnol opened this issue · comments

Hi,

I noticed that the amplitude times of StepCurrentSource have inconsistent values when they're being set after a call to run(), when using nest as a simulator. For example the following code:

import nest
import pyNN.nest as sim
from pyNN.nest import simulator

cs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0])
print(f'Nest time: {nest.biological_time}')
print(f'PyNN time: {simulator.state.t}')
print(f'Nest amplitude times: {nest.GetStatus(cs._device)[0]["amplitude_times"]}')
print(f'PyNN amplitude times: {cs.get_parameters()["times"].base_value}')

sim.run(50)
cs.set_parameters(times=[50.0], amplitudes=[5],copy=False)
print(f'Nest time: {nest.biological_time}')
print(f'PyNN time: {simulator.state.t}')
print(f'Nest amplitude times: {nest.GetStatus(cs._device)[0]["amplitude_times"]}')
print(f'PyNN amplitude times: {cs.get_parameters()["times"].base_value}')

Outputs the following, with amplitude times lower than the current biological time when they're being set after the first run:

Nest time: 0.0
PyNN time: 0.0
Nest amplitude times: [0.1]
PyNN amplitude times: [0.1]
Nest time: 50.1
PyNN time: 50.0
Nest amplitude times: [49.9]
PyNN amplitude times: [49.9]

Naively, I'd suppose that the source of this error lies in the _check_step_times() method of the NestStandardCurrentSource class, where

        ctr = np.searchsorted(times, resolution, side="right") - 1
        if ctr >= 0:
            times[ctr] = resolution
            times = times[ctr:]
            amplitudes = amplitudes[ctr:]

should be replaced by:

        ctr = np.searchsorted(times, state.t + resolution, side="right") - 1
        if ctr >= 0:
            times[ctr] = state.t + resolution
            times = times[ctr:]
            amplitudes = amplitudes[ctr:]

I also don't really understand why the amplitude times equals to 0 are set to 0 + resolution when the biological time is still equal to 0, as nest.biological_time and simulator.state.t are both equal to 0 at this moment.

I have also a question about the different values that nest.biological_time and simulator.state.t output. I understand that in the run() method of the _State class, the simulations last 1 timestep more than wanted to get all the recorded data from Nest. But why does this occur only when self.running is set to False, i.e. when calling run() a second time this additional timestep of simulation won't be added. This doesn't impair at all the gathering of all the recorded data corresponding to the 'second simulation'?

(Sorry for the ugly edit, I posted the issue by mistake while I was still writing it)