| 1 | # coding: utf-8 |
|---|
| 2 | """ |
|---|
| 3 | An implementation of benchmarks 1 and 2 from |
|---|
| 4 | |
|---|
| 5 | Brette et al. (2007) Journal of Computational Neuroscience 23: 349-398 |
|---|
| 6 | |
|---|
| 7 | The 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 |
|---|
| 9 | inhibitory neurons, connected via current-based "exponential" |
|---|
| 10 | synapses (instantaneous rise, exponential decay). |
|---|
| 11 | |
|---|
| 12 | This version demonstrates an alternative way to set-up the network, using |
|---|
| 13 | PopulationViews. |
|---|
| 14 | |
|---|
| 15 | Andrew Davison, UNIC, CNRS |
|---|
| 16 | March 2010 |
|---|
| 17 | |
|---|
| 18 | $Id: $ |
|---|
| 19 | """ |
|---|
| 20 | |
|---|
| 21 | import os |
|---|
| 22 | import socket |
|---|
| 23 | from math import * |
|---|
| 24 | |
|---|
| 25 | from pyNN.random import NumpyRNG, RandomDistribution |
|---|
| 26 | from pyNN.utility import get_script_args, Timer |
|---|
| 27 | usage = """Usage: python VAbenchmarks.py <simulator> <benchmark> |
|---|
| 28 | <simulator> is either neuron, nest, brian or pcsim |
|---|
| 29 | <benchmark> is either CUBA or COBA.""" |
|---|
| 30 | simulator_name, benchmark = get_script_args(2, usage) |
|---|
| 31 | exec("from pyNN.%s import *" % simulator_name) |
|---|
| 32 | |
|---|
| 33 | timer = Timer() |
|---|
| 34 | |
|---|
| 35 | # === Define parameters ======================================================== |
|---|
| 36 | |
|---|
| 37 | threads = 1 |
|---|
| 38 | rngseed = 98765 |
|---|
| 39 | parallel_safe = True |
|---|
| 40 | |
|---|
| 41 | n = 4000 # number of cells |
|---|
| 42 | r_ei = 4.0 # number of excitatory cells:number of inhibitory cells |
|---|
| 43 | pconn = 0.02 # connection probability |
|---|
| 44 | stim_dur = 50. # (ms) duration of random stimulation |
|---|
| 45 | rate = 100. # (Hz) frequency of the random stimulation |
|---|
| 46 | |
|---|
| 47 | dt = 0.1 # (ms) simulation timestep |
|---|
| 48 | tstop = 1000 # (ms) simulaton duration |
|---|
| 49 | delay = 0.2 |
|---|
| 50 | |
|---|
| 51 | # Cell parameters |
|---|
| 52 | area = 20000. # (µm²) |
|---|
| 53 | tau_m = 20. # (ms) |
|---|
| 54 | cm = 1. # (µF/cm²) |
|---|
| 55 | g_leak = 5e-5 # (S/cm²) |
|---|
| 56 | if benchmark == "COBA": |
|---|
| 57 | E_leak = -60. # (mV) |
|---|
| 58 | elif benchmark == "CUBA": |
|---|
| 59 | E_leak = -49. # (mV) |
|---|
| 60 | v_thresh = -50. # (mV) |
|---|
| 61 | v_reset = -60. # (mV) |
|---|
| 62 | t_refrac = 5. # (ms) (clamped at v_reset) |
|---|
| 63 | v_mean = -60. # (mV) 'mean' membrane potential, for calculating CUBA weights |
|---|
| 64 | tau_exc = 5. # (ms) |
|---|
| 65 | tau_inh = 10. # (ms) |
|---|
| 66 | |
|---|
| 67 | # Synapse parameters |
|---|
| 68 | if benchmark == "COBA": |
|---|
| 69 | Gexc = 4. # (nS) |
|---|
| 70 | Ginh = 51. # (nS) |
|---|
| 71 | elif 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 |
|---|
| 74 | Erev_exc = 0. # (mV) |
|---|
| 75 | Erev_inh = -80. # (mV) |
|---|
| 76 | |
|---|
| 77 | ### what is the synaptic delay??? |
|---|
| 78 | |
|---|
| 79 | # === Calculate derived parameters ============================================= |
|---|
| 80 | |
|---|
| 81 | area = area*1e-8 # convert to cm² |
|---|
| 82 | cm = cm*area*1000 # convert to nF |
|---|
| 83 | Rm = 1e-6/(g_leak*area) # membrane resistance in MΩ |
|---|
| 84 | assert tau_m == cm*Rm # just to check |
|---|
| 85 | n_exc = int(round((n*r_ei/(1+r_ei)))) # number of excitatory cells |
|---|
| 86 | n_inh = n - n_exc # number of inhibitory cells |
|---|
| 87 | if benchmark == "COBA": |
|---|
| 88 | celltype = IF_cond_exp |
|---|
| 89 | w_exc = Gexc*1e-3 # We convert conductances to uS |
|---|
| 90 | w_inh = Ginh*1e-3 |
|---|
| 91 | elif 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 | |
|---|
| 99 | extra = {'threads' : threads, |
|---|
| 100 | 'filename': "va2_%s.xml" % benchmark, |
|---|
| 101 | 'label': 'VA2'} |
|---|
| 102 | if simulator_name == "neuroml": |
|---|
| 103 | extra["file"] = "VAbenchmarks.xml" |
|---|
| 104 | |
|---|
| 105 | node_id = setup(timestep=dt, min_delay=delay, max_delay=delay, **extra) |
|---|
| 106 | np = num_processes() |
|---|
| 107 | |
|---|
| 108 | host_name = socket.gethostname() |
|---|
| 109 | print "Host #%d is on %s" % (node_id+1, host_name) |
|---|
| 110 | |
|---|
| 111 | print "%s Initialising the simulator with %d thread(s)..." % (node_id, extra['threads']) |
|---|
| 112 | |
|---|
| 113 | cell_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 | |
|---|
| 118 | if (benchmark == "COBA"): |
|---|
| 119 | cell_params['e_rev_E'] = Erev_exc |
|---|
| 120 | cell_params['e_rev_I'] = Erev_inh |
|---|
| 121 | |
|---|
| 122 | timer.start() |
|---|
| 123 | |
|---|
| 124 | print "%s Creating cell populations..." % node_id |
|---|
| 125 | all_cells = Population(n_exc+n_inh, celltype, cell_params, label="All Cells") |
|---|
| 126 | exc_cells = all_cells[:n_exc]; exc_cells.label = "Excitatory cells" |
|---|
| 127 | inh_cells = all_cells[n_exc:]; inh_cells.label = "Inhibitory cells" |
|---|
| 128 | if 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 | |
|---|
| 133 | print "%s Initialising membrane potential to random values..." % node_id |
|---|
| 134 | rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) |
|---|
| 135 | uniformDistr = RandomDistribution('uniform', [v_reset,v_thresh], rng=rng) |
|---|
| 136 | all_cells.initialize('v', uniformDistr) |
|---|
| 137 | |
|---|
| 138 | print "%s Connecting populations..." % node_id |
|---|
| 139 | exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay) |
|---|
| 140 | inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay) |
|---|
| 141 | |
|---|
| 142 | connections={} |
|---|
| 143 | connections['exc'] = Projection(exc_cells, all_cells, exc_conn, target='excitatory', rng=rng) |
|---|
| 144 | connections['inh'] = Projection(inh_cells, all_cells, inh_conn, target='inhibitory', rng=rng) |
|---|
| 145 | if (benchmark == "COBA"): |
|---|
| 146 | connections['ext'] = Projection(ext_stim, all_cells, ext_conn, target='excitatory') |
|---|
| 147 | |
|---|
| 148 | # === Setup recording ========================================================== |
|---|
| 149 | print "%s Setting up recording..." % node_id |
|---|
| 150 | all_cells.record() |
|---|
| 151 | exc_cells[[0, 1]].record_v() |
|---|
| 152 | |
|---|
| 153 | buildCPUTime = 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 =========================================================== |
|---|
| 163 | print "%d Running simulation..." % node_id |
|---|
| 164 | |
|---|
| 165 | run(tstop) |
|---|
| 166 | |
|---|
| 167 | simCPUTime = timer.diff() |
|---|
| 168 | |
|---|
| 169 | E_count = exc_cells.meanSpikeCount() |
|---|
| 170 | I_count = inh_cells.meanSpikeCount() |
|---|
| 171 | |
|---|
| 172 | # === Print results to file ==================================================== |
|---|
| 173 | |
|---|
| 174 | print "%d Writing data to file..." % node_id |
|---|
| 175 | |
|---|
| 176 | if not(os.path.isdir('Results')): |
|---|
| 177 | os.mkdir('Results') |
|---|
| 178 | |
|---|
| 179 | exc_cells.printSpikes("Results/VAbenchmark_%s_exc_%s_np%d.ras" % (benchmark, simulator_name, np)) |
|---|
| 180 | inh_cells.printSpikes("Results/VAbenchmark_%s_inh_%s_np%d.ras" % (benchmark, simulator_name, np)) |
|---|
| 181 | exc_cells[[0, 1]].print_v("Results/VAbenchmark_%s_exc_%s_np%d.v" % (benchmark, simulator_name, np)) |
|---|
| 182 | writeCPUTime = timer.diff() |
|---|
| 183 | |
|---|
| 184 | connections = "%d eâe,i %d iâe,i" % (connections['exc'].size(), |
|---|
| 185 | connections['inh'].size(),) |
|---|
| 186 | |
|---|
| 187 | if 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 | |
|---|
| 205 | end() |
|---|