Brian2GeNN: multiple synaptic output variables not supported

Description of problem

I am trying to reproduce the method of this article by Masquelier and Deco in Brian2: Network Bursting Dynamics in Excitatory Cortical Neuron Cultures Results from the Combination of Different Adaptive Mechanism. In short; it simulates a network of 800 fully connected excitatory LIF neurons with adaptation and STP. Reproducing it worked out and I am getting almost the same results. However, one simulation of 60 second takes about 3 to 4 hours to run. Therefore I am trying to speed it up by running it on the powerful GPU I have, through Brian2GeNN. First run I got the error: ‘‘brian2genn only supports a single summed variable per Synapses group.’’ So I rewrote to only sum s_nmda, instead of also s_ampa. Now I get the error: ‘‘brian2genn only supports a either a single synaptic output variable or a single summed variable per Synapses group.’’ and when I look in the Brian2GeNN documentation it says: ‘‘Summed variables are currently not supported in GeNN ‘’. So at this point it is unclear to me if no summed variables at all are allowed, or just not more than one. The manual states as a solution: ‘’ However, a simple form of summed variable is supported and intrinsic to GeNN. This is the action of ‘pre’ code in a Synapses definition onto a pre-synaptic variable. The allowed interaction is summing onto one pre-synaptic variable from each Synapses group.’’ But I am really unsure what this means and how to do this, an example would be super helpful.

The documentation of Brian2Genn also states ‘’ GeNN does not have support for multiple synaptic pathways as Brian 2 does, you can therefore only use a single pre and post pathway with Brian2GeNN’’. This is also slightly vague to me. Does this mean I cannot have more than one variable update per synapse? Or just not explicit pathways with names. And if it is not possible to have both nmda gating variable change and ampa gating variable change in one synapse with Brian2GeNN, how can I work around this? Should I make multiple Synapses groups?

Minimal code to reproduce problem

from scipy.io import *
from scipy.sparse import *
from scipy import *
import os
from numpy import *
from numpy import random
from brian2 import *
import brian2genn

set_device('genn')

Ne = 800  

#receptor parameters
delta = 0.08       
g_ampa = ((104.0*(1+10*delta))/1000)*nS
g_nmda = ((327*(1-delta))/1000)*nS
E_ampa = 0*mV
E_nmda = 0*mV
tau_ampa = 2*ms
taus_nmda = 100*ms
taux_nmda = 2*ms
alpha_nmda = 0.5*kHz

#Adaptation parameters
E_AHP = -80*mV
g_AHP = 10*nS
alpha_Ca = 0.0145  
tau_Ca = 4000*ms

#neuron model parameters
sigma = 6.5*mV 
Cm = 0.5*nF
gl = 25*nS
El = -70*mV
Vthr = -50*mV
Vreset = -55*mV
refr = 2. * ms      

#STP parameters
tau_f = 1600*ms
tau_d = 800*ms
U = 0.025

#Define simple model with reset
eqs = Equations('''dV/dt  = sigma*xi*(2*gl/Cm)**.5 + 1/Cm * (-gl*(V-El)-I_syn+I_I_AHP) :volt
I : amp
I_syn = I_ampa + I_nmda  : amp
I_ampa = g_ampa*(V-E_ampa)*s_ampa_tot : amp
I_nmda = g_nmda*(V-E_nmda)*s_nmda_tot/(1+exp(-0.062*V/mV)/3.57) : amp
s_nmda_tot :1
s_ampa_tot : 1
I_AHP = -g_AHP*Ca*(V-E_AHP) : amp
dCa/dt = - Ca / tau_Ca : 1 ''')

P = NeuronGroup(Ne, eqs, threshold='V>Vthr', reset='''V=Vreset
                                                    Ca += alpha_Ca''', refractory=refr, order=1,  method='euler')
P.V = -70*mV

#Define synapse models
eqs_synapsmodel = '''
s_nmda_tot_post = w *u_f * x_d * s_nmda :1 (summed)
ds_nmda/dt = -s_nmda/(taus_nmda)+alpha_nmda*x*(1-s_nmda) : 1 (clock-driven)
s_ampa_tot_post = w *u_f * x_d * s_ampa :1 (summed)
ds_ampa/dt = -s_ampa/tau_ampa :1 (clock-driven)
dx/dt = -x/(taux_nmda) :1 (clock-driven)
dx_d/dt = (1-x_d)/tau_d :1 (event-driven)
du_f/dt = (U-u_f)/tau_f :1 (event-driven)
w : 1
'''

eqs_onpre = '''
x += 1 
u_f += U*(1-u_f)
x_d *= (1-u_f)
s_ampa += 1
'''

Conn = Synapses(P, P, model=eqs_synapsmodel, on_pre=eqs_onpre, delay=3*ms, method='euler')
Conn.connect() 
Conn.w[:] = 9.25
Conn.u_f[:] = U
Conn.x_d[:] = 1

run(3*second, report='text')

What you have aready tried

I’ve tried changing the neuron and synapse equations to:

eqs = Equations('''dV/dt  = sigma*xi*(2*gl/Cm)**.5 + 1/Cm * (-gl*(V-El)-I_syn+I+I_AHP) :volt
I : amp
I_syn = I_ampa + I_nmda  : amp
I_ampa = g_ampa*(V-E_ampa)*s_ampa : amp
I_nmda = g_nmda*(V-E_nmda)*s_nmda_tot/(1+exp(-0.062*V/mV)/3.57) : amp
s_nmda_tot :1
ds_ampa/dt = -s_ampa/tau_ampa :1 
I_AHP = -g_AHP*Ca*(V-E_AHP) : amp
dCa/dt = - Ca / tau_Ca : 1 ''')

eqs_synapsmodel = '''
s_nmda_tot_post = w *u_f * x_d * s_nmda :1 (summed)
ds_nmda/dt = -s_nmda/(taus_nmda)+alpha_nmda*x*(1-s_nmda) : 1 (clock-driven)
dx/dt = -x/(taux_nmda) :1 (clock-driven)
dx_d/dt = (1-x_d)/tau_d :1 (event-driven)
du_f/dt = (U-u_f)/tau_f :1 (event-driven)
w : 1
'''

eqs_onpre = '''
x += 1 
u_f += U*(1-u_f)
x_d *= (1-u_f)
s_ampa += w *u_f * x_d
'''

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

Traceback only goes back to ‘’ exec(code, self.locals)’’. The error occurred after ‘‘building genn executable …’’.

I hope the questions are somewhat clear. Thanks in advance!

Update: even though the above question remains, I already get an error when testing Brian2GeNN on a simple simulation without synapses. I get the traceback:

Traceback (most recent call last):
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/home/Nina/Downloads/pycharm-2020.2.3/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/Nina/Downloads/pycharm-2020.2.3/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/Nina/PycharmProjects/pythonProject/Masquelier_single.py", line 98, in <module>
    run(1*second, report='text')
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/units/fundamentalunits.py", line 2434, in new_f
    result = f(*args, **kwds)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/magic.py", line 374, in run
    namespace=namespace, profile=profile, level=2+level)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/magic.py", line 232, in run
    namespace=namespace, profile=profile, level=level+1)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/base.py", line 276, in device_override_decorated_function
    return getattr(curdev, name)(*args, **kwds)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 1845, in network_run
    level=level + 1)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/devices/cpp_standalone/device.py", line 1511, in network_run
    self.build(direct_call=False, **self.build_options)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 884, in build
    self.copy_source_files(writer, directory)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 1798, in copy_source_files
    super(GeNNDevice, self).copy_source_files(writer, directory)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/devices/cpp_standalone/device.py", line 895, in copy_source_files
    writer.header_files.add('brianlib/'+file)
AttributeError: 'list' object has no attribute 'add'

Hi Nina, I’ll reply to your main question later. Just regarding the last question: the error you are seeing seems to indicate that you are using an older version of Brian 2 than the one your Brian2GeNN installation is compatible with.

I am using brian2 2.4.2 on python 3.6.12

Oh, apologies, it is actually the other way round: the latest Brian2GeNN release is from summer last year when Brian was still at 2.3. We did not do a release since then (we should…), so currently you’ll have to use Brian2GeNN from master for Brian 2.4.2.

I am sorry, I am not sure what it means to ‘use from master’ .

Sorry for the jargon, it means to use the current version in development from its “master” branch on github (GitHub - brian-team/brian2genn: Brian 2 frontend to the GeNN simulator). But it is a bit more complicated to install than a normal version and there’s no good reason why we do not have a easily installable version of Brian2GeNN that works with the latest release of Brian2. So if you give me a couple of minutes, I will make a new Brian2GeNN 1.6 release right away that you can then install in the usual way with pip.

Wow! Thank you so much, that would be amazing!

I made the 1.6 release, if you use something like pip install --upgrade brian2genn it should pick up the new version.

Thank you so much for the elaborate help. I successfully installed the new version of Brian2GeNN! The old error is gone but now I am having some problems adding the GeNN’s bin directory to my path but I will probably figure it out and then I will let you know when it all works! Thanks again!

Ok, let me come back to the initial questions. BTW: the model would be a nice addition to our “frompapers” example section – you are very welcome to contribute it if it is working nicely and reproduces their results!

First of all, I think there is a small error in the equations: the x_d and u_f variables cannot be event-driven, since they are referenced in the summed variable. Being event-driven means that the variables are only updated whenever a spike arrives, i.e. at the beginning of the on_pre block. The summed variable on the other hand is calculated at every time step, in between spikes it will therefore use incorrect values. It does not make much of a difference in your case, though, since the time between two spikes is probably small relative to the very long time constants tau_d and tau_f.

Unfortunately, fixing this will make the simulation even slower (for me, it is not that slow, though, the 3s simulation takes about 2min on my machine).

Regarding Brian2GeNN, it is not clear whether it will speed up your simulation much, due to the continuous links between all cells (GPU acceleration will be biggest for computationally intensive but independent computations, e.g. a complex neuron model with many equations that can be solved independently for each neuron).

Regarding the issues with summed variables and Brian2GeNN: Brian2GeNN does indeed support summed variables (since version 1.4), but the documentation was out of date :unamused: I have updated it with the 1.6 release. It now also lists the two restrictions you encountered: it only supports a single summed variable and it cannot be combined with another action on the post-synaptic cell (in your second code, the s_ampa += … refers to s_ampa in the post-synaptic group). So to get it working with Brian2GeNN, you would have to use one Synapses object for the AMPA connection and one for the NMDA connection.

Independent of Brian2GeNN, there are ways to simulate this model much faster, but this would make it less general. Are you planning to continue to use the same model structure as they have, i.e. all-to-all connectivity and homogeneous synaptic delays? If yes, one can reformulate the equations in a way that makes use of this structure and I can give you some more pointers on how to do that. The disadvantage would be that you could no longer change the connectivity or delays as you can in the current model.

This refers to multiple pathways in this sense, i.e. have multiple on_pre statements triggered with different delays or triggered by different events in the pre-synaptic group. This should not apply in your case here. You can update multiple variables in an on_pre statement with Brian2GeNN, but (if I remember correctly) you can only update one post-synaptic variable – in your first code example, you are not updating any post-synaptic variables but only synaptic variables.

Hope that all makes sense!

That is a very clear and complete answer! Thank you very much!

I will definitely do that if it works properly. Right now I need to increase the weights just a little bit to get the same results as they do and I am still figuring out why exactly.

I realized that at some point because the authors of the article shared their code (made in Brian1) and they use network operations to make the code more efficient. However, I am planning on applying a distribution to the delays and trying out different kinds of connectivity. But thank you for the offer.

2 Likes

Unfortunately, after a day of trying, I still didn’t get it to work. There is a big chance this is just because I messed something up with the paths and the files or the way cuda is installed or something like that (I’m new to Linux). However, I cannot figure out what exactly goes wrong so I thought maybe there is a chance you can see right away what goes wrong. I realise this support group is not exactly meant for these types of problems so if you don’t see the problem right away please don’t waste your time on this.

I have the very simple script:
from brian2 import *
import brian2genn
import os
os.environ[‘CUDA_PATH’] = ‘usr/local/cuda’
set_device(‘genn’)

tau = 10*ms
eqs = '''
dv/dt = (1-v)/tau : 1
'''

G = NeuronGroup(1, eqs)
run(100*ms)

and I get this output, error and traceback (sorry it is very long):

runfile('/home/Nina/PycharmProjects/pythonProject/main.py', wdir='/home/Nina/PycharmProjects/pythonProject')
INFO       The following preferences have been changed for Brian2GeNN, reset them manually if you use a different device later in the same script: codegen.loop_invariant_optimisations, core.network.default_schedule [brian2.devices.genn]
running brian code generation ...
INFO       No numerical integration method specified for group 'neurongroup', using method 'exact' (took 0.03s). [brian2.stateupdaters.base.method_choice]
building genn executable ...
In file included from /home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda/optimiser.h:7:0,
['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp']
                 from optimiser.cc:1:
make: Entering directory `/home/Nina/Downloads/genn-4.3.3/src/genn/generator'
/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda/backend.h:13:10: fatal error: cuda.h: No such file or directory
if [ -w /home/Nina/Downloads/genn-4.3.3/lib ]; then make -C /home/Nina/Downloads/genn-4.3.3/src/genn/genn; fi;
 #include <cuda.h>
if [ -w /home/Nina/Downloads/genn-4.3.3/lib ]; then make -C /home/Nina/Downloads/genn-4.3.3/src/genn/backends/cuda; fi;
          ^~~~~~~~
make[1]: Entering directory `/home/Nina/Downloads/genn-4.3.3/src/genn/backends/cuda'
compilation terminated.
mkdir -p /home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda
In file included from backend.cc:1:0:
mkdir -p /home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda
/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda/backend.h:13:10: fatal error: cuda.h: No such file or directory
mkdir -p /home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda
 #include <cuda.h>
          ^~~~~~~~
/home/Nina/.conda/envs/brianenv/bin/x86_64-conda_cos6-linux-gnu-c++ -std=c++11 -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/Nina/.conda/envs/brianenv/include -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/PycharmProjects/pythonProject -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -DMODEL=\"/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/magicnetwork_model.cpp\" -DBACKEND_NAMESPACE=CUDA -I"usr/local/cuda/include" -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -I"usr/local/cuda/include" -c -o /home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda/backend.o backend.cc
compilation terminated.
make[1]: *** [/home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda/optimiser.o] Error 1
/home/Nina/.conda/envs/brianenv/bin/x86_64-conda_cos6-linux-gnu-c++ -std=c++11 -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/Nina/.conda/envs/brianenv/include -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/PycharmProjects/pythonProject -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -DMODEL=\"/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/magicnetwork_model.cpp\" -DBACKEND_NAMESPACE=CUDA -I"usr/local/cuda/include" -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -I"usr/local/cuda/include" -c -o /home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda/presynapticUpdateStrategy.o presynapticUpdateStrategy.cc
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [/home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda/backend.o] Error 1
/home/Nina/.conda/envs/brianenv/bin/x86_64-conda_cos6-linux-gnu-c++ -std=c++11 -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/Nina/.conda/envs/brianenv/include -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/PycharmProjects/pythonProject -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -DMODEL=\"/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/magicnetwork_model.cpp\" -DBACKEND_NAMESPACE=CUDA -I"usr/local/cuda/include" -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -I"usr/local/cuda/include" -c -o /home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda/optimiser.o optimiser.cc
presynapticUpdateStrategy.cc:7:10: fatal error: cuda_runtime.h: No such file or directory
make[1]: Entering directory `/home/Nina/Downloads/genn-4.3.3/src/genn/genn'
 #include <cuda_runtime.h>
make[1]: Nothing to be done for `all'.
          ^~~~~~~~~~~~~~~~
make[1]: Leaving directory `/home/Nina/Downloads/genn-4.3.3/src/genn/genn'
compilation terminated.
make[1]: Leaving directory `/home/Nina/Downloads/genn-4.3.3/src/genn/backends/cuda'
make[1]: *** [/home/Nina/Downloads/genn-4.3.3/obj/genn/backends/cuda/presynapticUpdateStrategy.o] Error 1
make: Leaving directory `/home/Nina/Downloads/genn-4.3.3/src/genn/generator'
make: *** [backend] Error 2
genn-buildmodel.sh:86: error 50: command failure
ERROR      Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at <http://brian.discourse.group/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: /tmp/brian_debug_x7lc40qk.log  Additionally, you can also include a copy of the script that was run, available at: /tmp/brian_script__0ltb__3.py You can also include a copy of the redirected std stream outputs, available at /tmp/brian_stdout_c1lcmvbt.log and /tmp/brian_stderr_j6mjpq_d.log Thanks! [brian2]
Traceback (most recent call last):
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 882, in build
    self.compile_source(debug, directory, use_GPU)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 1169, in compile_source
    check_call(args, cwd=directory, env=env)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/subprocess.py", line 311, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp']' returned non-zero exit status 50.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/home/Nina/Downloads/pycharm-2020.2.3/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/Nina/Downloads/pycharm-2020.2.3/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/Nina/PycharmProjects/pythonProject/main.py", line 13, in <module>
    run(100*ms)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/units/fundamentalunits.py", line 2434, in new_f
    result = f(*args, **kwds)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/magic.py", line 374, in run
    namespace=namespace, profile=profile, level=2+level)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/magic.py", line 232, in run
    namespace=namespace, profile=profile, level=level+1)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/base.py", line 276, in device_override_decorated_function
    return getattr(curdev, name)(*args, **kwds)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 1825, in network_run
    level=level + 1)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/devices/cpp_standalone/device.py", line 1511, in network_run
    self.build(direct_call=False, **self.build_options)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 888, in build
    returncode=ex.returncode)
RuntimeError: Project compilation failed (Command ['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp'] failed with error code 50).
See the output above (if any) for more details.

The cuda and genn bin are in the PATH like specified in the brian2genn installation instructions. cuda and genn are installed properly (although I didn’t install cuda myself and it was done some time ago).

It this doesn’t work I’ll probably take your word for it that Brian2Genn will not speed up my script much and just leave it be.

Getting everything to run with CUDA can be tricky, and using the conda C++ compiler can complicate things even further. Are you sure that your CUDA installation is under /usr/local/cuda? On Linux there are two ways of installing CUDA, one is via the standard package manager (e.g. apt on Debian/Ubuntu, yum on RedHat, etc.), and one is via the installer from the CUDA homepage. The former installs CUDA in the standard paths, if I remember correctly you would have to use CUDA_PATH=/usr with it. The latter will install it into a versioned directory, I think, i.e. rather something like /usr/local/cuda-11.1.

And just to double check that CUDA is correctly in the path: a call from the Linux terminal to nvcc works?

I appears cuda in usr/local is a folder that points to cuda-7.5 which is also in the usr/local. So now i’ve done this in the linux terminal:

(brianenv) [Nina@utwks62681 bin]$ echo ''export CUDA_PATH=/usr/local/cuda-7.5'' >> ~/.bash_profile
(brianenv) [Nina@utwks62681 bin]$ echo ''export PATH=$PATH:$CUDA_PATH/bin'' >> ~/.bash_profile
(brianenv) [Nina@utwks62681 bin]$ echo ''export PATH=$PATH:/home/Nina/Downloads/genn-4.3.3/bin'' >> ~/.bash_profile

When I then open a terminal indeed nvcc doesn’t work although the path seems to be okay (has both cuda and genn bin?

(brianenv) [Nina@utwks62681 ~]$ echo $PATH
/home/Nina/.conda/envs/brianenv/bin:/usr/condabin:/usr/local/cuda-7.5/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/puttenmjam/.local/bin:/home/puttenmjam/bin:/opt/scripts:/var/lib/snapd/snap/bin:/Nina/Downloads/genn-4.3.3/bin
(brianenv) [Nina@utwks62681 ~]$ nvcc
nvcc fatal   : No input files specified; use option --help for more information
(brianenv) [Nina@utwks62681 ~]$ 

Now if I open python through this terminal and run it I get the error: RuntimeError: Add GeNN’s bin directory to the path or set the devices.genn.path preference. Even though it is in the path right?

The CUDA path looks ok and nvcc (i.e. the CUDA compiler) does seem to work ­– it gives you an error because you did not specify any file to compile but that’s ok. I just wanted to check whether it gives you something like “Command ‘nvcc’ not found”.
For the GENN bin path the definition looks ok but when you print out $PATH it seems to specify /Nina/Downloads/... instead of /home/Nina/Downloads/....

you’re right I messed up there. I think I fixed it:

(brianenv) [Nina@utwks62681 bin]$ echo $PATH
/home/Nina/.conda/envs/brianenv/bin:/usr/condabin:/usr/local/cuda-7.5/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/puttenmjam/.local/bin:/home/puttenmjam/bin:/opt/scripts:/var/lib/snapd/snap/bin:/Nina/Downloads/genn-4.3.3/bin:/home/Nina/Downloads/genn-4.3.3/bin

But I still get the same error as I mentioned originally when running the simple script. So the

RuntimeError: Project compilation failed (Command ['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp'] failed with error code 50).
See the output above (if any) for more details.

error

I don’t have an immediate idea what is going wrong, but could you run your script with Brian2GeNN’s debug option and post the output here (it will be long, though…)? To activate debugging, use

set_device('genn', debug=True)
INFO       The following preferences have been changed for Brian2GeNN, reset them manually if you use a different device later in the same script: codegen.loop_invariant_optimisations, core.network.default_schedule [brian2.devices.genn]
running brian code generation ...
INFO       No numerical integration method specified for group 'neurongroup', using method 'exact' (took 0.03s). [brian2.stateupdaters.base.method_choice]
building genn executable ...
['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp']
make: Entering directory `/home/Nina/Downloads/genn-4.3.3/src/genn/generator'
if [ -w /home/Nina/Downloads/genn-4.3.3/lib ]; then make -C /home/Nina/Downloads/genn-4.3.3/src/genn/genn; fi;
if [ -w /home/Nina/Downloads/genn-4.3.3/lib ]; then make -C /home/Nina/Downloads/genn-4.3.3/src/genn/backends/cuda; fi;
make[1]: Entering directory `/home/Nina/Downloads/genn-4.3.3/src/genn/backends/cuda'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/Nina/Downloads/genn-4.3.3/src/genn/backends/cuda'
make[1]: Entering directory `/home/Nina/Downloads/genn-4.3.3/src/genn/genn'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/Nina/Downloads/genn-4.3.3/src/genn/genn'
mkdir -p /home/Nina/PycharmProjects/pythonProject/GeNNworkspace
/home/Nina/.conda/envs/brianenv/bin/x86_64-conda_cos6-linux-gnu-c++ -std=c++11 -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/Nina/.conda/envs/brianenv/include -Wall -Wpedantic -Wextra -MMD -MP -I/home/Nina/Downloads/genn-4.3.3/include/genn/genn -I/home/Nina/Downloads/genn-4.3.3/include/genn/third_party -I/home/Nina/PycharmProjects/pythonProject -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace -I/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit -I/home/Nina/Downloads/genn-4.3.3/include/genn/backends/cuda -DMODEL=\"/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/magicnetwork_model.cpp\" -DBACKEND_NAMESPACE=CUDA -I"/usr/local/cuda-7.5/include" generator.cc -o /home/Nina/PycharmProjects/pythonProject/GeNNworkspace/generator -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/Nina/.conda/envs/brianenv/lib -Wl,-rpath-link,/home/Nina/.conda/envs/brianenv/lib -L/home/Nina/.conda/envs/brianenv/lib -L/home/Nina/Downloads/genn-4.3.3/lib  -lgenn_cuda_backend -lgenn -L"/usr/local/cuda-7.5/lib64" -lcuda -lcudart
In file included from /home/Nina/PycharmProjects/pythonProject/GeNNworkspace/magicnetwork_model.cpp:5:0,
                 from generator.cc:31:
/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit/randomkit.cc:132:1: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 };
 ^
/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit/randomkit.cc:132:1: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
In file included from /home/Nina/PycharmProjects/pythonProject/GeNNworkspace/objects.h:6:0,
                 from /home/Nina/PycharmProjects/pythonProject/GeNNworkspace/magicnetwork_model.cpp:7,
                 from generator.cc:31:
/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/clocks.h:12:3: warning: extra ';' [-Wpedantic]
  };
   ^
/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/clocks.h:13:2: warning: extra ';' [-Wpedantic]
 };
  ^
/home/Nina/.conda/envs/brianenv/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status
make: *** [/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/generator] Error 1
make: Leaving directory `/home/Nina/Downloads/genn-4.3.3/src/genn/generator'
genn-buildmodel.sh:86: error 50: command failure
ERROR      Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at <http://brian.discourse.group/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: /tmp/brian_debug_4oxuwkvs.log  Additionally, you can also include a copy of the script that was run, available at: /tmp/brian_script_vbn8zhvi.py Thanks! [brian2]
Traceback (most recent call last):
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 882, in build
    self.compile_source(debug, directory, use_GPU)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 1169, in compile_source
    check_call(args, cwd=directory, env=env)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/subprocess.py", line 311, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp']' returned non-zero exit status 50.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/home/Nina/Downloads/pycharm-2020.2.3/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/Nina/Downloads/pycharm-2020.2.3/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/Nina/PycharmProjects/pythonProject/main.py", line 16, in <module>
    run(100*ms)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/units/fundamentalunits.py", line 2434, in new_f
    result = f(*args, **kwds)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/magic.py", line 374, in run
    namespace=namespace, profile=profile, level=2+level)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/magic.py", line 232, in run
    namespace=namespace, profile=profile, level=level+1)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/core/base.py", line 276, in device_override_decorated_function
    return getattr(curdev, name)(*args, **kwds)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 1825, in network_run
    level=level + 1)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2/devices/cpp_standalone/device.py", line 1511, in network_run
    self.build(direct_call=False, **self.build_options)
  File "/home/Nina/.conda/envs/brianenv/lib/python3.6/site-packages/brian2genn/device.py", line 888, in build
    returncode=ex.returncode)
RuntimeError: Project compilation failed (Command ['/home/Nina/Downloads/genn-4.3.3/bin/genn-buildmodel.sh', '-i', '/home/Nina/PycharmProjects/pythonProject:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace:/home/Nina/PycharmProjects/pythonProject/GeNNworkspace/brianlib/randomkit', 'magicnetwork_model.cpp'] failed with error code 50).
See the output above (if any) for more details.

Actually I think we have advanced a bit, it is no longer complaining about not finding cuda.h, but now it only fails at the later linking stage. It might only be missing the LD_LIBRARY_PATH setting as mentioned in CUDA’s post-installation instructions. In your case, I think it would mean adding

export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

to .bash_profile or .bashrc