# 133127 connections and 302 neurons. How to make specific synaptic connections

**URL:** <https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277>\
**Category:** Support\
**Tags:** synapses\
**Created:** [17 August 2024 18:24 UTC](https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277 "2024-08-17T18:24:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter-mason-dpm](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/peter-mason-dpm/32/761_2.png) [@peter-mason-dpm](https://brian.discourse.group/u/peter-mason-dpm)\
**Post date:** [17 August 2024 18:24 UTC](https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277/1 "2024-08-17T18:24:37Z")

</div>

# Description of problem

I cannot find a way of connecting individual neurons together on a large scale.  
The closest I got was to fill one of the 8 neuron groups at which point an exception was generated when synapse.connect tried to exceed the number of declared neurons in the group.

# Minimal code to reproduce problem

It is not that sort of problem I only need to know it can be done and how

# What you have already tried

looking at the tutorial and the example code. AI is helpful and without it I would have not got this far.

As disclaimer I do not know what I let myself in for I am not a neurobiologist and spent most of my time writing Assembler and a bit of C to run on my own hardware.

This has been a fora into current programming and a successful attempt to keep my brain alive. All I wanted to do was connect up a few neurons and poke the worm with a virtual stick and see what happens.  
I now realise that what I am attempting is not the norm and most large applications are content with random connections but my source data demands specific named neurons, [‘I1L’, ‘I1R’], in specific groups, “touch” to be connected with, at this point, any old synapse.connection in some group.  
As a hint to where I have arrived at the following selection of the terminal output .  
` ` `  
First required neurons:  
BAGL  
PHAR  
VC01  
len required \_neurons 302  
First synaptic\_connections:  
[‘I1L’, ‘I1R’]  
[‘I1L’, ‘I2L’]  
[‘I1L’, ‘I2R’]  
len synaptic\_connections\_length 133127

neuron groups:  
touch: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘touch’),  
chemoreceptor: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘chemoreceptor’),  
thermosensory: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘thermosensory’),  
taste: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘taste’),  
motor: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘motor’),  
hemoreceptor: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘hemoreceptor’),  
food: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘food’),  
intermediate: NeuronGroup(clock=Clock(dt=100. \* usecond, name=‘defaultclock’), when=start, order=0, name=‘intermediate’),

Dictionary neuron\_name\_to\_index length: 303  
headers [‘neuron key’, ‘neuron\_index’, ‘neuron\_type’, ‘neuron index in type’]  
ALML (0, ‘touch’, 0)  
ADLR (1, ‘touch’, 1)  
PLNR (2, ‘touch’, 2)  
PVM (3, ‘touch’, 3)  
PLNL (4, ‘touch’, 4)  
ADLL (5, ‘touch’, 5)

# Create synapses based on the connections

```
for pre, post in synaptic_connections:
    pre_group = neuron_groups[neuron_name_to_index[pre][1]] # Get the neuron group
    post_group = neuron_groups[neuron_name_to_index[post][1]] # Get the neuron group
    #print('pre_group ',pre_group)
    #print('post_group ',post_group)
        
    pre_i = [neuron_name_to_index[pre][2]]
    post_j = [neuron_name_to_index[pre][2]]
    
    synapse = Synapses(pre_group, post_group,
                '''
                w : 1
                dapre/dt = -apre/taupre : 1 (clock-driven)
                dapost/dt = -apost/taupost : 1 (clock-driven)
                ''',
                on_pre='''
                v_post += w
                apre += Apre
                w = clip(w + apost, 0, wmax)
                ''',
                on_post='''
                apost += Apost
                w = clip(w + apre, 0, wmax)
                ''', method='linear')
    
    synapse.connect(i=pre_i, j=post_j)
    synapses.append(synapse)

```

` ` `

---

<div class="post-metadata">

**Author:** ![peter-mason-dpm](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/peter-mason-dpm/32/761_2.png) [@peter-mason-dpm](https://brian.discourse.group/u/peter-mason-dpm)\
**Post date:** [18 August 2024 08:53 UTC](https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277/2 "2024-08-18T08:53:05Z")

</div>

I am working on reproducing the issue with 3 neurons and 6 connections which is showed up other problems with the fall back intermediate group having zero neurons.  
This is a more understandable error message, however I would appreciate a idea of what it means.

Exception has occurred: IndexError  
Tried to create synapse indices outside valid range. Original error message: The given target indices contain values outside of the range [0, 0] allowed for the target group “motor”  
IndexError: The given target indices contain values outside of the range [0, 0] allowed for the target group “motor”

During handling of the above exception, another exception occurred:

File “C:\Users\peter\Nematode\_1v110\Brian\brain\_main.py”, line 168, in main  
synapse.connect(i=pre\_i, j=post\_j)  
File “C:\Users\peter\Nematode\_1v110\Brian\brain\_main.py”, line 196, in   
main() # Execute the main function  
^^^^^^  
IndexError: Tried to create synapse indices outside valid range. Original error message: The given target indices contain values outside of the range [0, 0] allowed for the target group “motor”

There is a motor group and it should have one neuron.  
There is a “touch” group and it receives synapses at least until the exception.

Additionally I get a message

WARNING Cannot use Cython, a test compilation failed: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: [Microsoft C++ Build Tools - Visual Studio](https://visualstudio.microsoft.com/visual-cpp-build-tools/) (DistutilsPlatformError) [brian2.codegen.runtime.cython\_rt.cython\_rt.failed\_compile\_test]  
INFO Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message:  
prefs.codegen.target = “numpy” [brian2.devices.device.codegen\_fallback]

I installed Build Tools but this message recurred.

---

<div class="post-metadata">

**Author:** ![peter-mason-dpm](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/peter-mason-dpm/32/761_2.png) [@peter-mason-dpm](https://brian.discourse.group/u/peter-mason-dpm)\
**Post date:** [19 August 2024 15:35 UTC](https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277/3 "2024-08-19T15:35:03Z")

</div>

It was me, an issue with pre and post indices. Apologies, but nice to meet you and thank you for the study notes they look as if they may be useful.

---

<div class="post-metadata">

**Author:** ![pabloabur](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/pabloabur/32/598_2.png) [@pabloabur](https://brian.discourse.group/u/pabloabur)\
**Post date:** [22 August 2024 00:58 UTC](https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277/4 "2024-08-22T00:58:27Z")

</div>

Hey @peter-mason-dpm. I couldn’t run your code because you’re using libraries/data I don’t have access to. But I didn’t see anything wrong in your code (I’m assuming it’s the same on attached to your other post). I suggest you have a look at Brian2’s tutorial regarding [synapses](https://brian2.readthedocs.io/en/stable/resources/tutorials/2-intro-to-brian-synapses.html). You can find many different ways of connecting populations together. I hope that helps!

---

<div class="post-metadata">

**Author:** ![peter-mason-dpm](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/peter-mason-dpm/32/761_2.png) [@peter-mason-dpm](https://brian.discourse.group/u/peter-mason-dpm)\
**Post date:** [22 August 2024 07:46 UTC](https://brian.discourse.group/t/133127-connections-and-302-neurons-how-to-make-specific-synaptic-connections/1277/5 "2024-08-22T07:46:07Z")

</div>

Thank you for the reply.

My experience has been that there’s nothing like real data for exercising obscure problems with code and I am coming to the conclusion that the only way to resolve this is looking deep within Brian. This exceeds my expertise. I note that some of the other posts with multiple synapses also reported Issues but no errors.

In the meantime I have reinstalled WSL in case that was the problem and I have looked at alternative ways of making multiple synapses using matrices. In any case this summer project is going to have to end as the roof needs repairing, the boat requires work and the cello has been ignored.
