# Conversion of the model from Brian1 to Brian2

**URL:** <https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754>\
**Category:** Support\
**Tags:** brian1\
**Created:** [26 July 2022 16:16 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754 "2022-07-26T16:16:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [26 July 2022 16:16 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/1 "2022-07-26T16:16:30Z")

</div>

Hi! Could you @mstimberg @adam kindly help me with conversion of the model (Gamma-beta alternation in the olfactory bulb (David, Fourcaud-Trocmé et al., 2015) [github link](https://github.com/ModelDBRepository/185014)) from Brian1 to Brian2 . At the moment there are several lines in which it is not clear how they will look in the Brian2.

# Minimal code to reproduce problem

```auto
.......
G=NeuronGroup(N_granule,QIF_eqs,threshold='V > 0.*mV',reset='V = -70.*mV',freeze=True,compile=True)
............

Cmg_AMPA = Connection(M,G,'sE',
                                                    weight=2.5*param_dict['exc_weight'], # 2.5 factor to compensate for the depressed strength of AMPA in the beta regime
                                                    sparseness=param_dict['stronginh_connectproba'],
                                                    delay=1.*ms) #
            mystp=STP(Cmg_AMPA,taud=150*ms,tauf=1*ms,U=1.)

......

```

At NeuronGroup i don’t know what is freeze and compile and how it is look like at brian2. At Connection i don’t know about STP function and how it convert to Brian2.

---

<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:** [28 July 2022 19:50 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/2 "2022-07-28T19:50:17Z")

</div>

Hi @serge25 . Make sure that you have a look at the [conversion guide in the documentation](https://brian2.readthedocs.io/en/stable/introduction/brian1_to_2/index.html), it should hopefully explain most of the necessary changes. You can ignore/remove the `freeze` and `compile` keywords in `NeuronGroup`, they just trigger some Brian1-specific optimisation and are no longer relevant.  
The `Connection` class has been replaced by `Synapses`, and we no longer provide an `STP` function. Instead, you’ll have to be explicit about the equations that you want to use (but of course, the advantage is that you can change the details of the plasticity in any way you want). The equations that are used for `STP` in Brian 1 are shown here: [Short-term plasticity — Brian 1.4.4 documentation](https://brian.readthedocs.io/en/stable/stp.html)  
Without having tested everything in detail, the equivalent definition for `Cmg_AMPA` in Brian 2 should therefore be the following:

```python
weight_AMPA = 2.5*param_dict['exc_weight'] # 2.5 factor to compensate ...
taud=150*ms
tauf=1*ms
U=1.

Cmg_AMPA = Synapses(M, G, '''dx/dt=(1-x)/taud : 1 (event-driven)
                             du/dt=(U-u)/tauf : 1 (event-driven)''',
                    on_pre='''sE_post += u*x*weight_AMPA
                              x = x*(1 - u)
                              u = u + U*(1 - u)''',
                    delay=1.*ms) 
Cmg_AMPA.connect(p=param_dict['stronginh_connectproba'])
Cmg_AMPA.x = 1
Cmg_AMPA.u = U

```

Hope that helps, best  
Marcel

---

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [6 March 2023 15:50 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/3 "2023-03-06T15:50:24Z")

</div>

Dear @mstimberg , what is the way for translate from brian1 to brian2 this parts of code:

```auto
 M = NeuronGroup(.........reset=Mitral_reset,freeze=False,compile=True)
.................................
dm,dd=param_dict['weakinh_mean_delay'],param_dict['weakinh_delay_dispersion']
Cmm_weak_inh =Synapses(.........delay=(dm-dd,dm+dd))
.......................................................................................
connected=Cmg_AMPA.W.transpose().copy() # copy and transpose M->G connection array
        mask_connect=(connected>0)
        Cgm_GABA.connect(G,M,mask_connect*param_dict['stronginh_weight'])
....................................................................

```

---

<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:** [6 March 2023 16:21 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/4 "2023-03-06T16:21:00Z")

</div>

Hi @serge25 . Could you be more specific about what you are struggling with? E.g. the `delay` syntax conversion is explained here: [Synapses (Brian 1 –\> 2 conversion) — Brian 2 2.5.1 documentation](https://brian2.readthedocs.io/en/stable/introduction/brian1_to_2/synapses.html#delays)

---

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [7 March 2023 13:37 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/5 "2023-03-07T13:37:16Z")

</div>

Is it right to translate it as:

```auto
delay='rand*(dm+dt)'

```

And how to translate this part:

```auto
connected=Cmg_AMPA.W.transpose().copy() # copy and transpose M->G connection array
        mask_connect=(connected>0)
        Cgm_GABA.connect(G,M,mask_connect*param_dict['stronginh_weight'])

```

---

<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:** [7 March 2023 14:00 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/6 "2023-03-07T14:00:33Z")

</div>

> [@serge25](#):
>
> Is it right to translate it as:
> 
> ```auto
> delay='rand*(dm+dt)'
> 
> ```

Not quite, it should be

```python
Cmm_weak_inh.delay = 'dm - dd + 2*dd*rand()'

```

or

> [@serge25](#):
>
> And how to translate this part:
> 
> ```auto
> connected=Cmg_AMPA.W.transpose().copy() # copy and transpose M->G connection array
> mask_connect=(connected>0)
> Cgm_GABA.connect(G,M,mask_connect*param_dict['stronginh_weight'])
> 
> ```

Do I understand correctly that this is meant to copy the M→G connections so that G→M has the equivalent symmetric connections?  
In that case, the most straightforward translation would be to exchange the source and target indices, by using:

```python
Cgm_GABA.connect(i=Cmg_AMPA.j, j=Cmg_AMPA.i)

```

Another alternative would be to use a single `Synapses` instance with an `on_pre` statement to apply the spikes from M→G, and an `on_post` statement to apply G→M.

---

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [14 March 2023 16:36 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/7 "2023-03-14T16:36:56Z")

</div>

Dear @mstimberg , could you please tell me how I can write these lines, taking into account the Brian2 simulator. In the Brian1 simulator, these lines of code work, in the Brian2 they do not:

```auto
connected=Cmg_AMPA.weight_AMPA.transpose().copy() # copy and transpose M->G connection array
mask_connect=(connected>0)
Cgm_GABA.connect() # finally create symmetrical connections
Cgm_GABA.weight_GABA = mask_connect*param_dict['stronginh_weight']

```

---

<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:** [14 March 2023 16:39 UTC](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/8 "2023-03-14T16:39:12Z")

</div>

Hi @serge25. I think I already answered this question in my [previous comment](https://brian.discourse.group/t/conversion-of-the-model-from-brian1-to-brian2/754/6) (see bottom part).
