Problem changing spike values in SpikeGeneratorGroup during simulation

Hi Brian Team,

I’m totally new to Brian2 and was wondering how to correctly change an input stimuli using the SpikeGeneratorGroup while iterating over a dataset (h5 dataset in my case) during a simulation. So, I start with a 10 neurons SpikeGeneratorGroup that is not firing anything.

My goal is to iterate through an h5 dataset and run my network for let’s say 1 second while changing the spikes from the first neuron by the current spike train and the other 9 by poisson spike trains. I have a function called make_input_spikes that merges a spike train from the dataset to an array of 9 other spike trains created by a poisson process and returns the indices and the spike times that I then give to set_spikes to redefine the spike trains within the generator at each iteration like so :

for data, target in dataset:
    current_times, current_indices = make_input_spikes(...)
    input_neurons.set_spikes(current_indices, current_times)
    net.run(300 * ms, report = 'text')

Each spike train in the dataset has a length of 300 with a 1*ms timestep. Of course the spikes after the first iteration are ignored cause they lie before the current simulation time.

WARNING    The SpikeGeneratorGroup contains spike times earlier than the start time of the current run (t = 1. second), these spikes will be ignored. [brian2.input.spikegeneratorgroup.ignored_spikes]

So I’m a bit confused about how I can just continuously feed new known spike trains to the Network.
Or maybe I’m just totally wrong in the way I use the simulator :blush:

Thank you for your support.

Brad.

Actually found a solution to this using a bit of documentation, sorry :blush:
So for my experiments I first need to reset some spike trains during the simulation regularly, I tried different things that seem to work, the first one is a network operation that reset my spikes without the knowledge of the data I have :

    @network_operation(dt=input_length*ms)
    def reset_spikes(t):
        spike_times, indices = make_poisson_process(...)
        input_neurons.set_spikes(indices, spike_times + t)

The make_poisson_process in that case just returns an array of spike trains following a poisson distribution. The other thing was just to add the simulation duration time to the spike times within the dataset iteration now using the data to create the spikes with my make_input_spikes function :

....
for idx, (data, target) in enumerate(dataset):
    current_times, current_indices = make_input_spikes(...)
    if idx == 0:
        input_neurons.set_spikes(current_indices, current_times)
    else:
        input_neurons.set_spikes(current_indices, current_times + (duration* idx))
    net.run(duration, report = 'text')
    ....

So I’m using this second piece of code as it’s giving me more flexibility in handling the data and what’s going on during the simulation as some other things have to be done, like resting the network later for example.

Silly question solved :yum:

Not a silly question at all :slight_smile: We are lacking examples that show more complex workflows like your case, our examples are mostly using a straightforward “setup model + run it once” approach.

PS: For simpler code, you can get rid of the if idx == 0 part, the duration * 0 will do the trick all by itself :slight_smile:

I’ll probably post more on this example if everything works fine then as I plan to finish these experiments real soon.

Ah true, makes more sense, I’m going to change that now, thank you very much ! :slightly_smiling_face: