Esempio n. 1
0
def test_datareturn():
    from neuron import coreneuron
    coreneuron.enable = False

    model = Network()

    tstop = 5

    pc.set_maxstep(10)

    def run(tstop):
        h.finitialize(-65)
        pc.psolve(tstop)

    if show:
        # visual verify that cells and acells have different final results so that
        # data return comparisons are substantive.
        from neuron import gui
        h.steps_per_ms = 1. / h.dt
        h.setdt()
        h.tstop = tstop
        mkgraphs(model)
        h.run()
    else:
        run(tstop)  # NEURON run
    std = model.data()

    print("CoreNEURON run")
    h.CVode().cache_efficient(1)
    coreneuron.enable = True

    coreneuron.cell_permute = 0
    run(tstop)
    tst = model.data()
    max_unpermuted = h.Vector(std).sub(h.Vector(tst)).abs().max()
    print("max diff unpermuted = %g" % max_unpermuted)

    coreneuron.cell_permute = 1
    run(tstop)
    tst = model.data()
    max_permuted = h.Vector(std).sub(h.Vector(tst)).abs().max()
    print("max diff permuted = %g" % max_permuted)

    pc.nthread(2)
    run(tstop)
    tst = model.data()
    max_permuted_thread = h.Vector(std).sub(h.Vector(tst)).abs().max()

    coreneuron.enable = False

    print("max diff unpermuted = %g" % max_unpermuted)
    print("max diff permuted = %g" % max_permuted)
    print("max diff permuted with %d threads = %g" %
          (pc.nthread(), max_permuted_thread))

    assert (max_unpermuted < 1e-10)
    assert (max_permuted < 1e-10)
    assert (max_permuted_thread < 1e-10)

    if __name__ != "__main__":
        # tear down
        pc.nthread(1)
        pc.gid_clear()
        return None

    return model
tgls = [
    [0  , {'dt': 5     , 'steps_per_ms': 0.2}, []],
    [45 , {'dt': 0.0125, 'steps_per_ms': 2  }, []],
    [55 , {'dt': 0.05, 'steps_per_ms': 2  }, []],
    [200, {}, []]# end of simulation
]

for tgl in tgls:
    runto, attrs, execs = tgl[0], tgl[1], tgl[2]
    h.continuerun(runto)
    for attr in attrs:
        setattr(h, attr, attrs[attr])
## in case some hoc toggle function must be called.
    for exstr in execs:
        exec(exstr)
    h.setdt()

## additional calculations - surface area at our recording (current density * surface area = current)
## mA/cm2 * um2 * (cm2 / (1e8 * um2)) * ((1e6 * nA) / mA)
## mA * um2 * cm2 * 1e6nA
## ----------------------
##   cm2 * 1e8um2 * mA

## compute current from current density
area = csomas[0]('drgsoma')(0.5).area()
re_i = re.compile('(ina)|(ik)')
for trace in recvs:
    if re_i.search(trace):
        for cell in recvs[trace]:
            recvs[trace][cell].mul(area * 1e-2)
Esempio n. 3
0
def test_datareturn():
    from neuron import coreneuron

    coreneuron.enable = False

    model = Network()

    tstop = 5

    pc.set_maxstep(10)

    def run(tstop, mode):
        h.finitialize(-65)
        if mode == 0:
            pc.psolve(tstop)
        elif mode == 1:
            while h.t < tstop:
                pc.psolve(h.t + 1.0)
        else:
            while h.t < tstop:
                h.continuerun(h.t + 0.5)
                pc.psolve(h.t + 0.5)

    if show:
        # visual verify that cells and acells have different final results so that
        # data return comparisons are substantive.
        from neuron import gui

        h.steps_per_ms = 1.0 / h.dt
        h.setdt()
        h.tstop = tstop
        mkgraphs(model)
        h.run()
    else:
        run(tstop, 0)  # NEURON run
    std = model.data()

    print("CoreNEURON run")
    h.CVode().cache_efficient(1)
    coreneuron.enable = True
    coreneuron.gpu = bool(
        distutils.util.strtobool(os.environ.get("CORENRN_ENABLE_GPU", "false"))
    )

    coreneuron.cell_permute = 0
    for mode in [0, 1, 2]:
        run(tstop, mode)
        tst = model.data()
        max_unpermuted = h.Vector(std).sub(h.Vector(tst)).abs().max()
        print("mode ", mode)
        print("max diff unpermuted = %g" % max_unpermuted)

        coreneuron.cell_permute = 1
        run(tstop, mode)
        tst = model.data()
        max_permuted = h.Vector(std).sub(h.Vector(tst)).abs().max()
        print("max diff permuted = %g" % max_permuted)

        pc.nthread(2)
        run(tstop, mode)

        tst = model.data()
        max_permuted_thread = h.Vector(std).sub(h.Vector(tst)).abs().max()

        coreneuron.enable = False

        print(
            "max diff permuted with %d threads = %g"
            % (pc.nthread(), max_permuted_thread)
        )

        assert max_unpermuted < 1e-10
        assert max_permuted < 1e-10
        assert max_permuted_thread < 1e-10
        pc.nthread(1)

    if __name__ != "__main__":
        # tear down
        pc.nthread(1)
        pc.gid_clear()
        return None

    return model
Esempio n. 4
0
def test_datareturn():
    from neuron import coreneuron

    coreneuron.enable = False

    model = Network()

    tstop = 5

    pc.set_maxstep(10)

    def run(tstop, mode):
        h.finitialize(-65)
        if mode == 0:
            pc.psolve(tstop)
        elif mode == 1:
            while h.t < tstop:
                pc.psolve(h.t + 1.0)
        else:
            while h.t < tstop:
                h.continuerun(h.t + 0.5)
                pc.psolve(h.t + 0.5)

    if show:
        # visual verify that cells and acells have different final results so that
        # data return comparisons are substantive.
        from neuron import gui

        h.steps_per_ms = 1.0 / h.dt
        h.setdt()
        h.tstop = tstop
        mkgraphs(model)
        h.run()
    else:
        run(tstop, 0)  # NEURON run
    std = model.data()

    print("CoreNEURON run")
    h.CVode().cache_efficient(1)
    coreneuron.enable = True
    coreneuron.verbose = 0
    coreneuron.gpu = bool(
        distutils.util.strtobool(os.environ.get("CORENRN_ENABLE_GPU",
                                                "false")))

    results = []
    cell_permute_values = (1, 2) if coreneuron.gpu else (0, 1)
    for mode, nthread, cell_permute in itertools.product([0, 1, 2], [1, 2],
                                                         cell_permute_values):
        pc.nthread(nthread)
        coreneuron.cell_permute = cell_permute
        run(tstop, mode)
        tst = model.data()
        max_diff = (h.Vector(v for k, v in std).sub(h.Vector(
            v for k, v in tst)).abs().max())
        assert len(std) == len(tst)
        print("mode={} nthread={} permute={} max diff={}".format(
            mode, nthread, cell_permute, max_diff))
        results.append(max_diff)
        if max_diff > 1e-10:
            for i in range(len(std)):
                nrn_key, nrn_val = std[i]
                tst_key, tst_val = tst[i]
                assert nrn_key == tst_key
                if abs(nrn_val - tst_val) >= 1e-10:
                    print(i, nrn_key, nrn_val, tst_val, abs(nrn_val - tst_val))

    assert all(max_diff < 1e-10 for max_diff in results)

    if __name__ != "__main__":
        # tear down
        coreneuron.enable = False
        pc.nthread(1)
        pc.gid_clear()