I'm writing a code for network which is activated by the input spike trains recorded experimentally or from another model. I load all presynaptic spike events into a vectors and then play these vectors by VecStim-s. Everything worked perfect until I ran simulation on parallel MPI cluster. Surprisingly events generated by VecStim were received only by synapses at same host, other hosts received nothing.
Here a simple code to illustrate the problem:
Code: Select all
import pickle, time
import numpy as np
from mpi4py import MPI
from neuron import h
class cell:
def __init__(self):
#Passive cell
self.soma = h.Section()
self.soma.L = 40.
self.soma.diam = 20.
self.soma.nseg = 1
self.soma.insert("pas")
self.soma.g_pas = 0.001
self.soma.e_pas = -65
#record voltage into vector
self.volt = h.Vector()
self.volt.record(self.soma(0.5)._ref_v)
#simple synapse
self.syn = h.Exp2Syn(0.5, sec=self.soma)
self.syn.tau1 = 1.
self.syn.tau2 = 2.
self.syn.e = 0
#record synaptic current
self.syni = h.Vector()
self.syni.record(self.syn._ref_i)
#Create Parallel Contex
pc = h.ParallelContext()
#if I'm host #0, I also source of spike
# events for all cells.
# event source has gid=0
if int(pc.id()) == 0:
d =np.genfromtxt("timevec.dat")
vs = h.VecStim()
vec = h.Vector(d.size)
vec.from_python(d)
vs.play(vec)
netcon = h.NetCon(vs,None)
pc.set_gid2node(0,pc.id())
pc.cell(0,netcon)
#Create cell
c = cell()
#Connect synapse with source
nc = pc.gid_connect(0,c.syn)
#setup delay and synaptic conductance
nc.delay = 1
nc.weight[0] = 0.1
#load some file for NSG portal
h.load_file("stdgui.hoc")
#init, init max step
# and run
h.stdinit()
h.tstop = 100
h.dt = 0.001
pc.set_maxstep(0.05)
########################
pc.psolve(100) #Works weird
#========= OR =========#
#h.run() #Works well
########################
# save to pickle object
with open("v%d.pkl"%int(pc.id()),'wb') as fd:
pickle.dump(np.array(c.volt),fd)
pickle.dump(np.array(c.syni),fd)
#well done
pc.runworker()
time.sleep(1)
pc.done()
exit()
However when I used h.run() function instead of pc.psolve() the result looked much better
The question is that: is it OK to use h.run() instead psolve()? If no where I made a mistake which lead to this strange result?
Thanks,
-Ruben