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 *
set_device('cpp_standalone')
@implementation('cpp','''
// 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'
run(100*ms)