-
Notifications
You must be signed in to change notification settings - Fork 1
/
ring.py
82 lines (71 loc) · 2.11 KB
/
ring.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
from neuron import h
h.load_file('nrngui.hoc')
pc = h.ParallelContext()
rank = int(pc.id())
nhost = int(pc.nhost())
from cell import BallStick
class Ring(object):
def __init__(self, ncell, delay):
#print "construct ", self
self.delay = delay
self.ncell = int(ncell)
self.mkring(self.ncell)
self.mkstim()
self.spike_record()
def __del__(self):
pc.gid_clear()
#print "delete ", self
def mkring(self, ncell):
self.mkcells(ncell)
self.connectcells(ncell)
def mkcells(self, ncell):
global rank, nhost
self.cells = []
for i in range(rank, ncell, nhost):
cell = BallStick()
self.cells.append(cell)
pc.set_gid2node(i, rank)
nc = cell.connect2target(None)
pc.cell(i, nc)
def connectcells(self, ncell):
global rank, nhost
self.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)
self.nclist.append(nc)
nc.delay = self.delay
nc.weight[0] = 0.01
#Instrumentation - stimulation and recording
def mkstim(self):
if not pc.gid_exists(0):
return
self.stim = h.NetStim()
self.stim.number = 1
self.stim.start = 0
self.ncstim = h.NetCon(self.stim, pc.gid2cell(0).synlist[0])
self.ncstim.delay = 0
self.ncstim.weight[0] = 0.01
def spike_record(self):
self.tvec = h.Vector()
self.idvec = h.Vector()
for i in range(len(self.cells)):
nc = self.cells[i].connect2target(None)
pc.spike_record(nc.srcgid(), self.tvec, self.idvec)
def runring(ncell=5, delay=1, tstop=100):
ring = Ring(ncell, delay)
pc.set_maxstep(10)
h.stdinit()
pc.psolve(tstop)
spkcnt = pc.allreduce(len(ring.tvec), 1)
tmax = pc.allreduce(ring.tvec.x[-1], 2)
tt = h.Vector()
idv = h.Vector()
pc.allgather(ring.tvec.x[-1], tt)
pc.allgather(ring.idvec.x[-1], idv)
idmax = int(idv.x[int(tt.max_ind())])
return (int(spkcnt), tmax, idmax, (ncell, delay, tstop, (pc.id_world(), pc.nhost_world())))