I’m hoping to define a user-defined cpp function first and apply it to multiple brian2 object later. In the following code, all the user-function related code are pre-defined, i.e.
# read the cpp code
def read_spike_rate_code(spike_mon_obj):
with open(os.path.join(current_dir,'spike_rate.cpp')) as f:
spike_rate_code = f.read()
return spike_rate_code.replace('%%SPIKECOUNT%%',
device.get_array_name(spikemon.variables['count']))
# defined user function
@implementation('cpp', spike_rate_code,
dependencies={'ta2d': ta2d})
@check_units(t=second, i=1, result=1)
def spike_rate(scale, t, i):
raise NotImplementedError('use standalone mode')
Then I tried to use it in this way:
spike_rate_code = read_spike_rate_code(spikemon) #!!!!!
........
input_neurons.run_regularly('rate=spike_rate(scale, t, i)*Hz', dt=0.2*ms)
I got the following error because the cpp code need to be defined in the decorator:
@implementation('cpp', spike_rate_code,
NameError: name 'spike_rate_code' is not defined
Is it possible to bypass this issue? The complete code are attached. Thanks for the help
mm.py (1.1 KB)
spike_rate.cpp.txt (238 Bytes)