Debian Codegraph @

testsuite/test_old/coba.cc

raw
1 /*
2 * This file is part of MUSIC.
3 * Copyright (C) 2007 CSC, KTH
4 *
5 * MUSIC is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * MUSIC is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #define N 4000
20
21 #define T 5.0
22 #define DT 1e-4
23 #define PRINT_EVERY_NTH 100
24 #define N_PLOTTED_ECELLS 5
25 #define N_PLOTTED_ICELLS 5
26
27 #define cell_area 20000e-12
28 #define tau_m 20e-3
29 #define C_m 1e-2
30 #define rho_leak 5e-1
31 #define Erev_leak -65e-3
32
33 #define Gexc 6e-9
34 #define Ginh 67e-9
35 #define Erev_exc 0
36 #define Erev_inh -80e-3
37 #define tau_exc 5e-3
38 #define tau_inh 10e-3
39
40 #define conn_prob 0.02
41 #define conn_delay 1e-6 // arbitrary non-zero
42
43 #define gNa 0.1e4
44 #define gKd 0.03e4
45 #define ENa 50e-3
46 #define EK -90e-3
47 #define Vtr -63e-3
48
49 #define N_e ((int) (0.8 * N))
50 #define N_i (N - N_e)
51
52 #include <iostream>
53 #include <cmath>
54
55 #include <split.hh>
56 #include <split/connection-set.hh>
57
58 using namespace libsplit;
59
60 class projection;
61
62 class cells
63 {
64 private:
65 split_int* split;
66 int _pop_id;
67 int _leak_id;
68 int _na_id;
69 int _k_id;
70 int _size;
71
72 public:
73 cells (split_int* _split, int size);
74 int pop_id () { return _pop_id; }
75 int na_id () { return _na_id; }
76 int size () { return _size; }
77
78 projection* project (cells* post);
79
80 void set_parameters ();
81 };
82
83 class projection
84 {
85 split_int* split;
86 int proj_id;
87 connection_set c;
88 public:
89 projection (split_int* _split, cells& pre, cells& post)
90 : split (_split), c (random_uniform (conn_prob))
91 {
92 c.init (0, pre.size (), 0, post.size ());
93 proj_id = split->create_projection (CHEMICAL_SYNAPSE, SCALAR,
94 pre.pop_id (), CONTRIB, pre.na_id (),
95 post.pop_id (), 0,
96 c.size ());
97 for (c.begin (); !c.end (); ++c)
98 {
99 split->set_projection_index_int (proj_id, SYN_PRE, c.id (), c.pre ());
100 split->set_projection_index_int (proj_id, SYN_POST, c.id (), c.post ());
101 split->set_projection_index_real (proj_id, SYN_DELAY, c.id (),
102 conn_delay);
103 }
104 }
105
106 void set_parameters (double G, double Erev, double tau)
107 {
108 split->set_projection_scalar_real (proj_id, SYN_E, Erev);
109 split->set_projection_scalar_real (proj_id, SYN_DURATION, 0.0);
110 split->set_projection_scalar_real (proj_id, SYN_RAISE, 0.0);
111 split->set_projection_scalar_real (proj_id, SYN_DECAY, tau);
112 for (c.begin (); !c.end (); ++c)
113 split->set_projection_index_real (proj_id, SYN_G, c.id (), G);
114 }
115 };
116
117 cells::cells (split_int* _split, int size)
118 : split (_split), _size (size)
119 {
120 int tree_map[1] = { 0 };
121 _pop_id = split->create_population ();
122 split->create_electric_tree (_pop_id, ELECTRIC_SCALAR_STAR, N_e, 0, 0,
123 tree_map /* dummy */ );
124 _leak_id = split->create_e_leak (_pop_id, N_e, 0);
125 _na_id = split->create_simple_channel (_pop_id, TRAUB_NA, SCALAR, N_e, 0);
126 _k_id = split->create_simple_channel (_pop_id, HH_K, SCALAR, N_e, 0);
127 }
128
129 projection*
130 cells::project (cells* post)
131 {
132 return new projection (split, *this, *post);
133 }
134
135 void
136 cells::set_parameters ()
137 {
138 split->set_scalar_real (_pop_id, ELECTRIC, 0, CM, cell_area * C_m);
139 split->set_scalar_real (_pop_id, ELECTRIC, 0, GCORE, 0);
140 split->set_scalar_real (_pop_id, CONTRIB, _leak_id, E_LEAK_E, Erev_leak);
141 for (int i = 0; i < _size; ++i)
142 {
143 split->set_index_real (_pop_id, ELECTRIC, 0, INITIAL, i, Erev_leak);
144 split->set_index_real (_pop_id, CONTRIB, _leak_id,
145 E_LEAK_G_M, i, cell_area * rho_leak);
146 }
147
148 // Na activation
149 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
150 ACT_ALPHA_A, 0.32e6);
151 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
152 ACT_ALPHA_B, 13e-3 + Vtr);
153 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
154 ACT_ALPHA_C, 4e-3);
155 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
156 ACT_BETA_A, 0.28e6);
157 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
158 ACT_BETA_B, 40e-3 + Vtr);
159 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
160 ACT_BETA_C, 5e-3);
161 split->set_scalar_int (_pop_id, CONTRIB, _na_id,
162 ACT_EXPO, 3);
163 // Na inactivation
164 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
165 INACT_ALPHA_A, 0.128e3);
166 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
167 INACT_ALPHA_B, 17e-3 + Vtr);
168 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
169 INACT_ALPHA_C, 18e-3);
170 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
171 INACT_BETA_A, 4e3);
172 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
173 INACT_BETA_B, 40e-3 + Vtr);
174 split->set_scalar_real (_pop_id, CONTRIB, _na_id,
175 INACT_BETA_C, 5e-3);
176 split->set_scalar_int (_pop_id, CONTRIB, _na_id,
177 INACT_EXPO, 1);
178 // K
179 split->set_scalar_real (_pop_id, CONTRIB, _k_id,
180 ACT_ALPHA_A, 0.032e6);
181 split->set_scalar_real (_pop_id, CONTRIB, _k_id,
182 ACT_ALPHA_B, 15e-3 + Vtr);
183 split->set_scalar_real (_pop_id, CONTRIB, _k_id,
184 ACT_ALPHA_C, 5e-3);
185 split->set_scalar_real (_pop_id, CONTRIB, _k_id,
186 ACT_BETA_A, 0.5e3);
187 split->set_scalar_real (_pop_id, CONTRIB, _k_id,
188 ACT_BETA_B, 10e-3 + Vtr);
189 split->set_scalar_real (_pop_id, CONTRIB, _k_id,
190 ACT_BETA_C, 40e-3);
191 split->set_scalar_int (_pop_id, CONTRIB, _k_id,
192 ACT_EXPO, 4);
193
194 for (int i = 0; i < _size; ++i)
195 {
196 // Na
197 split->set_index_real (_pop_id, CONTRIB, _na_id,
198 CHAN_E, i, ENa);
199 split->set_index_real (_pop_id, CONTRIB, _na_id,
200 CHAN_G, i, cell_area * gNa);
201 // K
202 split->set_index_real (_pop_id, CONTRIB, _k_id,
203 CHAN_E, i, EK);
204 split->set_index_real (_pop_id, CONTRIB, _k_id,
205 CHAN_G, i, cell_area * gKd);
206 }
207 }
208
209 class noise {
210 split_int* split;
211 cells* c;
212 int id;
213 public:
214 noise (split_int* _split, cells* _c)
215 : split (_split), c (_c)
216 {
217 id = split->create_noise (c->pop_id (), c->size (), 0);
218 }
219 void set_parameters ()
220 {
221 for (int i = 0; i < c->size (); ++i)
222 {
223 split->set_index_real (c->pop_id (), CONTRIB, id,
224 NOISE_E, i, 0);
225 split->set_index_real (c->pop_id (), CONTRIB, id,
226 NOISE_G, i, 7.5e-10);
227 split->set_index_real (c->pop_id (), CONTRIB, id,
228 NOISE_INTENSITY, i, 100);
229 split->set_index_real (c->pop_id (), CONTRIB, id,
230 NOISE_INITIAL, i, 0);
231 split->set_index_real (c->pop_id (), CONTRIB, id,
232 NOISE_TAU, i, 0.01);
233 split->set_index_real (c->pop_id (), CONTRIB, id,
234 NOISE_START_TIME, i, 0);
235 split->set_index_real (c->pop_id (), CONTRIB, id,
236 NOISE_END_TIME, i, 0.05);
237 }
238 }
239 };
240
241 void
242 setup_volts_plot (split_int* split, int id, cells* c, int n, int& idx)
243 {
244 for (int i = 0; i < n; ++i)
245 {
246 split->set_plot_index_int (id, idx, PLOT_ID, 0);
247 split->set_plot_index_int (id, idx, PLOT_POP_ID, c->pop_id ());
248 split->set_plot_index_int (id, idx, PLOT_TYPE, ELECTRIC);
249 split->set_plot_index_int (id, idx, PLOT_TAG, STATE_SV);
250 split->set_plot_index_int (id, idx, PLOT_IDX, i);
251 split->set_plot_index_real (id, idx, PLOT_MIN, -0.08);
252 split->set_plot_index_real (id, idx, PLOT_MAX, 0.05);
253 ++idx;
254 }
255 }
256
257 int
258 main (int argc, char **argv)
259 {
260 std::cout << "Setup\n";
261
262 split_int* split = new split_int (&argc, &argv);
263
264 // Create cells
265 cells* ecells = new cells (split, N_e);
266 cells* icells = new cells (split, N_i);
267
268 // Create synapses
269 projection* ee = ecells->project (ecells);
270 projection* ei = ecells->project (icells);
271 projection* ii = icells->project (icells);
272 projection* ie = icells->project (ecells);
273
274 // Create ports
275 int n_ports = 0;
276 while (true)
277 {
278 std::ostrstream portname;
279 portname << "ein" << n_ports;
280 if (is_port (portname.str ()))
281 {
282 split->create_spike_input (portname.str (), ecells->pop_id (), 0, N);
283 std::ostrstream portname;
284 portname << "iin" << n_ports;
285 if (is_port (portname.sr ()))
286 split->create_spike_input (portname.str (), icells->pop_id (), 0, N);
287 ++n_ports;
288 }
289 else
290 break;
291 }
292 if (n_ports > 0)
293 {
294 split->create_spike_output ("eout", ecells->pop_id (), CONTRIB, ecells->na_id ());
295 split->create_spike_output ("iout", icells->pop_id (), CONTRIB, icells->na_id ());
296 }
297
298 // Noiseinjection
299 noise* enoise = new noise (split, ecells);
300 noise* inoise = new noise (split, icells);
301
302 // Volt plots
303 int volts_id = split->create_plot ("volts.out",
304 N_PLOTTED_ECELLS + N_PLOTTED_ICELLS);
305 split->set_plot_scalar_int (volts_id, PLOT_EVERY_NTH, 1);
306 int idx = 0;
307 setup_volts_plot (split, volts_id, ecells, N_PLOTTED_ECELLS, idx);
308 setup_volts_plot (split, volts_id, icells, N_PLOTTED_ICELLS, idx);
309
310 // Spike plot
311 int spikes_id = split->create_spike_plot_ranges ("spikes.out");
312 split->set_plot_range (spikes_id, ecells->pop_id (), ELECTRIC, 0,
313 STATE_SV, 0, ecells->size ());
314 split->set_plot_range (spikes_id, icells->pop_id (), ELECTRIC, 0,
315 STATE_SV, 0, icells->size ());
316
317 // Distribute simulation onto slaves
318 split->map (0);
319
320 // Cell parameters
321 ecells->set_parameters ();
322 icells->set_parameters ();
323
324 // Synaptic parameters
325 ee->set_parameters (Gexc, Erev_exc, tau_exc);
326 ei->set_parameters (Gexc, Erev_exc, tau_exc);
327 ii->set_parameters (Ginh, Erev_inh, tau_inh);
328 ie->set_parameters (Ginh, Erev_inh, tau_inh);
329
330 // Noise parameters
331 enoise->set_parameters ();
332 inoise->set_parameters ();
333
334 // Allocate
335 split->allocate (0.0, T, DT);
336
337 // Initialize
338 split->initialize (DT);
339
340 // Simulate
341 std::cout << "Simulate\n";
342 int total_steps = (int) ceil (T / DT);
343 for (int steps = 0; steps < total_steps; steps += PRINT_EVERY_NTH)
344 split->simulate (PRINT_EVERY_NTH);
345
346 // Quit
347 split->quit ();
348
349 return 0;
350 }