# Error with synapse

**URL:** <https://brian.discourse.group/t/error-with-synapse/591>\
**Category:** Support\
**Created:** [25 January 2022 18:18 UTC](https://brian.discourse.group/t/error-with-synapse/591 "2022-01-25T18:18:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maryidea](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Maryidea](https://brian.discourse.group/u/Maryidea)\
**Post date:** [25 January 2022 18:18 UTC](https://brian.discourse.group/t/error-with-synapse/591/1 "2022-01-25T18:18:24Z")

</div>

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

```Python
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)

```pytb
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'.

```

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [26 January 2022 09:38 UTC](https://brian.discourse.group/t/error-with-synapse/591/2 "2022-01-26T09:38:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maryidea](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Maryidea](https://brian.discourse.group/u/Maryidea)\
**Post date:** [26 January 2022 11:07 UTC](https://brian.discourse.group/t/error-with-synapse/591/3 "2022-01-26T11:07:24Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [27 January 2022 16:02 UTC](https://brian.discourse.group/t/error-with-synapse/591/4 "2022-01-27T16:02:51Z")

</div>

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](https://brian2.readthedocs.io/en/stable/examples/frompapers.Stimberg_et_al_2018.example_4_synrel.html) , 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):

```auto
┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐
│ 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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Maryidea](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Maryidea](https://brian.discourse.group/u/Maryidea)\
**Post date:** [28 January 2022 23:03 UTC](https://brian.discourse.group/t/error-with-synapse/591/5 "2022-01-28T23:03:17Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![Maryidea](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Maryidea](https://brian.discourse.group/u/Maryidea)\
**Post date:** [29 January 2022 00:09 UTC](https://brian.discourse.group/t/error-with-synapse/591/6 "2022-01-29T00:09:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [31 January 2022 10:55 UTC](https://brian.discourse.group/t/error-with-synapse/591/7 "2022-01-31T10:55:20Z")

</div>

Hi @Maryidea . Sorry about the`exc`/`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):

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

```

you replace it like this:

```auto
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`.

---

<div class="post-metadata">

**Author:** ![Maryidea](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Maryidea](https://brian.discourse.group/u/Maryidea)\
**Post date:** [2 February 2022 09:11 UTC](https://brian.discourse.group/t/error-with-synapse/591/8 "2022-02-02T09:11:04Z")

</div>

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