Example #1
0
def mkcells(gidinfo):
    timeit()
    for gid in gidinfo:
        x, y, z = gidinfo[gid]
        cell = h.Cell()
        gidinfo[gid] = CellInfo(cell)

        # cell shape is actually an arc and area is fastidious with respect
        # to all 6 sides. But length
        # treated as line distance between org points (interior corners
        # in circumferential direction. Set diam so area is correct including
        # end areas.
        cell.soma.pt3dclear()
        cell.soma.pt3dadd(x, y, z, 1.)
        ilayer, icircle, ipt = gid2org(gid)
        x1, y1, z1 = xyz(ilayer, icircle, ipt + 1)
        cell.soma.pt3dadd(x1, y1, z1, 1.)
        length = cell.soma.L
        area = sum(mkgap.cell_side_areas(gid))
        diam = area / pi / length
        cell.soma.diam = diam
        assert (isclose(cell.soma(.5).area(), area, abs_tol=area * 1e-5))

        cell.position(x, y, z)
        pc.set_gid2node(gid, rank)
        nc = cell.connect2target(None)
        pc.cell(gid, nc)
    x = pc.allreduce(len(gidinfo), 1)
    pr("Global number of real cells is %d" % x)
    timeit("mkcells")
Example #2
0
def mkgaps(gidinfo, gaps):
    timeit()
    mark = set()
    for gapinfo in gaps.values():
        gg = (gapinfo.gid1, gapinfo.gid2)
        id = gapinfo.id
        mkhalfgap(gg[0], gg[1], id, gidinfo, mark)
        mkhalfgap(gg[1], gg[0], -id, gidinfo, mark)
    pc.setup_transfer()

    x = 0
    for cell in gidinfo.values():
        x += len(cell.gaps)
    x = pc.allreduce(x, 1)
    pr("Global number of halfgap is %d" % x)

    timeit("mkgaps")
Example #3
0
def setallgaps(meang, interval, drift):
    npurkgap = 0
    for gid1, cellinfo in gidinfo.items():
        for gid2, gap in cellinfo.gaps.items():
            gapinfo = mkgap.gaps[(gid1, gid2) if gid1 < gid2 else (gid2, gid1)]
            area = gapinfo.area
            g = mkgap.abscond(area, meang)
            if is_purkinje_gap(gapinfo.gid1, gapinfo.gid2):
                g *= param.purkinje_gap_factor
                cellinfo.is_purk = True
                npurkgap += 1
            gap.meang = g
            gap.gmax = g
            gap.gmin = g
            gap.g = g
            gap.rg = interval
            gap.drift = drift
    npurkgap = pc.allreduce(npurkgap, 1)
    pr("number of purkinje gaps is %d" % (npurkgap / 2))
Example #4
0
def cellconread():
  timeit()
  # new Heart-3D paraboloid organization
  global ncon, ncell, connections
  import cellorg, mkgap
  from cellorg import sim_layers, sim_circles
  ncell = cellorg.ngid
  #old way iterating over all possible cells takes 5.4 seconds
  for gid in range(rank, ncell, nhost):
    ilayer, icircle, ipt = cellorg.gid2org(gid)
    if icircle < cellorg.ncircle[ilayer] - 1:
      if cellorg.is_simulated(ilayer, icircle, ipt):
        xyz = cellorg.xyz(ilayer, icircle, ipt)
        gidinfo[gid] = xyz
  '''
  #new way iterating only over cells that exist takes
  import param as p
  for ilayer in sim_layers:
    for icircle in sim_circles[ilayer]:
      i0 = cellorg.angle2ipt(p.simulation_angledeg[0]*2*pi/360, ilayer, icircle)
      i1 = cellorg.angle2ipt(p.simulation_angledeg[1]*2*pi/360, ilayer, icircle)
      for ipt in range(i0, i1+1):
        if cellorg.is_simulated(ilayer, icircle, ipt):
          gid = cellorg.org2gid(ilayer, icircle, ipt)
          if gid%nhost == rank:
            gidinfo[gid] = cellorg.xyz(ilayer, icircle, ipt)
  '''
  timeit("gidinfo setup")

  for gid in gidinfo:
    # because of floating round-off error which may or may not create
    # a gap with area close to 0, guarantee gap pairs by only creating
    # gaps where gid1 < gid2
    mkgap.gaps_for_gid(gid)
  n = int(pc.allreduce(n_triang_zero(), 1))
  pr("accurate_triang_area calculation returned zero %d times" % n)
  timeit("connections determined")

  # for parallel, copy gid2 gaps to ranks that need them
  mkgap.gaps_gid2_copy()
  connections = mkgap.gaps
Example #5
0
def ecg_final():
  #return
  for i in range(nelectrode):
    pc.allreduce(ecg_v[i], 1)
Example #6
0
 def nhost_min(v):
     return int(pc.allreduce(min(v), 3))
Example #7
0
 def nhost_max(v):
     return int(pc.allreduce(max(v), 2))
Example #8
0
 def nhost_sum(v):
     return int(pc.allreduce(sum(v), 1))
Example #9
0
 def nhost_len(v):
     return int(pc.allreduce(len(v), 1))
Example #10
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])