Real Time Monitor

I ignore whether it has ever been discussed, but a very useful feature IMHO would be to monitor ongoing spiking activity as we simulate a network. In many practical contexts, before producing some final simulation, we need to explore a network’s dynamics, for example, to see whether we are hitting the right attractor upon which to leverage our simulations. I need to change the duration parameter in the run and retrieve my monitor and plot it accordingly. It would be nice instead of accessing the monitor as the recording goes on, without the need to run full simulations. If I were coding in C/C++, that would be easy, as I have a file stream open for the whole duration of the simulation, and the stream grows in time, while I can check my network activity as it develops in real/time, by GNUPLOT, for example.

Monitors that write their results to disk online has been on our list for a long time (see e.g. github issue #289, but no-one did find the time to actually do it (and the details of syntax and functionality have never been decided). If you don’t mind writing C++ code, there’s nothing that stops you from using our extension mechanisms from doing it, though. Here’s a simple example using a custom function. This will write all the spikes from the group to a single text file at every time step:)

from brian2 import *

// Note that functions always need a return value at the moment
double store_spike(int i, double t) {
    static std::ofstream spike_file("/some/path/spikes.txt");  // opens the file the first time
    spike_file << i << " " << t << std::endl;
    return 0.;  // unused
@check_units(i=1, t=second, result=1)
def store_spike(i, t):
    raise NotImplementedError('Use standalone mode')

G = NeuronGroup(10, 'rates : Hz (constant)', threshold='rand()<rates*dt',
                reset='dummy_var = store_spike(i, t)')
G.rates = '50*Hz + i*50*Hz'