Description of problem
Hello, i can’t seem to be able to run my code on c++ standalone mode.
I get the error :
Cannot retrieve the values of state variables in standalone code before the simulation has been run.
Also i can’t seems to figure out how to do the multithreading. My code takes like 17 hours to run even with an i9.
Thank you for your help
Minimal code to reproduce problem
import numpy as np
from brian2 import units
from sklearn import datasets, model_selection
from brian2 import *
import matplotlib.pyplot as plt
prefs.codegen.target = 'cython'
set_device('cpp_standalone', build_on_run=False)
time_per_sample=350*ms
resting_time = 0.15 * units.second
N = 1000
F = 10 * Hz
gmax = 1 / 5
# Création des neurones
tau = 10 * ms
eqs_neuron = '''
dv/dt = -v/tau : 1
'''
input_group = PoissonGroup(N, rates=F)
neuron = NeuronGroup(1, model=eqs_neuron, threshold='v>1', reset='v=0', method='euler')
# Création des synapses
eqs_stdp = '''
w : 1
da/dt = -a / tau_a : 1 (event-driven)
db/dt = -b / tau_b : 1 (event-driven)
tau_a = 20*ms : second
tau_b = 20*ms : second
A = 0.001 *gmax : 1
B = -0.001 *gmax : 1
gmax = 1./5. : 1
'''
on_pre = '''
v_post += w
a += A
w = clip(w + b,0,gmax)
'''
on_post = '''
b += B
w = clip(w + a,0,gmax)
'''
S = Synapses(input_group, neuron, model=eqs_stdp, on_pre=on_pre, on_post=on_post, method='euler')
S.connect()
S.w = 'rand() * gmax'
mon = StateMonitor(S, 'w', record=[0, 1])
s_mon = SpikeMonitor(input_group)
net = Network(input_group, S, neuron,s_mon,mon)
number_of_epochs = 1
for i in range(number_of_epochs):
print('Starting iteration %i' % i)
for i in range(10):
# Configurer le taux d'entrée
input_group.rates = i*10 * units.Hz
# Simuler le réseau
net.run(time_per_sample)
a=s_mon.count
# Laisser les variables retourner à leurs valeurs de repos
net.run(resting_time)
print(S.w)
What you have already tried
i tried using reinit() and activate() but without success
Full traceback of error (if relevant)
Traceback (most recent call last):
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-343826d46dda>", line 1, in <module>
runfile('/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/minModel.py', wdir='/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/minModel.py", line 66, in <module>
print(S.w)
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/core/variables.py", line 1398, in __repr__
values = repr(self[:])
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/core/variables.py", line 824, in __getitem__
return self.get_item(item, level=1)
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/core/variables.py", line 816, in get_item
values = self.get_with_index_array(item)
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/core/base.py", line 278, in device_override_decorated_function
return func(*args, **kwds)
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/core/variables.py", line 1103, in get_with_index_array
return variable.get_value()[indices]
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/core/variables.py", line 464, in get_value
return self.device.get_value(self)
File "/Users/carlos/Documents/LeTaffe/Neurosciences/projet2/STDP/venv/lib/python3.9/site-packages/brian2/devices/cpp_standalone/device.py", line 513, in get_value
raise NotImplementedError('Cannot retrieve the values of state '
NotImplementedError: Cannot retrieve the values of state variables in standalone code before the simulation has been run.
WARNING Active device does not have an attribute 'shape', ignoring this [brian2.devices.device]
WARNING Active device does not have an attribute 'shape', ignoring this [brian2.devices.device]
WARNING Active device does not have an attribute 'shape', ignoring this [brian2.devices.device]
WARNING Active device does not have an attribute 'shape', ignoring this [brian2.devices.device]