Error with synapse

Hi , excuseme , i tried to simulate a " Closed-Loop Gliotransmission " synapse with three neurons and two astrocytes and the connection synapse is like this :

ecs_syn_to_astro = Synapses(synapses , astrocytes, 'Y_S_post = Y_S_pre : mmolar (summed)')
ecs_syn_to_astro.connect (j='i if i < 500')
ecs_astro_to_syn = Synapses ( astrocytes , synapses , 'G_A_post = G_A_pre : mmolar (summed)')
ecs_astro_to_syn.connect (j='i if i < 500')

and i get a error for the last line .

Full traceback of error (if relevant)

IndexError                                Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/brian2/codegen/runtime/cython_rt/cython_rt.py in run_block(self, block)
    156             try:
--> 157                 return compiled_code.main(self.namespace)
    158             except Exception as exc:

_cython_magic_53851247f6b73d887ad8f87e1cc90925.pyx in _cython_magic_53851247f6b73d887ad8f87e1cc90925.main()

IndexError: index j=0 outside allowed range from 0 to -1

The above exception was the direct cause of the following exception:

BrianObjectException                      Traceback (most recent call last)
6 frames
/usr/local/lib/python3.7/dist-packages/brian2/codegen/runtime/cython_rt/cython_rt.py in run_block(self, block)
    159                 message = (f"An exception occured during the execution of the "
    160                            f"'{block}' block of code object '{self.name}'.\n")
--> 161                 raise BrianObjectException(message, self.owner) from exc
    162 
    163     def _insert_func_namespace(self, func):

BrianObjectException: Error encountered with object named 'synapses_5'.
Object was created here (most recent call only, full details in debug log):
File '<ipython-input-2-f832fdabe896>', line 211, in <module>
ecs_astro_to_syn = Synapses ( astrocytes , synapses , 'G_A_post = G_A_pre : mmolar (summed)' )

An exception occured during the execution of the 'run' block of code object 'synapses_5_synapses_create_generator_codeobject'.

Hi @Maryidea . Admittedly the error message is not great, but β€œindex j=0 outside allowed range from 0 to -1” means that no synapse can be created, because the target group is empty (in other words, even the index 0 is β€œtoo big”). From your code this means that the synapses that ecs_astro_to_syn is supposed to connect to, does not have any synapses. There’s a synapses.connect(...) missing somewhere earlier.
All that said, if you actually have three neurons and two astrocytes, I do not quite see how the connect statement j='i if i < 500' is supposed to work. This connect statement means to connect things in a one-to-one fashion (astrocyte 0 with synapse 0, astrocyte 1 with synapse 1, etc.), for the first 500 synapses/astrocytes – you do not seem to have that many.

1 Like

Thank you @mstimberg for your attention and your explanations. according to your explanation i wrote this :

astro_to_astro_eqs = β€˜β€™β€™
delta_I = I_post - I_pre :mmolar
J_coupling_post = F * (I_post - I_pre) : mmolar/second (summed)β€˜β€™β€™
synapses.connect()
astro_to_astro = Synapses(astrocytes , astrocytes , model=astro_to_astro_eqs)
astro_to_astro.connect(β€˜j == (i + 1) % 1’)
ecs_syn_to_astro = Synapses(synapses , astrocytes, β€˜Y_S_post = Y_S_pre : mmolar (summed)’)
ecs_syn_to_astro.connect(j=β€˜i if i < 6’)
ecs_astro_to_syn = Synapses ( astrocytes , synapses , β€˜G_A_post = G_A_pre : mmolar (summed)’)
ecs_astro_to_syn.connect(j=β€˜i if i < 6’)

and i don’t get any error . but i don’t know that is true or not !

I am not sure, this might be correct, but it depends on what you want to do. You said in your initial post that you want to use closed-loop gliotransmission with three neurons and two astrocytes, but I am not sure what this means. In our closed-loop transmission example in Example: example_4_synrel β€” Brian 2 2.5.0.3 documentation , each pair of neurons has a single synapse and a single astrocyte which is connected reciprocally with the synapse. What connectivity scheme do you have in mind for your simulation? Is it like this (N… are neurons, S… are synapses, and A… are astrocytes):

β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”
β”‚ N0 β”œβ”€β”€β–Ί S0 β”œβ”€β”€β–Ί N1 β”œβ”€β”€β–Ί S1 β”œβ”€β”€β–Ί N2 β”‚
β””β”€β”€β”€β”€β”˜  β””β”¬β”€β”€β–²β”˜  β””β”€β”€β”€β”€β”˜  β””β”¬β”€β”€β–²β”˜  β””β”€β”€β”€β”€β”˜
         β”‚  β”‚            β”‚  β”‚
        β”Œβ–Όβ”€β”€β”΄β”          β”Œβ–Όβ”€β”€β”΄β”
        β”‚ A0 ◄──────────► A1 β”‚
        β””β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”˜

If that is the connection scheme you have in mind (and if you don’t want to extend your simulation to much bigger networks later), the easiest solution would be to use explicit indices instead of the general string expressions.
Something along these lines:

neurons = NeuronGroup(3, ...)
astrocytes = NeuronGroup(2, ...)
synapses = Synapses(neurons, neurons, ...)
synapses.connect(i=[0, 1], j=[1, 2]) # connect neurons 0β†’1 and 1β†’2
astro_to_astro = Synapses(astrocytes, astrocytes, ...)
astro_to_astro.connect(i=[0, 1], j=[1, 0])  # connect astrocytes 0β†’1 and 1β†’0
ecs_syn_to_astro = Synapses(synapses, astrocytes, ...)
ecs_syn_to_astro.connect(i=[0, 1], j=[0, 1])  # connect syn to astro 0β†’0 and 1β†’1
ecs_astro_to_syn = Synapses(astrocytes, synapses, ...)
ecs_astro_to_syn.connect(i=[0, 1], j=[0, 1])  # connect astro to syn 0β†’0 and 1β†’1
1 Like

Thank you @mstimber for your explanations , actually i want to simulate two pre-synaptic neuron with one post synaptic neuron and two astrocytes that they connect with β€œJ_coupling” . i think that i can write the synapses like what you write here , but if i want to extend my simulation i should find another way .

and sorry my simulation have problem with β€œexc” and i replaced it with β€œecs” and for run i get this error

UnsupportedEquationsException: Cannot integrate stochastic equations with this state updater.
The above exception was the direct cause of the following exception:
BrianObjectException Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/brian2/core/network.py in before_run(self, run_namespace)
892 obj.before_run(run_namespace)
893 except Exception as ex:
β†’ 894 raise BrianObjectException(β€œAn error occurred when preparing an object.”, obj) from ex
895
896 # Check that no object has been run as part of another network before
BrianObjectException: Error encountered with object named β€˜neurongroup_9_stateupdater’.
Object was created here (most recent call only, full details in debug log):
File β€˜β€™, line 204, in
astrocytes = NeuronGroup( 2 , astro_eqs , threshold= β€˜C > C_Theta’ , refractory='C> C_Theta ’ , reset = glio_release , method =β€˜rk4’ )
An error occurred when preparing an object. (See above for original error message and traceback.)

Hi @Maryidea . Sorry about theexc/ecs confusion, that was my mistake. I’ll edit my earlier comment to avoid other people being confused by it.
Regarding your error: you seem to have added a noise term with the variable \xi (i.e. xi) to your equations. The rk4 integration method cannot deal with stochastic equations. You can either chose a method that can deal with this type of equation (euler, heun and milstein should probably all work in your case), or reformulate the noise in a way that is mathematically slightly less correct in general (the noise is a value that only changes in between time steps), but is exactly equivalent to the way it gets evaluated with the euler integration algorithm. For a noise code like this (your equation is obviously longer, but this focusses only on the noise part):

dv/dt = tau**-0.5*sigma*xi: volt

you replace it like this:

dv/dt = noise: volt
noise = sigma*randn()/(sqrt(tau)*sqrt(dt)) : volt/second (constant over dt)

You can then use an integration algorithm like rk4, which will integrate the deterministic part of the equation with better accuracy than euler.

1 Like

Thank you so much for your attention , what you said was so helpfull for me
thank you

1 Like