Exemplo n.º 1
0
def mkmitral(gid):
    if ismitral(gid):
        nrn = genMitral(gid)
        m = h.Mitral(gid)
    else:
        nrn = genMTufted(gid)
        m = h.mTufted(gid)

    m.createsec(len(nrn.dend), len(nrn.tuft))

    for i, d in enumerate(nrn.dend):

        if d.parent == nrn.soma[0]:
            m.secden[i].connect(m.soma(.5))
        else:
            index = nrn.dend.index(d.parent)
            m.secden[i].connect(m.secden[index](1))

    m.geometry()  # again to get the hillock stylized shape

    fillall(nrn, m)

    m.subsets()
    m.topol()  # need to connect secondary dendrites explicitly
    m.segments(
    )  # again to get the proper number of segments for tuft and secden
    m.memb()

    m.setup_orns(gid, params.stream_orn_w)

    if ismitral(gid):
        orn_g_std = params.orn_g_mc_std
        orn_g_baseline = params.orn_g_mc_baseline
        orn_g_max = params.orn_g_mc_max
    elif ismtufted(gid):
        orn_g_std = params.orn_g_mt_std
        orn_g_baseline = params.orn_g_mt_baseline
        orn_g_max = params.orn_g_mt_max

    for i in range(int(m.ntuft)):
        m.ornsyn.o(i).g_e_baseline = orn_g_baseline
        m.ornsyn.o(i).std_e = orn_g_std
        m.ornsyn.o(i).g_e_max = orn_g_max

    if mgid2glom(gid) in params.vclamp:
        m.vcinit()

    return m
def _pd(mgid, isec, x):
  try:
    m = mitrals[mgid]
  except KeyError:
    if gidfunc.ismitral(mgid):
      m = grow.genMitral(mgid)
    elif gidfunc.ismtufted(mgid):
      m = grow.genMTufted(mgid)
    mitrals[mgid] = m

  d = x * (len(m.dend[isec].points)-1)
  sec = m.dend[isec].parent
  while sec != m.soma[0]:
    d += len(sec.points)-1
    sec = sec.parent
  return d*20
Exemplo n.º 3
0
 def issynapse(gid):
     return not (gidfunc.ismitral(gid) or gidfunc.ismtufted(gid)
                 or gidfunc.isgranule(gid))
Exemplo n.º 4
0
def init():
    data = {}
    for uid in range(nhost):
      data.update({ uid:(getmodel().mitrals.keys()) })
    data = a2a.all2all(data)
    mgids = []
    for _mgids in data.values(): mgids += _mgids
    mgids = set(mgids)

    # initialize source
    
    for mgid in getmodel().mitrals.keys():
        mpriden = split.mpriden(mgid)
        if not mpriden:
          continue
       
        rgj = params.ranstream(mgid, params.stream_gap_junction)

        
        mpriden.push()
        secref = h.SectionRef()
        h.pop_section()
        
        h.mk_gj_src(pc, mgid, secref)

        glomid = mgid2glom(mgid)
        
        sistergids = []

        # no longer all to all, only a chain
        if not (ismtufted(mgid) and (mgid - nmi) % nmt == (nmt - 1)):
            if ismitral(mgid) and mgid % nmxg == (nmxg - 1):
                sistergids += [glomid * nmt + nmi]
            else:
                sistergids += [mgid + 1]
            
        if not (ismitral(mgid) and mgid % nmxg == 0):
            if ismtufted(mgid) and (mgid - nmi) % nmt == 0:
                sistergids += [(glomid + 1) * nmxg - 1]
            else:
                sistergids += [mgid - 1]
            
        sistergids = mgids.intersection(range(glomid * nmxg, glomid * nmxg + nmxg) + range(glomid * nmt + nmi, glomid * nmt + nmt + nmi)).difference([ mgid ])  

        for sistermgid in sistergids:
            gap = h.Gap(mpriden(0.99))

            if ismitral(mgid) and ismitral(sistermgid):
                gap.g = rgj.uniform(gj_min_g1, gj_max_g1)
            elif  ismtufted(mgid) and ismtufted(sistermgid):
                gap.g = rgj.uniform(gj_min_g3, gj_max_g3)
            else:
                gap.g = rgj.uniform(gj_min_g2, gj_max_g2)
                

            getmodel().gj[(mgid, sistermgid)] = gap
            

    pc.barrier()

    # initialize targets
    for key, gap in getmodel().gj.items():
        mgid, sistermgid = key
        pc.target_var(gap, gap._ref_vgap, sistermgid)

    util.elapsed('Gap junctions built')
Exemplo n.º 5
0
def multisplit_distrib(model):
    enter = h.startsw()

    cxlist = determine_multisplit_complexity(model)

    #start over
    destroy_model(model)

    # fake cell to solve problem with gap junctions
    #  init_fake_cell()

    # but we still have model.mconnections and model.rank_gconnections
    # from the round-robin distribution perspective.
    # we will need to tell the ranks  where to distribute that information

    cxlist = load_bal(
        cxlist,
        nhost)  #cxlist is the list of (cx,(gid,piece)) we want on this process
    # the new distribution of mitrals and granules
    model.gids = set([item[1][0] for item in cxlist])
    model.mitral_gids = set(
        [gid for gid in model.gids if ismitral(gid) or ismtufted(gid)])
    model.granule_gids = set([gid for gid in model.gids if isgranule(gid)])
    model.blanes_gids = set([gid for gid in model.gids if isblanes(gid)])

    # for splitting need gid:[pieceindices]
    gid2pieces = {}
    for item in cxlist:
        gid = item[1][0]
        piece = item[1][1]
        if not gid2pieces.has_key(gid):
            gid2pieces[gid] = []
        gid2pieces[gid].append(piece)

    # get the correct mconnections and gconnections
    # Round-robin ranks that presently have the connection info for the gids
    rr = {}
    for gid in model.gids:
        r = gid % nhost
        if not rr.has_key(r):
            rr[r] = []
        rr[r].append(gid)
    rr = all2all(rr)
    # rr is now the ranks for where to send the synapse information
    # all the gids in rr were 'owned' by the round-robin distribution
    # may wish to revisit so that only synapse info for relevant pieces is
    # scattered.

    mc = model.mconnections
    gc = model.rank_gconnections

    # construct a ggid2connection dict
    ggid2connection = {}
    for r in gc:
        for ci in gc[r]:
            ggid = ci[3]
            if not ggid2connection.has_key(ggid):
                ggid2connection[ggid] = []
            ggid2connection[ggid].append(ci)

    for r in rr:
        gids = rr[r]
        mgci = []
        rr[r] = mgci
        for gid in gids:

            if mc.has_key(gid):
                mgci.append(mc[gid])
            elif gidfunc.isgranule(gid):
                mgci.append(ggid2connection[gid])
    mgci = all2all(rr)

    # mgci contains all the connection info needed by the balanced distribution

    # create mitrals and granules, split and register and create synapses
    nmc.dc.mk_mitrals(model)  # whole cells
    nmc.build_granules(model)
    nmc.build_blanes(model)

    for gid in gid2pieces:
        if ismitral(gid) or ismtufted(gid):
            split.splitmitral(gid, model.mitrals[gid], gid2pieces[gid])

    pc.multisplit()

    nmc.register_mitrals(model)
    nmc.register_granules(model)
    nmc.register_blanes(model)

    # build_synapses() ... use mgci to build explicitly
    model.mgrss = {}
    for r in mgci:
        for cil in mgci[r]:
            for ci in cil:
                if not model.mgrss.has_key(mgrs.mgrs_gid(ci[0], ci[3], ci[6])):
                    rsyn = mgrs.mk_mgrs(*ci[0:7])
                    if rsyn:
                        model.mgrss[rsyn.md_gid] = rsyn
    nmultiple = int(pc.allreduce(mgrs.multiple_cnt(), 1))

    # it is faster if generated again
    blanes.mk_gl2b_connections()
    # excitatory
    for mgid, blanes_gid, w in model.mt2blanes_connections:
        syn = blanes.mt2blanes(mgid, blanes_gid, w)
        model.mt2blanes[syn.gid] = syn

    blanes.mk_b2g_connections()
    # inhibitory synapses from blanes to gc
    for ggid, blanes_gid, w in model.blanes2gc_connections:
        syn = blanes.blanes2granule(blanes_gid, ggid, w)
        model.blanes2gc[syn.gid] = syn

    if rank == 0:
        print 'nmultiple = ', nmultiple
    detectors = h.List("AmpaNmda")
    util.elapsed('%d ampanmda for reciprocalsynapses constructed' %
                 int(pc.allreduce(detectors.count(), 1)))
    detectors = h.List("FastInhib")
    util.elapsed('%d fi for reciprocalsynapses constructed' %
                 int(pc.allreduce(detectors.count(), 1)))
    detectors = h.List("ThreshDetect")
    util.elapsed('%d ThreshDetect for reciprocalsynapses constructed' %
                 int(pc.allreduce(detectors.count(), 1)))
    util.elapsed('%d mt to bc' % int(pc.allreduce(len(model.mt2blanes), 1)))
    util.elapsed('%d bc to gc' % int(pc.allreduce(len(model.blanes2gc), 1)))

    if rank == 0: print 'multisplit_distrib time ', h.startsw() - enter
Exemplo n.º 6
0
def chk_gran_conn():
    model = modeldata.getmodel()
    ggids = model.granule_gids
    mgids = model.mitral_gids
    mgrss = model.mgrss

    # for each granule, list of all mgid it connects to and vice versa
    g2m = {}
    m2g = {}
    for mgrs in mgrss.values():
        ggid = mgrs.ggid
        mgid = mgrs.mgid
        if mgrs.gd:  # granule exists on this rank
            if ggid not in g2m:
                g2m[ggid] = []
            g2m[ggid].append(mgid)
        if mgrs.md:  # mitral or mtufted exists on this rank
            if mgid not in m2g:
                m2g[mgid] = []
            m2g[mgid].append(ggid)

    a = 'Number of granules that go to mitral and mtufted (regardless of glomerulus)'
    na = 0
    for ms in g2m.values():
        nmit = 0
        nmtuft = 0
        for mgid in ms:
            nmit += 1 if gidfunc.ismitral(mgid) else 0
            nmtuft += 1 if gidfunc.ismtufted(mgid) else 0
        na += 1 if nmit > 0 and nmtuft > 0 else 0
    na = int(pc.allreduce(na, 1))
    if pc.id() == 0:
        print("%d %s" % (na, a))

    a = '[total,imin,imax,iavg,xmin,xmax,xavg] granule connections to mitral'
    b = '[total,imin,imax,iavg,xmin,xmax,xavg] granule connections to mtuft'
    nab = [[[], [], [], []], [[], [], [], []]]

    for ms in g2m.values():
        # assume if first is mitral then all are mitrals otherwise mtuft
        dat = nab[0] if gidfunc.ismitral(ms[0]) else nab[1]

        # want to distinguish intra mitral, distinct mitral, and any mitral
        # generate map of distinct:count for that distinct instance
        distinct = {}
        for d in set(ms):
            distinct[d] = 0
        for m in ms:
            distinct[m] += 1

        n_any = len(ms)
        n_distinct_m = len(distinct)
        n_intra_m_min = min(distinct.values())
        n_intra_m_max = max(distinct.values())
        dat[0].append(n_any)
        dat[1].append(n_distinct_m)
        dat[2].append(n_intra_m_min)
        dat[3].append(n_intra_m_max)

    def nhost_len(v):
        return int(pc.allreduce(len(v), 1))

    def nhost_sum(v):
        return int(pc.allreduce(sum(v), 1))

    def nhost_max(v):
        return int(pc.allreduce(max(v), 2))

    def nhost_min(v):
        return int(pc.allreduce(min(v), 3))

    def pr0(s):
        if pc.id() == 0:
            print(s)

    def pr(title, dat):
        i = 0
        pr0(title)
        totg = nhost_len(dat[i])
        pr0("%d granules of this type" % totg)
        pr0("%d total connections" % nhost_sum(dat[i]))
        if totg:
            pr0("%d min ; %d max ; %g avg" % (nhost_min(
                dat[i]), nhost_max(dat[i]), float(nhost_sum(dat[i])) / totg))

    pr(a, nab[0])
    pr(b, nab[1])
Exemplo n.º 7
0
  def __init__(self, mgid, isec, xm, ggid, ipri, xg, slot):
    self.mgid = mgid
    self.ggid = ggid
    self.slot = slot
    self.xm = xm
    self.xg = xg
    self.isec = isec
    self.ipri = ipri
    
    self.msecden = split.msecden(mgid, isec)
    self.gpriden = split.gpriden(ggid, ipri)
    self.md_gid = mgrs_gid(mgid, ggid)
    self.gd_gid = mgrs_gid(ggid, mgid)
    self.md = None #ThreshDetect on mitral
    self.gd = None #ThreshDetect on granule
    if params.use_fi_stdp:
      self.fi = None #FastInhibSTDP on mitral
      self.postspike2fi = None # negative weight NetCon from md to fi
    else:
      self.fi = None #FastInhib on mitral
    self.ampanmda = None #AmpaNmda on granule
    self.gd2fi = None #NetCon to fi
    self.md2ampanmda = None #NetCon to ampanmda

    if pc.gid_exists(self.md_gid) > 0. or pc.gid_exists(self.gd_gid) > 0.:
      print "md_gid=%d and/or gd_gid=%d already registered" % (self.md_gid, self.gd_gid)
      raise RuntimeError

    if self.msecden:
      self.md = h.ThreshDetect(self.msecden(xm))
      if params.use_fi_stdp:
        self.fi = h.FastInhibSTDP(self.msecden(xm))
        nc = h.NetCon(self.md, self.fi)
        self.postspike2fi = nc
        nc.weight[0] = -1
        nc.delay = 1

      else:
        self.fi = h.FastInhib(self.msecden(xm))
        try:
          if params.training_inh:
            self.fi.training = 1
          else:
            self.fi.training = 0
        except:
#          print 'error'
          self.fi.training = 1
          
      if ismitral(mgid):
        self.fi.gmax = params.mc_inh_gmax
        self.fi.tau1 = params.mc_fi_tau1
        self.fi.tau2 = params.mc_fi_tau2
      elif ismtufted(mgid):
        self.fi.gmax = params.mt_inh_gmax
        self.fi.tau1 = params.mt_fi_tau1
        self.fi.tau2 = params.mt_fi_tau2

      pc.set_gid2node(self.md_gid, pc.id())
      pc.cell(self.md_gid, h.NetCon(self.md, None), 1)

    if self.gpriden:
      self.spine = h.GranuleSpine()
      if gcissup(self.ggid):
        self.spine.sup_deep_flag(1)
      else:
        self.spine.sup_deep_flag(0)

      self.spine.neck.connect(self.gpriden(xg))
      
      #self.dsac = dSAC(self.ggid, self.spine)
      
      self.gd = h.ThreshDetect(self.spine.head(0.5))
      self.gd.vthresh = -50
      self.ampanmda = h.AmpaNmda(self.spine.head(0.5))
      if ismitral(mgid):
        self.ampanmda.gmax = params.mc_exc_gmax
      elif ismtufted(mgid):
        self.ampanmda.gmax = params.mt_exc_gmax
      try:
        if params.training_exc:
          self.ampanmda.training = 1
        else:
          self.ampanmda.training = 0
      except:
#        print 'error'
        self.ampanmda.training = 1

      pc.set_gid2node(self.gd_gid, pc.id())
      pc.cell(self.gd_gid, h.NetCon(self.gd, None), 1)

    # Cannot be done above because output ports must exist prior to using 
    # an output gid as an input port on the same process.
    if self.fi:
      self.gd2fi = pc.gid_connect(self.gd_gid, self.fi)
      if params.use_fi_stdp:
        self.gd2fi.weight[0] = 1
      else:
        self.gd2fi.weight[0] = 1 # normalized
        try:
          init_inh_weight = params.init_inh_weight
        except:
          init_inh_weight = 0
        self.gd2fi.weight[1] = init_inh_weight
      self.gd2fi.delay = 1
      
    if self.ampanmda:
      self.md2ampanmda = pc.gid_connect(self.md_gid, self.ampanmda)
      self.md2ampanmda.weight[0] = 1 #normalized
      try:
        init_exc_weight = params.init_exc_weight
      except:
        init_exc_weight = 0
      self.md2ampanmda.weight[1] = init_exc_weight
      self.md2ampanmda.delay = 1