Conversion of the model from Brian1 to Brian2

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

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

Hi @serge25 . Make sure that you have a look at the conversion guide in the documentation, 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
Without having tested everything in detail, the equivalent definition for Cmg_AMPA in Brian 2 should therefore be the following:

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

1 Like

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

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

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

Is it right to translate it as:

delay='rand*(dm+dt)'

And how to translate this part:

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'])

Not quite, it should be

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

or

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:

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.

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:

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']

Hi @serge25. I think I already answered this question in my previous comment (see bottom part).