Esempio n. 1
0
def prun(tstop, restore=False):
    pc.set_maxstep(10 * ms)
    h.finitialize(-65 * mV)

    if restore == "SaveState":
        ns = h.SaveState()
        sf = h.File("state%d.bin" % pc.id())
        ns.fread(sf)
        ns.restore(0)  # event queue restored
        sf.close()
    elif restore == "BBSaveState":
        cp_out_to_in()  # prepare for restore.
        bbss = h.BBSaveState()
        bbss.restore_test()
    else:
        pc.psolve(tstop / 2)

        # SaveState save
        ss = h.SaveState()
        ss.save()
        sf = h.File("state%d.bin" % pc.id())
        ss.fwrite(sf)
        sf.close()

        # BBSaveState Save
        cnt = h.List("PythonObject").count()
        for i in range(1):
            bbss = h.BBSaveState()
            bbss.save_test()
            bbss = None
        assert h.List("PythonObject").count() == cnt

    pc.psolve(tstop)
Esempio n. 2
0
def run2(tstop, mode=None):
    pc.set_maxstep(10)
    h.finitialize()
    if mode == "save_test":
        pc.psolve(tstop / 2)
        h.BBSaveState().save_test()
    elif mode == "restore_test":
        cp_out_to_in()
        h.BBSaveState().restore_test()
    pc.psolve(tstop)
Esempio n. 3
0
 def srun(tsave, tstop):
     cvode = h.CVode()
     qm = cvode.queue_mode()
     print("srun tsave=%g tstop=%g start=%g delay=%g %s" %
           (tsave, tstop, ns.start, nsnc.delay, "binq" if qm else ""))
     run(tsave)
     st = spiketime.c()
     sg = spikegid.c()
     bbss = h.BBSaveState()
     bbss.save("allcell_bbss.dat")
     qm = 0
     if qm:
         print("after save")
         h.CVode().print_event_queue()
     h.finitialize(-65)
     spiketime.resize(0)
     spikegid.resize(0)
     bbss.restore("allcell_bbss.dat")
     if qm:
         print("after restore")
         h.CVode().print_event_queue()
     pc.psolve(tstop)
     st.append(spiketime)
     sg.append(spikegid)
     spiketime.copy(st)
     spikegid.copy(sg)
     print("    %d spikes" % len(spiketime))
Esempio n. 4
0
def test_6():  # Test BBSaveState.ignore
    rmfiles()
    model = Ring(5, 0)
    syn = model.cells[0].syn
    prun(1)
    h.finitialize(-65)
    g_expect = syn.g
    pc.psolve(20)
    g_actual = syn.g
    bbss = h.BBSaveState()
    bbss.ignore(syn)
    bbss.save("allcell-bbss.dat")
    h.finitialize(-65)
    bbss.restore("allcell-bbss.dat")
    print(g_expect, g_actual, syn.g)
    assert syn.g == g_expect
    h.finitialize(-65)
    pc.psolve(20)
    bbss.ignore(syn)
    bbss.ignore()
    bbss.save("allcell-bbss.dat")
    h.finitialize(-65)
    bbss.restore("allcell-bbss.dat")
    print(g_expect, g_actual, syn.g)
    assert abs((syn.g - g_actual) / (syn.g + g_actual)) < 1e-12

    pc.gid_clear()
Esempio n. 5
0
def test_7():  # save a ring with n cells and extra section, restore n-1 cells
    rmfiles()
    model = Ring(5, 0)
    model.cells[0].foo = h.Section(name="foo", cell=model.cells[0])
    prun(5)
    v_expect = model.cells[0].soma(0.5).v
    bbss = h.BBSaveState()
    bbss.save_test()
    model = Ring(4, 0)
    prun(0.1)
    bbss = h.BBSaveState()
    cp_out_to_in()
    bbss.restore_test()
    print(v_expect, model.cells[0].soma(0.5).v)
    assert abs(v_expect - model.cells[0].soma(0.5).v) < 1e-13

    pc.gid_clear()
Esempio n. 6
0
def prun(tstop, mode=None):
    pc.set_maxstep(10 * ms)
    h.finitialize(-65 * mV)

    if mode == "save_test":  # integrate to tstop/2 and save
        pc.psolve(tstop / 2)
        bbss = h.BBSaveState()
        bbss.save_test()  # creates separate file in bbss_out for each piece
    elif mode == "save_test_bin":
        pc.psolve(tstop / 2)
        bbss = h.BBSaveState()
        bbss.save_test_bin(
        )  # like save_test but binary wholecell in binbufout
    elif mode == "save":
        pc.psolve(tstop / 2)
        bbss = h.BBSaveState()
        bbss.save("allcell-bbss.dat")  # single file for everything (nhost==1!)
    elif mode == "restore_test":
        cp_out_to_in()  # prepare for restore.
        bbss = h.BBSaveState()
        bbss.restore_test()
    elif mode == "restore_test_bin":
        subprocess_run("mkdir binbufin")
        subprocess_run("cp binbufout/* binbufin")
        bbss = h.BBSaveState()
        bbss.restore_test_bin()
    elif mode == "restore":
        bbss = h.BBSaveState()
        bbss.restore("allcell-bbss.dat")
        bbss.vector_play_init()  # just for coverage as there are none.

    pc.psolve(tstop)  # integrate the rest of the way
Esempio n. 7
0
def test_3():
    rmfiles()
    hl = hlist()
    npo = hl.count()

    stdspikes = {
        0.0: [
            1.975000000099995,
            21.300000000099324,
            39.70000000010047,
            58.05000000010464,
            76.4000000001088,
            94.80000000011299,
        ],
        1.0: [
            5.9250000001000505,
            24.800000000099125,
            43.32500000010129,
            61.725000000105474,
            80.10000000010965,
            98.47500000011382,
        ],
        2.0: [
            9.900000000099972,
            28.40000000009892,
            46.950000000102115,
            65.3750000001063,
            83.77500000011048,
        ],
        3.0: [
            13.900000000099745,
            32.15000000009875,
            50.600000000102945,
            69.02500000010713,
            87.45000000011132,
        ],
        4.0: [
            17.900000000099517,
            36.02500000009963,
            54.32500000010379,
            72.70000000010796,
            91.12500000011215,
        ],
    }

    ring = Ring(3, 2)
    assert hl.count() == npo

    prun(100 * ms)
    if "usetable_hh" not in dir(h):  # coreneuron has different hh.mod
        stdspikes = get_all_spikes(ring)
    compare_dicts(get_all_spikes(ring), stdspikes)
    stdspikes_after_50 = {}
    for gid in stdspikes:
        stdspikes_after_50[gid] = [
            spk_t for spk_t in stdspikes[gid] if spk_t >= 50.0
        ]

    prun(100 * ms, mode="save_test")  # at tstop/2 does a BBSaveState.save
    assert hl.count() == npo
    compare_dicts(get_all_spikes(ring), stdspikes)

    prun(100 * ms,
         mode="restore_test")  # BBSaveState restore to start at t = tstop/2
    assert hl.count() == npo
    compare_dicts(get_all_spikes(ring), stdspikes_after_50)

    # while we are at it check the BBSaveState binary file mode.
    prun(100 * ms, mode="save_test_bin")
    compare_dicts(get_all_spikes(ring), stdspikes)
    prun(100 * ms, mode="restore_test_bin")
    compare_dicts(get_all_spikes(ring), stdspikes_after_50)

    # while we are at it check the BBSaveState save/restore single file mode.
    prun(100 * ms, mode="save")
    compare_dicts(get_all_spikes(ring), stdspikes)
    prun(100 * ms, mode="restore")
    compare_dicts(get_all_spikes(ring), stdspikes_after_50)
    assert hl.count() == npo

    # save_request works but not very useful as save_gid and restore_gid
    # not implemented.
    pc.set_maxstep(10)
    h.finitialize(-65)
    gids = h.Vector()
    sizes = h.Vector()
    bbss = h.BBSaveState()
    ngid = bbss.save_request(gids, sizes)
    assert ngid == len(ring.cells)
    # prints "not implemented"
    bbss.save_gid()
    bbss.restore_gid()
    assert hl.count() == npo
    del bbss

    # binq
    rmfiles()
    h.CVode().queue_mode(1)
    prun(100, mode="save")
    compare_dicts(get_all_spikes(ring), stdspikes)
    prun(100, mode="restore")
    compare_dicts(get_all_spikes(ring), stdspikes_after_50)
    prun(100, mode="save_test_bin")
    compare_dicts(get_all_spikes(ring), stdspikes)
    prun(100, mode="restore_test_bin")
    compare_dicts(get_all_spikes(ring), stdspikes_after_50)
    h.CVode().queue_mode(0)

    pc.gid_clear()
Esempio n. 8
0
def runBBSS():
    svst = h.BBSaveState()
    svst.save_test()