def test_delete_nodespace_unlinks_native_module(test_nodenet, resourcepath):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(None, "foo")
    foopipe = netapi.create_node("Pipe", nodespace.uid, 'foopipe')
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "gatetypes": ["gen", "foo", "bar"]}}')
    with open(nodefunc_file, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")
    micropsi.reload_native_modules()
    testnode = netapi.create_node("Testnode", None, "test")
    netapi.link(testnode, 'foo', foopipe, 'sub')
    netapi.link(foopipe, 'sur', testnode, 'bar')
    micropsi.save_nodenet(test_nodenet)
    # I don't understand why, but this is necessary.
    micropsi.revert_nodenet(test_nodenet)
    netapi.delete_nodespace(nodespace)
    data = netapi.get_node(testnode.uid).get_data(include_links=True)
    assert data['links'] == {}
示例#2
0
def test_unlink_slot(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    node = netapi.create_node("Pipe", None)
    pipe1 = netapi.create_node("Pipe", None)
    pipe2 = netapi.create_node("Pipe", None)
    netapi.link_with_reciprocal(node, pipe1, 'subsur')
    netapi.link_with_reciprocal(node, pipe2, 'subsur')
    netapi.link(pipe1, 'gen', node, 'por')
    netapi.link(pipe2, 'gen', node, 'por')
    netapi.link(pipe1, 'sur', node, 'por')
    micropsi.save_nodenet(test_nodenet)
    netapi.unlink_slot(node, 'por')
    assert node.get_slot('por').empty
    assert not node.get_slot('sur').empty
    micropsi.revert_nodenet(test_nodenet)
    netapi = micropsi.nodenets[test_nodenet].netapi
    node = netapi.get_node(node.uid)
    netapi.unlink_slot(node, 'por', source_node_uid=pipe1.uid)
    assert len(node.get_slot('por').get_links()) == 1
    assert node.get_slot('por').get_links()[0].source_node.uid == pipe2.uid
    micropsi.revert_nodenet(test_nodenet)
    netapi = micropsi.nodenets[test_nodenet].netapi
    node = netapi.get_node(node.uid)
    netapi.unlink_slot(node, 'por', source_gate_name='sur')
    assert len(node.get_slot('por').get_links()) == 2  # pipe1:gen, pipe2:gen
    assert len(node.get_slot('sur').get_links()) == 2  # only sur->por unlinked
示例#3
0
def test_node_parameters_from_persistence(fixed_nodenet, resourcepath):
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "gatetypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "parameters": ["testparam"],\
            "parameter_defaults": {\
                "testparam": 13\
              }\
            }}')
    with open(nodefunc_file, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")
    micropsi.reload_native_modules()
    res, uid = micropsi.add_node(fixed_nodenet, "Testnode", [10, 10, 10], name="Test")
    node = micropsi.nodenets[fixed_nodenet].get_node(uid)
    node.set_parameter("testparam", 42)
    micropsi.save_nodenet(fixed_nodenet)
    micropsi.revert_nodenet(fixed_nodenet)
    node = micropsi.nodenets[fixed_nodenet].get_node(uid)
    assert node.get_parameter("testparam") == 42
def test_grow_partitions(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(None, name="partition", options={
        "new_partition": True,
        "initial_number_of_nodes": 2,
        "average_elements_per_node_assumption": 4,
        "initial_number_of_nodespaces": 1
    })

    for i in range(20):
        netapi.create_node("Pipe", nodespace.uid, "N %d" % i)

    partition = nodespace.partition

    # growby (NoN // 2): 2,3,4,6,9,13,19,28
    assert len(partition.allocated_nodes) == 28
    assert partition.NoE > 28 * 4

    for i in range(2):
        netapi.create_nodespace(nodespace.uid, name="NS %d" % i)

    assert len(partition.allocated_nodespaces) == 4

    # step, save, and load the net to make sure all data structures have been grown properly
    micropsi.step_nodenet(test_nodenet)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    micropsi.step_nodenet(test_nodenet)
示例#5
0
def fixed_nodenet(request, test_world, engine):
    """
    A test nodenet filled with some example data (nodenet_data.py)
    Structure:

          ->  A1 ->  A2
        /
       S                     ACTA
        \
          ->  B1 ->  B2

    S: Sensor, brightness_l
    A1: Pipe
    A2: Pipe
    B1: Pipe
    B2: Pipe
    ACTA: Activator, por
    """
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    if engine == "theano_engine":
        fixed_nodenet_data = fixed_nodenet_data.replace('Root', 's0001')
    success, uid = micropsi.new_nodenet("Fixednet",
                                        engine=engine,
                                        worldadapter="Braitenberg",
                                        owner="Pytest User",
                                        world_uid=test_world,
                                        uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)
    yield uid
    try:
        micropsi.delete_nodenet(uid)
    except:
        pass
示例#6
0
def test_unlink_slot(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    node = netapi.create_node("Pipe", None)
    pipe1 = netapi.create_node("Pipe", None)
    pipe2 = netapi.create_node("Pipe", None)
    netapi.link_with_reciprocal(node, pipe1, 'subsur')
    netapi.link_with_reciprocal(node, pipe2, 'subsur')
    netapi.link(pipe1, 'gen', node, 'por')
    netapi.link(pipe2, 'gen', node, 'por')
    netapi.link(pipe1, 'sur', node, 'por')
    micropsi.save_nodenet(test_nodenet)
    netapi.unlink_slot(node, 'por')
    assert node.get_slot('por').empty
    assert not node.get_slot('sur').empty
    micropsi.revert_nodenet(test_nodenet)
    netapi = micropsi.nodenets[test_nodenet].netapi
    node = netapi.get_node(node.uid)
    netapi.unlink_slot(node, 'por', source_node_uid=pipe1.uid)
    assert len(node.get_slot('por').get_links()) == 1
    assert node.get_slot('por').get_links()[0].source_node.uid == pipe2.uid
    micropsi.revert_nodenet(test_nodenet)
    netapi = micropsi.nodenets[test_nodenet].netapi
    node = netapi.get_node(node.uid)
    netapi.unlink_slot(node, 'por', source_gate_name='sur')
    assert len(node.get_slot('por').get_links()) == 2  # pipe1:gen, pipe2:gen
    assert len(node.get_slot('sur').get_links()) == 2  # only sur->por unlinked
示例#7
0
def fixed_nodenet(request, test_world, engine):
    """
    A test nodenet filled with some example data (nodenet_data.py)
    Structure:

          ->  A1 ->  A2
        /
       S                     ACTA
        \
          ->  B1 ->  B2

    S: Sensor, brightness_l
    A1: Pipe
    A2: Pipe
    B1: Pipe
    B2: Pipe
    ACTA: Activator, por
    """
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    if engine == "theano_engine":
        fixed_nodenet_data = fixed_nodenet_data.replace('Root', 's0001')
    success, uid = micropsi.new_nodenet("Fixednet", engine=engine, worldadapter="Braitenberg", owner="Pytest User", world_uid=test_world, uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)
    yield uid
    try:
        micropsi.delete_nodenet(uid)
    except:
        pass
示例#8
0
def test_autoalign_operation(test_nodenet):
    ops = runtime.get_available_operations()
    for selectioninfo in ops['autoalign']['selection']:
        if selectioninfo['nodetypes'] == ['Nodespace']:
            assert selectioninfo['mincount'] == 1
            assert selectioninfo['maxcount'] == -1
        else:
            assert selectioninfo['mincount'] == 2
            assert selectioninfo['maxcount'] == -1
            assert selectioninfo['nodetypes'] == []
    assert ops['autoalign']['category'] == 'layout'
    assert ops['autoalign']['parameters'] == []

    api = runtime.nodenets[test_nodenet].netapi
    ns1 = api.create_nodespace(None, "foo")
    p1 = api.create_node("Pipe", None, "p1")
    p2 = api.create_node("Pipe", None, "p2")
    p3 = api.create_node("Pipe", None, "p3")
    api.link_with_reciprocal(p1, p2, 'subsur')
    api.link_with_reciprocal(p1, p3, 'subsur')
    api.link_with_reciprocal(p2, p3, 'porret')
    runtime.save_nodenet(test_nodenet)
    runtime.run_operation(test_nodenet, "autoalign", {}, [p1.uid, p2.uid, p3.uid, ns1])
    assert p1.position[0] == p2.position[0]
    assert p1.position[1] < p2.position[1]
    assert p2.position[1] == p3.position[1]
    runtime.revert_nodenet(test_nodenet)
    runtime.run_operation(test_nodenet, "autoalign", {}, [api.get_nodespace(None).uid])
    assert p1.position[0] == p2.position[0]
    assert p1.position[1] < p2.position[1]
    assert p2.position[1] == p3.position[1]
    result, data = runtime.run_operation(test_nodenet, "autoalign", {}, [p1.uid])
    assert 'error' in data
示例#9
0
def test_delete_nodespace_unlinks_native_module(test_nodenet, resourcepath):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(None, "foo")
    foopipe = netapi.create_node("Pipe", nodespace.uid, 'foopipe')
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "gatetypes": ["gen", "foo", "bar"]}}')
    with open(nodefunc_file, 'w') as fp:
        fp.write(
            "def testnodefunc(netapi, node=None, **prams):\r\n    return 17")
    micropsi.reload_native_modules()
    testnode = netapi.create_node("Testnode", None, "test")
    netapi.link(testnode, 'foo', foopipe, 'sub')
    netapi.link(foopipe, 'sur', testnode, 'bar')
    micropsi.save_nodenet(test_nodenet)
    # I don't understand why, but this is necessary.
    micropsi.revert_nodenet(test_nodenet)
    netapi.delete_nodespace(nodespace)
    data = netapi.get_node(testnode.uid).get_data(include_links=True)
    assert data['links'] == {}
示例#10
0
def test_nodenet(request, test_world, engine):
    global nn_uid
    nodenets = micropsi.get_available_nodenets("Pytest User") or {}
    if nn_uid not in nodenets:
        success, nn_uid = micropsi.new_nodenet("Testnet", engine=engine, owner="Pytest User", uid='Testnet')
        micropsi.save_nodenet(nn_uid)
    return nn_uid
示例#11
0
def test_grow_partitions(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(
        None,
        name="partition",
        options={
            "new_partition": True,
            "initial_number_of_nodes": 2,
            "average_elements_per_node_assumption": 4,
            "initial_number_of_nodespaces": 1
        })

    for i in range(20):
        netapi.create_node("Pipe", nodespace.uid, "N %d" % i)

    partition = nodespace.partition

    # growby (NoN // 2): 2,3,4,6,9,13,19,28
    assert len(partition.allocated_nodes) == 28
    assert partition.NoE > 28 * 4

    for i in range(2):
        netapi.create_nodespace(nodespace.uid, name="NS %d" % i)

    assert len(partition.allocated_nodespaces) == 4

    # step, save, and load the net to make sure all data structures have been grown properly
    micropsi.step_nodenet(test_nodenet)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    micropsi.step_nodenet(test_nodenet)
示例#12
0
def test_autoalign_operation(test_nodenet):
    ops = runtime.get_available_operations()
    assert ops['autoalign']['selection']['nodetypes'] == []
    assert ops['autoalign']['selection']['mincount'] == 1
    assert ops['autoalign']['selection']['maxcount'] == -1
    assert ops['autoalign']['category'] == 'layout'
    assert ops['autoalign']['parameters'] == []

    api = runtime.nodenets[test_nodenet].netapi
    ns1 = api.create_nodespace(None, "foo")
    p1 = api.create_node("Pipe", None, "p1")
    p2 = api.create_node("Pipe", None, "p2")
    p3 = api.create_node("Pipe", None, "p3")
    api.link_with_reciprocal(p1, p2, 'subsur')
    api.link_with_reciprocal(p1, p3, 'subsur')
    api.link_with_reciprocal(p2, p3, 'porret')
    runtime.save_nodenet(test_nodenet)
    runtime.run_operation(test_nodenet, "autoalign", {},
                          [p1.uid, p2.uid, p3.uid, ns1])
    assert p1.position[0] == p2.position[0]
    assert p1.position[1] < p2.position[1]
    assert p2.position[1] == p3.position[1]
    runtime.revert_nodenet(test_nodenet)
    runtime.run_operation(test_nodenet, "autoalign", {},
                          [api.get_nodespace(None).uid])
    assert p1.position[0] == p2.position[0]
    assert p1.position[1] < p2.position[1]
    assert p2.position[1] == p3.position[1]
    result, data = runtime.run_operation(test_nodenet, "autoalign", {},
                                         [p1.uid])
    assert 'error' in data
示例#13
0
def save_all_nodenets():
    user_id, permissions, token = get_request_data()
    if "manage nodenets" in permissions:
        for uid in runtime.nodenets:
            runtime.save_nodenet(uid)
        response.set_cookie('notification', '{"msg":"All nodenets saved", "status":"success"}', path='/')
        redirect('/nodenet_mgt')
    return template("error", msg="Insufficient rights to access nodenet console")
示例#14
0
def test_worldadapter_update_config(default_world, default_nodenet):
    runtime.set_nodenet_properties(default_nodenet, worldadapter="Default", world_uid=default_world)
    runtime.save_nodenet(default_nodenet)
    assert runtime.nodenets[default_nodenet].worldadapter_instance.foo == 'bar'
    runtime.set_nodenet_properties(default_nodenet, worldadapter="Default", world_uid=default_world, worldadapter_config={'foo': 'changed'})
    assert runtime.nodenets[default_nodenet].worldadapter_instance.foo == 'changed'
    assert runtime.nodenets[default_nodenet].worldadapter_instance.config['foo'] == 'changed'
    assert runtime.worlds[default_world].agents[default_nodenet].foo == 'changed'
示例#15
0
def test_partition_persistence(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace, source, register = prepare(netapi)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    nodenet.step()
    assert register.activation == 1
def test_partition_persistence(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace, source, register = prepare(netapi)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    nodenet.step()
    assert register.activation == 1
示例#17
0
def fixed_nodenet(request, test_world, engine):
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    if engine == "theano_engine":
        fixed_nodenet_data = fixed_nodenet_data.replace('Root', 's0001')
    success, uid = micropsi.new_nodenet("Fixednet", engine=engine, worldadapter="Braitenberg", owner="Pytest User", world_uid=test_world, uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)
    return uid
示例#18
0
def test_nodenet(request, test_world, engine):
    global nn_uid
    nodenets = micropsi.get_available_nodenets("Pytest User") or {}
    if nn_uid not in nodenets:
        success, nn_uid = micropsi.new_nodenet("Testnet",
                                               engine=engine,
                                               owner="Pytest User",
                                               uid='Testnet')
        micropsi.save_nodenet(nn_uid)
    return nn_uid
def test_nodespace_properties(test_nodenet):
    data = {'testvalue': 'foobar'}
    rootns = micropsi.get_nodenet(test_nodenet).get_nodespace(None)
    micropsi.set_nodespace_properties(test_nodenet, rootns.uid, data)
    assert micropsi.nodenets[test_nodenet].metadata['nodespace_ui_properties'][rootns.uid] == data
    assert micropsi.get_nodespace_properties(test_nodenet, rootns.uid) == data
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    assert micropsi.get_nodespace_properties(test_nodenet, rootns.uid) == data
    properties = micropsi.get_nodespace_properties(test_nodenet)
    assert properties[rootns.uid] == data
示例#20
0
def test_nodenet(request, test_world, engine):
    """
    Fixture: A completely empty nodenet without a worldadapter
    """
    global nn_uid
    success, nn_uid = micropsi.new_nodenet("Testnet", engine=engine, owner="Pytest User", uid='Testnet')
    micropsi.save_nodenet(nn_uid)
    yield nn_uid
    try:
        micropsi.delete_nodenet(nn_uid)
    except:
        pass
示例#21
0
def test_nodespace_properties(test_nodenet):
    data = {'testvalue': 'foobar'}
    rootns = micropsi.get_nodenet(test_nodenet).get_nodespace(None)
    micropsi.set_nodespace_properties(test_nodenet, rootns.uid, data)
    assert micropsi.nodenets[test_nodenet].metadata['nodespace_ui_properties'][
        rootns.uid] == data
    assert micropsi.get_nodespace_properties(test_nodenet, rootns.uid) == data
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    assert micropsi.get_nodespace_properties(test_nodenet, rootns.uid) == data
    properties = micropsi.get_nodespace_properties(test_nodenet)
    assert properties[rootns.uid] == data
示例#22
0
def default_nodenet(request):
    """
    A nodenet with the default engine
    Use this for tests that are engine-agnostic
    """
    success, nn_uid = micropsi_runtime.new_nodenet("Defaultnet", owner="Pytest User")
    micropsi_runtime.save_nodenet(nn_uid)
    yield nn_uid
    try:
        micropsi_runtime.delete_nodenet(nn_uid)
    except:
        pass
示例#23
0
def test_nodenet(request, default_world, engine):
    """
    An empty nodenet, with the currently tested engine.
    Use this for tests that should run in both engines
    """
    global nn_uid
    success, nn_uid = micropsi_runtime.new_nodenet("Testnet", engine=engine, owner="Pytest User")
    micropsi_runtime.save_nodenet(nn_uid)
    yield nn_uid
    try:
        micropsi_runtime.delete_nodenet(nn_uid)
    except:
        pass
示例#24
0
def test_nodenet(request):
    global nn_uid
    nodenets = micropsi.get_available_nodenets("Pytest User") or {}
    if nn_uid not in nodenets:
        success, nn_uid = micropsi.new_nodenet("Testnet", worldadapter="Default", owner="Pytest User", world_uid=world_uid, uid='Testnet')
        micropsi.add_node(nn_uid, 'Concept', [10, 10], uid='N1', name='N1')
        micropsi.add_link(nn_uid, 'N1', 'gen', 'N1', 'gen')
        micropsi.save_nodenet(nn_uid)

    def fin():
            micropsi.revert_nodenet(nn_uid)
    request.addfinalizer(fin)
    return nn_uid
示例#25
0
def fixed_nodenet(request, test_world, engine):
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    if engine == "theano_engine":
        fixed_nodenet_data = fixed_nodenet_data.replace('Root', 's0001')
    success, uid = micropsi.new_nodenet("Fixednet",
                                        engine=engine,
                                        worldadapter="Braitenberg",
                                        owner="Pytest User",
                                        world_uid=test_world,
                                        uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)
    return uid
def test_save_nodenet(test_nodenet):
    # save_nodenet
    micropsi.save_nodenet(test_nodenet)
    # unload_nodenet
    micropsi.unload_nodenet(test_nodenet)
    try:
        micropsi.get_nodespace(test_nodenet, "Root", -1)
        assert False, "could fetch a Nodespace that should not have been in memory"
    except:
        pass
    # load_nodenet
    micropsi.load_nodenet(test_nodenet)
    nodespace = micropsi.get_nodespace(test_nodenet, "Root", -1)
    assert len(nodespace["nodes"]) == 4
示例#27
0
def fixed_nodenet(request, test_world):
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    success, uid = micropsi.new_nodenet("Fixednet", worldadapter="Braitenberg", owner="Pytest User", world_uid=test_world, uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)

    def fin():
        if DELETE_TEST_FILES_ON_EXIT:
            try:
                micropsi.delete_nodenet(uid)
            except:
                pass
    request.addfinalizer(fin)
    return uid
示例#28
0
def test_node_parameters(fixed_nodenet, resourcepath):
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "gatetypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "parameters": ["linktype", "threshold", "protocol_mode"],\
            "parameter_values": {\
                "linktype": ["catexp", "subsur"],\
                "protocol_mode": ["all_active", "most_active_one"]\
            },\
            "parameter_defaults": {\
                "linktype": "catexp",\
                "protocol_mode": "all_active"\
            }}\
        }')
    with open(nodefunc_file, 'w') as fp:
        fp.write(
            "def testnodefunc(netapi, node=None, **prams):\r\n    return 17")

    assert micropsi.reload_native_modules()
    res, uid = micropsi.add_node(fixed_nodenet,
                                 "Testnode", [10, 10],
                                 name="Test",
                                 parameters={
                                     "linktype": "catexp",
                                     "threshold": "",
                                     "protocol_mode": "all_active"
                                 })
    # nativemodule = micropsi.nodenets[fixed_nodenet].get_node(uid)
    assert micropsi.save_nodenet(fixed_nodenet)
示例#29
0
def test_save_nodenet(test_nodenet):
    prepare_nodenet(test_nodenet)
    # save_nodenet
    micropsi.save_nodenet(test_nodenet)
    # unload_nodenet
    micropsi.unload_nodenet(test_nodenet)
    try:
        micropsi.get_nodenet_data(test_nodenet, None)
        assert False, "could fetch a Nodespace that should not have been in memory"
    except:
        pass
    # load_nodenet
    micropsi.load_nodenet(test_nodenet)
    nodespace = micropsi.get_nodenet_data(test_nodenet, None)
    assert len(nodespace["nodes"]) == 4
    micropsi.delete_nodenet(test_nodenet)
def test_node_parameters(fixed_nodenet, resourcepath):
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "gatetypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "parameters": ["linktype", "threshold", "protocol_mode"],\
            "parameter_values": {\
                "linktype": ["catexp", "subsur"],\
                "protocol_mode": ["all_active", "most_active_one"]\
            },\
            "parameter_defaults": {\
                "linktype": "catexp",\
                "protocol_mode": "all_active"\
            }}\
        }')
    with open(nodefunc_file, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")

    assert micropsi.reload_native_modules()
    res, uid = micropsi.add_node(fixed_nodenet, "Testnode", [10, 10], name="Test", parameters={"linktype": "catexp", "threshold": "", "protocol_mode": "all_active"})
    # nativemodule = micropsi.nodenets[fixed_nodenet].get_node(uid)
    assert micropsi.save_nodenet(fixed_nodenet)
示例#31
0
def test_create_nodenet_from_template(test_nodenet, node, engine):
    mode = micropsi.cfg['micropsi2'].get('single_agent_mode')
    micropsi.cfg['micropsi2'].update({'single_agent_mode': '1'})
    api = micropsi.nodenets[test_nodenet].netapi
    node1 = api.get_node(node)
    node2 = api.create_node("Register", None, "node2")
    api.link(node1, 'gen', node2, 'gen')
    micropsi.save_nodenet(test_nodenet)
    result, uid = micropsi.new_nodenet('copynet', engine=engine, template=test_nodenet)
    data = micropsi.get_nodes(uid)
    for uid, n in data['nodes'].items():
        if n['name'] == node1.name:
            assert len(n['links']['gen']) == 2
        else:
            assert n['name'] == node2.name
    micropsi.cfg['micropsi2'].update({'single_agent_mode': mode})
示例#32
0
def test_create_nodenet_from_template(test_nodenet, node, engine):
    mode = micropsi.cfg['micropsi2'].get('single_agent_mode')
    micropsi.cfg['micropsi2'].update({'single_agent_mode': '1'})
    api = micropsi.nodenets[test_nodenet].netapi
    node1 = api.get_node(node)
    node2 = api.create_node("Register", None, "node2")
    api.link(node1, 'gen', node2, 'gen')
    micropsi.save_nodenet(test_nodenet)
    result, uid = micropsi.new_nodenet('copynet',
                                       engine=engine,
                                       template=test_nodenet)
    data = micropsi.get_nodes(uid)
    for uid, n in data['nodes'].items():
        if n['name'] == node1.name:
            assert len(n['links']['gen']) == 2
        else:
            assert n['name'] == node2.name
    micropsi.cfg['micropsi2'].update({'single_agent_mode': mode})
示例#33
0
def test_runner_condition_persists(test_nodenet):
    micropsi.set_runner_condition(test_nodenet, steps=7)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    assert micropsi.nodenets[test_nodenet].get_runner_condition()['step'] == 7
示例#34
0
def test_runner_condition_persists(test_nodenet):
    micropsi.set_runner_condition(test_nodenet, steps=7)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    assert micropsi.nodenets[test_nodenet].get_runner_condition()['step'] == 7
示例#35
0
def save_nodenet(nodenet_uid):
    """ Persist the current state of the nodenet"""
    return runtime.save_nodenet(nodenet_uid)
示例#36
0
def save_nodenet(nodenet_uid):
    return runtime.save_nodenet(nodenet_uid)
def test_copy_nodes():
    success, nodenet_uid1 = micropsi.new_nodenet("Origin_Nodenet", "Default", owner="tester")
    success, nodenet_uid2 = micropsi.new_nodenet("Target_Nodenet", "Default", owner="tester")

    # create a few nodes
    assert nodenet_uid1 not in micropsi.nodenets
    micropsi.load_nodenet(nodenet_uid1)
    assert nodenet_uid1 in micropsi.nodenets
    micropsi.load_nodenet(nodenet_uid2)
    assert nodenet_uid1 in micropsi.nodenets
    assert nodenet_uid2 in micropsi.nodenets

    micropsi.add_node(nodenet_uid1, "Nodespace", (100, 150), "Root", uid="ns1")
    micropsi.add_node(nodenet_uid1, "Nodespace", (200, 150), "Root", uid="confl")
    micropsi.add_node(nodenet_uid1, "Nodespace", (400, 150), "Root", uid="ns2")
    micropsi.add_node(nodenet_uid2, "Nodespace", (200, 150), "Root", uid="confl")

    micropsi.add_node(nodenet_uid1, "Register", (300, 140), "Root", uid="n1")
    micropsi.add_node(nodenet_uid1, "Register", (300, 240), "Root", uid="n2")
    micropsi.add_node(nodenet_uid1, "Register", (300, 340), "Root", uid="associated_node")
    micropsi.add_node(nodenet_uid1, "Register", (400, 240), "ns1", uid="n3")
    micropsi.add_node(nodenet_uid1, "Register", (400, 240), "ns2", uid="n4")
    micropsi.add_node(nodenet_uid1, "Register", (100, 240), "confl", uid="n5")
    micropsi.add_node(nodenet_uid2, "Register", (100, 140), "Root", uid="n1")
    micropsi.add_node(nodenet_uid2, "Register", (150, 240), "Root", uid="nt2")

    micropsi.add_link(nodenet_uid1, "n1", "gen", "n2", "gen", uid="l1")
    micropsi.add_link(nodenet_uid1, "n2", "gen", "n3", "gen", uid="l2")
    micropsi.add_link(nodenet_uid1, "n1", "gen", "associated_node", "gen", uid="la")
    micropsi.add_link(nodenet_uid1, "n3", "gen", "n1", "gen", uid="l3")
    micropsi.add_link(nodenet_uid1, "n4", "gen", "n1", "gen", uid="l4")
    micropsi.add_link(nodenet_uid2, "n1", "gen", "nt2", "gen", uid="l1")

    # now copy stuff between nodespaces
    micropsi.copy_nodes( ["n1", "n2", "n3", "n5", "ns1", "confl"], nodenet_uid1, nodenet_uid2)

    micropsi.save_nodenet(nodenet_uid1)
    micropsi.save_nodenet(nodenet_uid2)

    target = micropsi.get_nodespace(nodenet_uid2, "Root", -1)
    assert len(target["nodes"]) == 4 + 2
    assert len(target["nodespaces"]) == 2 + 2

    assert "n1" in target["nodes"]
    assert "n2" in target["nodes"]
    assert "n3" in target["nodes"]
    assert "associated_node" not in target["nodes"]
    assert "n4" not in target["nodes"]
    assert "n5" in target["nodes"]
    assert "nt2" in target["nodes"]

    assert "ns1" in target["nodespaces"]
    assert "ns2" not in target["nodespaces"]
    assert "confl" in target["nodespaces"]

    assert len(target["links"]) == 3 + 1
    assert "l1" in target["links"]
    assert "l2" in target["links"]
    assert "l3" in target["links"]
    assert "l4" not in target["links"]

    # we should also test for parentage and link connectivity


    # TODO now test copying within the same nodenet

    micropsi.copy_nodes( ["n1", "n2", "n3", "n5", "ns1", "confl"], nodenet_uid1, nodenet_uid1, target_nodespace_uid="ns2" )
    micropsi.save_nodenet(nodenet_uid1)
    # delete_nodenets
    micropsi.delete_nodenet(nodenet_uid1)
    micropsi.delete_nodenet(nodenet_uid2)