-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathringpar.py
99 lines (80 loc) · 1.86 KB
/
ringpar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from neuron import h
h.load_file('nrngui.hoc')
pc = h.ParallelContext()
rank = int(pc.id())
nhost = int(pc.nhost())
from cell import BallStick
# Network Creation
NCELL = 20
cells = []
nclist = []
def mkring(ncell):
mkcells(ncell)
connectcells()
def mkcells(ncell):
global cells, rank, nhost
cells = []
for i in range(rank, ncell, nhost):
cell = BallStick()
cells.append(cell)
pc.set_gid2node(i, rank)
nc = cell.connect2target(None)
pc.cell(i, nc)
def connectcells():
global cells, nclist, rank, nhost, NCELL
nclist = []
# not efficient but demonstrates use of pc.gid_exists
for i in range(NCELL):
targid = (i+1)%NCELL
if pc.gid_exists(targid):
target = pc.gid2cell(targid)
syn = target.synlist[0]
nc = pc.gid_connect(i, syn)
nclist.append(nc)
nc.delay = 1
nc.weight[0] = 0.01
mkring(NCELL)
#Instrumentation - stimulation and recording
def mkstim():
''' stimulate gid 0 with NetStim to start ring '''
global stim, ncstim
if not pc.gid_exists(0):
return
stim = h.NetStim()
stim.number = 1
stim.start = 0
ncstim = h.NetCon(stim, pc.gid2cell(0).synlist[0])
ncstim.delay = 0
ncstim.weight[0] = 0.01
mkstim()
def spike_record():
''' record spikes from all gids '''
global tvec, idvec
tvec = h.Vector()
idvec = h.Vector()
pc.spike_record(-1, tvec, idvec)
def prun(tstop):
''' simulation control '''
pc.set_maxstep(10)
h.stdinit()
pc.psolve(tstop)
def spikeout():
''' report simulation results to stdout '''
global rank, tvec, idvec
pc.barrier()
for i in range(nhost):
if i == rank:
for i in range(len(tvec)):
print('%g %d' % (tvec.x[i], int(idvec.x[i])))
pc.barrier()
def finish():
''' proper exit '''
pc.runworker()
pc.done()
h.quit()
if __name__ == '__main__':
spike_record()
prun(100)
spikeout()
if (nhost > 1):
finish()