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

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)

`

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 (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.

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.

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. You can find many different ways of connecting populations together. I hope that helps!

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.