Пример #1
0
def err_test2():
    r = Ring(3, 2)
    r.ncs[0].delay = 0
    pc.nthread(2)
    pc.set_maxstep(1)
    expect_err("h.finitialize(-65)")
    pc.nthread(1)
    r.ncs[0].delay = h.dt
    pc.set_maxstep(h.dt)
    h.finitialize(-65)
    if "'NRN_ENABLE_MPI=OFF'" not in h.nrnversion(6):
        # Fixed step method does not allow a mindelay < dt + 1e-10
        expect_err("pc.psolve(1.0)")  # wonder if this is too stringent an error
    else:
        pc.psolve(1.0)
    r.ncs[0].delay = 0
    assert pc.set_maxstep(1) == 1.0
    cvode.queue_mode(0, 1)
    pc.set_maxstep(1)
    h.finitialize(-65)
    pc.psolve(1)
    assert cvode.queue_mode() == 0
    v1 = h.Vector(10)
    pc.max_histogram(v1)
    v2 = h.Vector(10)
    pc.max_histogram()
    # cover nrn_gid2outpresyn
    pc.prcellstate(10000, "tmp")
    pc.prcellstate(0, "tmp")

    pc.gid_clear()
    del r
    locals()
Пример #2
0
def test_push_section():
    h("""create hCable1, hCable2""")
    h.push_section("hCable1")
    assert h.secname() == "hCable1"
    h.pop_section()
    h.push_section("hCable2")
    assert h.secname() == "hCable2"
    h.pop_section()
    h.delete_section(sec=h.hCable1)
    h.delete_section(sec=h.hCable2)

    sections = [h.Section(name="pCable%d" % i) for i in range(2)]
    sections.append(h.Section())  # Anonymous in the past
    for sec in sections:
        name_in_hoc = h.secname(sec=sec)
        h.push_section(name_in_hoc)
        assert h.secname() == name_in_hoc
        h.pop_section()
    s = sections[-1]
    h.delete_section(sec=s)  # but not yet freed (though the name is now "")
    # not [no longer] a section pointer
    expect_err(
        "s.hoc_internal_name()"
    )  # this is what is generating the error in the next statement.
    expect_err('h.push_section(int(s.hoc_internal_name().replace("__nrnsec_", ""), 0))')

    # not a sectionname
    expect_hocerr(h.push_section, ("not_a_sectionname",))
Пример #3
0
def test_praxis():
    vec = h.Vector([2, 3])
    h.attr_praxis(1e-5, 0.5, 0)
    print("x={} vec={}".format(efun(vec), vec.to_python()))
    x = h.fit_praxis(efun, vec)
    print("after fit_praxis x={} vec={}".format(x, vec.to_python()))

    vec.x[0] = 100.0
    expect_err("h.fit_praxis(efun, vec)")
    if __name__ == "__main__":
        vec.x[0] = 200.0
        print("another test")
        x = h.fit_praxis(efun, vec)
        print("this line gets printed in interactive mode")
Пример #4
0
def test_finithandler():
    soma = h.Section(name="soma")
    fih = h.FInitializeHandler(1, (callback, (0)))
    for i in range(2):
        h.finitialize()

    fih = h.FInitializeHandler(1, (callback, (1)))
    for i in range(1):
        expect_err("h.finitialize()")

    del fih  # a mysterious consequence of expect_err is that need this
    locals()  # in order for the callback to be deleted in time for next
    if __name__ == "__main__":
        print("another test")
        fih = h.FInitializeHandler(1, (callback, (2)))
        h.finitialize()
        print("this line gets printed in interactive mode")
Пример #5
0
def test_func_call():
    for sec in h.allsec():
        h.delete_section(sec=sec)
    soma = h.Section(name="soma")
    dend = h.Section(name="dend")
    axon = h.Section(name="axon")
    dend.connect(soma(0))
    dend.nseg = 5
    axon.connect(soma(1))
    axon.nseg = 3
    h.topology()
    invoke = False

    def f(x):
        y = x**2
        if invoke:
            if h.cas() == dend and x == 1.0:
                1 / 0
            if h.cas() == dend and x > 0.6:
                sys.exit(0)
        print("{}({})".format(h.cas(), x))
        return y

    # all points exist
    rvp = h.RangeVarPlot(f, dend(1.0), axon(1.0))
    vec = h.Vector()
    rvp.to_vector(vec)
    invoke = True

    # but no errors as those are marked non-existent
    h.RangeVarPlot(f, dend(1.0), axon(1.0))

    # now an error
    expect_err("rvp.to_vector(vec)")

    if __name__ == "__main__":
        invoke = False
        rvp = h.RangeVarPlot(f, dend(0.9), axon(1.0))
        invoke = True
        rvp.to_vector(vec)
        print("this test_func_call line gets printed in interactive mode")

    del soma, dend, axon, rvp, vec
    locals()
Пример #6
0
def test_nosection():
    expect_err("h.IClamp(.5)")
    expect_err("h.IClamp(5)")
    s = h.Section()
    expect_err("h.IClamp(5)")
    del s
    locals()
Пример #7
0
def test_disconnect():
    print("test_disconnect")
    for sec in h.allsec():
        h.delete_section(sec=sec)
    h.topology()
    n = 5

    def setup(n):
        sections = [h.Section(name="s%d" % i) for i in range(n)]
        for i, sec in enumerate(sections[1:]):
            sec.connect(sections[i])
        return sections

    sl = setup(n)

    def chk(sections, i):
        print(sections, i)
        h.topology()
        x = len(sections[0].wholetree())
        assert x == i

    chk(sl, n)

    h.disconnect(sec=sl[2])
    chk(sl, 2)

    sl = setup(n)
    sl[2].disconnect()
    chk(sl, 2)

    sl = setup(n)
    expect_err("h.disconnect(sl[2])")
    expect_err("h.delete_section(sl[2])")

    del sl
    locals()
Пример #8
0
def err_test1():
    r = Ring(3, 2)
    expect_err("pc.set_gid2node(0, pc.id())")
    nc = pc.gid_connect(10000, r.cells[0].syn)
    expect_err("pc.set_gid2node(10000, pc.id())")
    expect_err("pc.threshold(10000)")
    expect_err("pc.cell(10000)")
    expect_err("pc.cell(99999)")
    expect_err("pc.cell(0, None)")
    expect_err("pc.gid_connect(0, None)")
    pc.set_gid2node(99999, pc.id())
    expect_err("pc.gid_connect(99999, r.cells[0].syn)")
    expect_err("pc.gid_connect(1, r.cells[0].syn, h.Vector())")
    nc = h.NetCon(None, r.cells[1].syn)
    expect_err("pc.gid_connect(1, r.cells[0].syn, nc)")
    nc = h.NetCon(None, r.cells[0].syn)
    pc.gid_connect(1, r.cells[0].syn, nc)

    pc.gid_clear()
    del nc, r
    locals()
Пример #9
0
def test_deleted_sec():
    for sec in h.allsec():
        h.delete_section(sec=sec)
    s = h.Section()
    s.insert("hh")
    seg = s(0.5)
    ic = h.IClamp(seg)
    mech = seg.hh
    rvlist = [rv for rv in mech]
    vref = seg._ref_v
    gnabarref = mech._ref_gnabar
    sec_methods_ok = set([s.cell, s.name, s.hname, s.same, s.hoc_internal_name])
    sec_methods_chk = set(
        [
            getattr(s, n)
            for n in dir(s)
            if "__" not in n
            and type(getattr(s, n)) == type(s.x3d)
            and getattr(s, n) not in sec_methods_ok
        ]
    )
    seg_methods_chk = set(
        [
            getattr(seg, n)
            for n in dir(seg)
            if "__" not in n and type(getattr(seg, n)) == type(seg.area)
        ]
    )
    mech_methods_chk = set(
        [
            getattr(mech, n)
            for n in dir(mech)
            if "__" not in n and type(getattr(mech, n)) == type(mech.segment)
        ]
    )
    rv_methods_chk = set(
        [
            getattr(rvlist[0], n)
            for n in dir(rvlist[0])
            if "__" not in n and type(getattr(rvlist[0], n)) == type(rvlist[0].name)
        ]
    )
    rv_methods_chk.remove(rvlist[0].name)
    h.delete_section(sec=s)

    for methods in [sec_methods_chk, seg_methods_chk, mech_methods_chk, rv_methods_chk]:
        for m in methods:
            # Most would fail because of no args, but expect a check
            # for valid section first.
            words = str(m).split()
            print("m is " + words[4] + "." + words[2])
            expect_err("m()")

    assert str(s) == "<deleted section>"
    assert str(seg) == "<segment of deleted section>"
    assert str(mech) == "<mechanism of deleted section>"
    expect_err("h.sin(0.0, sec=s)")
    expect_err("print(s.L)")
    expect_err("s.L = 100.")
    expect_err("s.nseg")
    expect_err("s.nseg = 5")
    expect_err("print(s.v)")
    expect_err("print(s.orientation())")
    expect_err("s.insert('pas')")
    expect_err("s.insert(h.pas)")
    expect_err("s(.5)")
    expect_err("s(.5).v")
    expect_err("seg.v")
    expect_err("seg._ref_v")
    expect_err("s(.5).v = -65.")
    expect_err("seg.v = -65.")
    expect_err("seg.gnabar_hh")
    expect_err("mech.gnabar")
    expect_err("seg.gnabar_hh = .1")
    expect_err("mech.gnabar = .1")
    expect_err("rvlist[0][0]")
    expect_err("rvlist[0][0] = .1")
    expect_err("for sg in s: pass")
    expect_err("for m in seg: pass")
    expect_err("for r in mech: pass")

    assert s == s
    # See https://github.com/neuronsimulator/nrn/issues/1343
    if sys.version_info >= (3, 8):
        expect_err("dir(s)")
        expect_err("dir(seg)")
        expect_err("dir(mech)")
    assert type(dir(rvlist[0])) == list
    expect_err("help(s)")
    expect_err("help(seg)")
    expect_err("help(mech)")
    help(rvlist[0])  # not an error since it does not access s

    dend = h.Section()
    expect_err("dend.connect(s)")
    expect_err("dend.connect(seg)")

    # Note vref and gnabarref if used may cause segfault or other indeterminate result

    assert ic.get_segment() == None
    assert ic.has_loc() == 0.0
    expect_err("ic.get_loc()")
    expect_err("ic.amp")
    expect_err("ic.amp = .001")
    ic.loc(dend(0.5))
    assert ic.get_segment() == dend(0.5)

    imp = h.Impedance()
    expect_err("imp.loc(seg)")
    expect_err("h.distance(0, seg)")
    expect_hocerr(imp.loc, (seg,))
    expect_hocerr(h.distance, (0, seg))

    del ic, imp, dend
    locals()

    return s, seg, mech, rvlist, vref, gnabarref
Пример #10
0
def test_py2nrnstring():
    print(uni)

    # I don't think h.getstr() can be made to work from python
    # so can't test unicode on stdin read by hoc.
    h("strdef s")
    h('s = "hello"')
    checking("h('getstr(s)')")
    h("getstr(s)")
    "goodbye"
    assert h.s == "hello"

    checking("h(uni + ' = 1')")
    assert h(uni + " = 1") == 0

    # Allowed! The s format for PyArg_ParseTuple specifies that
    # Unicode objects are converted to C strings using 'utf-8' encoding.
    # If this conversion fails, a UnicodeError is raised.
    checking("""h('s = "%s"'%uni)""")
    assert h('s = "%s"' % uni) == 1
    assert h.s == uni

    checking('h.printf("%s", uni)')
    expect_hocerr(h.printf, ("%s", uni))

    checking("hasattr(h, uni)")
    expect_hocerr(hasattr, (h, uni))

    expect_err("h.à = 1")

    expect_err("a = h.à")

    expect_err('a = h.ref("à")')

    ns = h.NetStim()
    # nonsense but it does test the unicode error message
    checking('h.setpointer(ns._ref_start, "à", ns)')
    expect_hocerr(h.setpointer, (ns._ref_start, "à", ns))
    del ns

    # No error for these two (unless cell is involved)!
    checking("s = h.Section(name=uni)")
    s = h.Section(name=uni)
    assert s.name() == uni
    checking("s = h.Section(uni)")
    s = h.Section(uni)
    assert s.name() == uni

    expect_err('h.Section(name="apical", cell=Foo(uni))')

    soma = h.Section()
    expect_err("a = soma.à")

    expect_err("soma.à = 1")

    expect_err("a = soma(.5).à")

    expect_err("soma(.5).à = 1")

    soma.insert("hh")
    expect_err("a = soma(.5).hh.à")

    expect_err("soma(.5).hh.à = 1")