# Multiple "summed variables"

**URL:** <https://brian.discourse.group/t/multiple-summed-variables/117>\
**Category:** Support\
**Created:** [28 August 2020 08:26 UTC](https://brian.discourse.group/t/multiple-summed-variables/117 "2020-08-28T08:26:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ziaeemehr](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/ziaeemehr/32/12_2.png) [@Ziaeemehr](https://brian.discourse.group/u/Ziaeemehr)\
**Post date:** [28 August 2020 08:26 UTC](https://brian.discourse.group/t/multiple-summed-variables/117/1 "2020-08-28T08:26:28Z")

</div>

Hi,  
Consider we have two population of neurons, labeled by “i” and “e”.  
We can have 4 synapse object. `{ii, ee, ie, ei}` to connect them to each other or themselves.

```python
    '''
    membrane_Im = I_ext + gNa*m_inf**3*h*(ENa-vm) + \
        gl*(El-vm) + gK*n**4*(EK-vm) +gSyn*s_in*(ESyn-vm): amp
    
    s_in : 1
    ds/dt = 0.5 * (1 + tanh(0.1*vm/mV)) * (1-s)/tau_r - s/tau_d : 1
    '''

    S_ei = b2.Synapses(neuron_e,
                       neuron_i, '''
                    w : 1
                    s_in_post = w*s_pre:1 (summed)
                    ''')
    S_ei.connect('i != j', p=p_ei)
    S_ei.w = weight_ei
    # --------------------------------------------------------------#
    S_ie = b2.Synapses(neuron_i, neuron_e, '''
                    w : 1
                    s_in_post = w*s_pre:1 (summed)
                    ''' )
    S_ie.connect('i != j', p=p_ie)
    S_ie.w = weight_ie
    # --------------------------------------------------------------#
    S_ii = b2.Synapses(neuron_i, neuron_i, '''
                    w : 1
                    s_in_post = w*s_pre:1 (summed)
                    ''' )
    S_ii.connect('i != j', p=p_ii)
    S_ii.w = weight_ii

```

If we add the `S_ii` to the simulation we get the following error:

```auto
NotImplementedError: Multiple "summed variables" 
target the variable "s_in" in group "neurongroup_1". 
Use multiple variables in the target group instead.

```

suggest to use multiple variable `in` in the target group,  
but I don’t know how?  
[GitHup](https://github.com/ITNG/ModelingNeuralDynamics/blob/master/brian/chapter30/PING1.py)

---

<div class="post-metadata">

**Author:** ![Ziaeemehr](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/ziaeemehr/32/12_2.png) [@Ziaeemehr](https://brian.discourse.group/u/Ziaeemehr)\
**Post date:** [29 August 2020 04:55 UTC](https://brian.discourse.group/t/multiple-summed-variables/117/2 "2020-08-29T04:55:56Z")

</div>

I found this in the [summed variables](https://brian2.readthedocs.io/en/stable/user/synapses.html#summed-variables), it should help:

```python
neurons = NeuronGroup(1, model='''dv/dt=(gtot-v)/(10*ms) : 1
                                  gtot = gtot1 + gtot2: 1
                                  gtot1 : 1
                                  gtot2 : 1''')

```

for others maybe read it later I put the full code [here](https://github.com/ITNG/ModelingNeuralDynamics/blob/master/brian/chapter30/PING_1/lib.py).

---

<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:** [1 September 2020 12:08 UTC](https://brian.discourse.group/t/multiple-summed-variables/117/3 "2020-09-01T12:08:02Z")

</div>

This is the direct fix for the error, but I think in your original model there is another issue: excitatory and inhibitory synapses have different reversal potentials, and their currents therefore need to be separated. Your model probably should look more like:

```auto
    membrane_Im = ... + gSyn_e*s_in_e*(ESyn_e-vm)
                      + gSyn_i*s_in_i*(ESyn_i-vm) : amp
    s_in_e : 1
    s_in_i : 1

```

and then the respective synapses either target `s_in_e_post` or `s_in_i_post`.

---

<div class="post-metadata">

**Author:** ![Ziaeemehr](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/ziaeemehr/32/12_2.png) [@Ziaeemehr](https://brian.discourse.group/u/Ziaeemehr)\
**Post date:** [1 September 2020 16:52 UTC](https://brian.discourse.group/t/multiple-summed-variables/117/4 "2020-09-01T16:52:26Z")

</div>

Thank you @mstimberg. 👍
