Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RCagnol opened this issue Oct 7, 2022 · 0 comments
Milestone

Comments

@RCagnol
Copy link

RCagnol commented Oct 7, 2022

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)

@RCagnol RCagnol changed the title Inconsistency in thee Inconsistency when setting the amplitude times of StepCurrentSource after several simulation runs Oct 7, 2022
@apdavison apdavison added this to the 0.10.2 milestone Oct 13, 2022
@apdavison apdavison modified the milestones: 0.10.2, 0.11.0 Feb 5, 2023
rozsatib added a commit to rozsatib/mozaik that referenced this issue May 5, 2023
@apdavison apdavison modified the milestones: 0.11.0, 0.13.0 Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants