root/trunk/examples/VAbenchmarks2.py @ 869

Revision 869, 7.3 KB (checked in by pierre, 2 years ago)

All tests are now passed with Brian, expect the one with plasticity (because delay is dendritic, and can not be supported in Brian yet), and the one with Assemblies (not supported yet in Brian). Update the network examples to take into account the new syntax for record_X functions

  • Property svn:eol-style set to native
Line 
1# coding: utf-8
2"""
3An implementation of benchmarks 1 and 2 from
4
5    Brette et al. (2007) Journal of Computational Neuroscience 23: 349-398
6
7The IF network is based on the CUBA and COBA models of Vogels & Abbott
8(J. Neurosci, 2005).  The model consists of a network of excitatory and
9inhibitory neurons, connected via current-based "exponential"
10synapses (instantaneous rise, exponential decay).
11
12This version demonstrates an alternative way to set-up the network, using
13PopulationViews.
14
15Andrew Davison, UNIC, CNRS
16March 2010
17
18$Id: $
19"""
20
21import os
22import socket
23from math import *
24
25from pyNN.random import NumpyRNG, RandomDistribution
26from pyNN.utility import get_script_args, Timer
27usage = """Usage: python VAbenchmarks.py <simulator> <benchmark>
28           <simulator> is either neuron, nest, brian or pcsim
29           <benchmark> is either CUBA or COBA."""
30simulator_name, benchmark = get_script_args(2, usage) 
31exec("from pyNN.%s import *" % simulator_name)
32
33timer = Timer()
34
35# === Define parameters ========================================================
36
37threads  = 1
38rngseed  = 98765
39parallel_safe = True
40
41n        = 4000  # number of cells
42r_ei     = 4.0   # number of excitatory cells:number of inhibitory cells
43pconn    = 0.02  # connection probability
44stim_dur = 50.   # (ms) duration of random stimulation
45rate     = 100.  # (Hz) frequency of the random stimulation
46
47dt       = 0.1   # (ms) simulation timestep
48tstop    = 1000  # (ms) simulaton duration
49delay    = 0.2
50
51# Cell parameters
52area     = 20000. # (µm²)
53tau_m    = 20.    # (ms)
54cm       = 1.     # (µF/cm²)
55g_leak   = 5e-5   # (S/cm²)
56if benchmark == "COBA":
57    E_leak   = -60.  # (mV)
58elif benchmark == "CUBA":
59    E_leak   = -49.  # (mV)
60v_thresh = -50.   # (mV)
61v_reset  = -60.   # (mV)
62t_refrac = 5.     # (ms) (clamped at v_reset)
63v_mean   = -60.   # (mV) 'mean' membrane potential, for calculating CUBA weights
64tau_exc  = 5.     # (ms)
65tau_inh  = 10.    # (ms)
66
67# Synapse parameters
68if benchmark == "COBA":
69    Gexc = 4.     # (nS)
70    Ginh = 51.    # (nS)
71elif benchmark == "CUBA":
72    Gexc = 0.27   # (nS) #Those weights should be similar to the COBA weights
73    Ginh = 4.5    # (nS) # but the delpolarising drift should be taken into account
74Erev_exc = 0.     # (mV)
75Erev_inh = -80.   # (mV)
76
77### what is the synaptic delay???
78
79# === Calculate derived parameters =============================================
80
81area  = area*1e-8                     # convert to cm²
82cm    = cm*area*1000                  # convert to nF
83Rm    = 1e-6/(g_leak*area)            # membrane resistance in MΩ
84assert tau_m == cm*Rm                 # just to check
85n_exc = int(round((n*r_ei/(1+r_ei)))) # number of excitatory cells   
86n_inh = n - n_exc                     # number of inhibitory cells
87if benchmark == "COBA":
88    celltype = IF_cond_exp
89    w_exc    = Gexc*1e-3              # We convert conductances to uS
90    w_inh    = Ginh*1e-3
91elif benchmark == "CUBA":
92    celltype = IF_curr_exp
93    w_exc = 1e-3*Gexc*(Erev_exc - v_mean) # (nA) weight of excitatory synapses
94    w_inh = 1e-3*Ginh*(Erev_inh - v_mean) # (nA)
95    assert w_exc > 0; assert w_inh < 0
96
97# === Build the network ========================================================
98
99extra = {'threads' : threads,
100         'filename': "va2_%s.xml" % benchmark,
101         'label': 'VA2'}
102if simulator_name == "neuroml":
103    extra["file"] = "VAbenchmarks.xml"
104
105node_id = setup(timestep=dt, min_delay=delay, max_delay=delay, **extra)
106np = num_processes()
107
108host_name = socket.gethostname()
109print "Host #%d is on %s" % (node_id+1, host_name)
110
111print "%s Initialising the simulator with %d thread(s)..." % (node_id, extra['threads'])
112   
113cell_params = {
114    'tau_m'      : tau_m,    'tau_syn_E'  : tau_exc,  'tau_syn_I'  : tau_inh,
115    'v_rest'     : E_leak,   'v_reset'    : v_reset,  'v_thresh'   : v_thresh,
116    'cm'         : cm,       'tau_refrac' : t_refrac}
117
118if (benchmark == "COBA"):
119    cell_params['e_rev_E'] = Erev_exc
120    cell_params['e_rev_I'] = Erev_inh
121   
122timer.start()
123
124print "%s Creating cell populations..." % node_id
125all_cells = Population(n_exc+n_inh, celltype, cell_params, label="All Cells")
126exc_cells = all_cells[:n_exc]; exc_cells.label = "Excitatory cells"
127inh_cells = all_cells[n_exc:]; inh_cells.label = "Inhibitory cells"
128if benchmark == "COBA":
129    ext_stim = Population(20, SpikeSourcePoisson, {'rate' : rate, 'duration' : stim_dur}, label="expoisson")
130    rconn = 0.01
131    ext_conn = FixedProbabilityConnector(rconn, weights=0.1)
132
133print "%s Initialising membrane potential to random values..." % node_id
134rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
135uniformDistr = RandomDistribution('uniform', [v_reset,v_thresh], rng=rng)
136all_cells.initialize('v', uniformDistr)
137
138print "%s Connecting populations..." % node_id
139exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay)
140inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay)
141
142connections={}
143connections['exc'] = Projection(exc_cells, all_cells, exc_conn, target='excitatory', rng=rng)
144connections['inh'] = Projection(inh_cells, all_cells, inh_conn, target='inhibitory', rng=rng)
145if (benchmark == "COBA"):
146    connections['ext'] = Projection(ext_stim, all_cells, ext_conn, target='excitatory')
147
148# === Setup recording ==========================================================
149print "%s Setting up recording..." % node_id
150all_cells.record()
151exc_cells[[0, 1]].record_v()
152
153buildCPUTime = timer.diff()
154
155# === Save connections to file =================================================
156
157#print "%s Saving connections to file..." % node_id
158#for prj in connections.keys():
159#    connections[prj].saveConnections('Results/VAbenchmark_%s_%s_%s_np%d.conn' % (benchmark, prj, simulator_name, np))
160#saveCPUTime = timer.diff()
161
162# === Run simulation ===========================================================
163print "%d Running simulation..." % node_id
164
165run(tstop)
166
167simCPUTime = timer.diff()
168
169E_count = exc_cells.meanSpikeCount()
170I_count = inh_cells.meanSpikeCount()
171
172# === Print results to file ====================================================
173
174print "%d Writing data to file..." % node_id
175
176if not(os.path.isdir('Results')):
177    os.mkdir('Results')
178
179exc_cells.printSpikes("Results/VAbenchmark_%s_exc_%s_np%d.ras" % (benchmark, simulator_name, np))
180inh_cells.printSpikes("Results/VAbenchmark_%s_inh_%s_np%d.ras" % (benchmark, simulator_name, np))
181exc_cells[[0, 1]].print_v("Results/VAbenchmark_%s_exc_%s_np%d.v" % (benchmark, simulator_name, np))
182writeCPUTime = timer.diff()
183
184connections = "%d e→e,i  %d i→e,i" % (connections['exc'].size(),
185                                      connections['inh'].size(),)
186
187if node_id == 0:
188    print "\n--- Vogels-Abbott Network Simulation ---"
189    print "Nodes                  : %d" % np
190    print "Simulation type        : %s" % benchmark
191    print "Number of Neurons      : %d" % n
192    print "Number of Synapses     : %s" % connections
193    print "Excitatory conductance : %g nS" % Gexc
194    print "Inhibitory conductance : %g nS" % Ginh
195    print "Excitatory rate        : %g Hz" % (E_count*1000.0/tstop,)
196    print "Inhibitory rate        : %g Hz" % (I_count*1000.0/tstop,)
197    print "Build time             : %g s" % buildCPUTime
198    #print "Save connections time  : %g s" % saveCPUTime
199    print "Simulation time        : %g s" % simCPUTime
200    print "Writing time           : %g s" % writeCPUTime
201
202
203# === Finished with simulator ==================================================
204
205end()
Note: See TracBrowser for help on using the browser.