Example #1
0
def test_get_nodespace_changes(fixed_nodenet):
    net = micropsi.nodenets[fixed_nodenet]
    net.step()
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 0)
    assert set(result['nodes_dirty'].keys()) == set(net.get_node_uids())
    assert result['nodes_deleted'] == []
    assert result['nodespaces_dirty'] == {}
    assert result['nodespaces_deleted'] == []
    nodes = {}
    for n in net.netapi.get_nodes():
        nodes[n.name] = n
    net.netapi.unlink(nodes['A1'], 'por', nodes['A2'], 'gen')
    net.netapi.delete_node(nodes['B2'])
    newnode = net.netapi.create_node('Pipe', None, "asdf")
    net.netapi.link(newnode, 'gen', nodes['B1'], 'gen')
    newspace = net.netapi.create_nodespace(None, "nodespace")
    net.step()
    test = micropsi.get_nodenet_activation_data(fixed_nodenet, [None], 1)
    assert test['has_changes']
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 1)
    assert nodes['B2'].uid in result['nodes_deleted']
    assert nodes['A1'].uid in result['nodes_dirty']
    assert nodes['A2'].uid in result['nodes_dirty']
    assert result['nodes_dirty'][nodes['A1'].uid]['links'] == {}
    assert newnode.uid in result['nodes_dirty']
    assert len(result['nodes_dirty'][newnode.uid]['links']['gen']) == 1
    assert newspace.uid in result['nodespaces_dirty']
    assert len(result['nodes_dirty'].keys()) == 4
    assert len(result['nodespaces_dirty'].keys()) == 1
    net.step()
    test = micropsi.get_nodenet_activation_data(fixed_nodenet, [None], 2)
    assert not test['has_changes']
def test_get_nodespace_changes(fixed_nodenet):
    net = micropsi.nodenets[fixed_nodenet]
    net.step()
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 0)
    assert set(result['nodes_dirty'].keys()) == set(net.get_node_uids())
    assert result['nodes_deleted'] == []
    assert result['nodespaces_dirty'] == {}
    assert result['nodespaces_deleted'] == []
    nodes = {}
    for n in net.netapi.get_nodes():
        nodes[n.name] = n
    net.netapi.unlink(nodes['A1'], 'por', nodes['A2'], 'gen')
    net.netapi.delete_node(nodes['B2'])
    newnode = net.netapi.create_node('Pipe', None, "asdf")
    net.netapi.link(newnode, 'gen', nodes['B1'], 'gen')
    newspace = net.netapi.create_nodespace(None, "nodespace")
    net.step()
    test = micropsi.get_nodenet_activation_data(fixed_nodenet, [None], 1)
    assert test['has_changes']
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 1)
    assert nodes['B2'].uid in result['nodes_deleted']
    assert nodes['A1'].uid in result['nodes_dirty']
    assert nodes['A2'].uid in result['nodes_dirty']
    assert result['nodes_dirty'][nodes['A1'].uid]['links'] == {}
    assert newnode.uid in result['nodes_dirty']
    assert len(result['nodes_dirty'][newnode.uid]['links']['gen']) == 1
    assert newspace.uid in result['nodespaces_dirty']
    assert len(result['nodes_dirty'].keys()) == 4
    assert len(result['nodespaces_dirty'].keys()) == 1
    net.step()
    test = micropsi.get_nodenet_activation_data(fixed_nodenet, [None], 2)
    assert not test['has_changes']
Example #3
0
def test_get_nodespace_changes_cycles(fixed_nodenet):
    net = micropsi.nodenets[fixed_nodenet]
    net.step()
    nodes = {}
    for n in net.netapi.get_nodes():
        nodes[n.name] = n
    net.netapi.delete_node(nodes['B2'])
    net.step()
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 1)
    assert nodes['B2'].uid in result['nodes_deleted']
    for i in range(101):
        net.step()
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 1)
    assert nodes['B2'].uid not in result['nodes_deleted']
def test_get_nodespace_changes_cycles(fixed_nodenet):
    net = micropsi.nodenets[fixed_nodenet]
    net.step()
    nodes = {}
    for n in net.netapi.get_nodes():
        nodes[n.name] = n
    net.netapi.delete_node(nodes['B2'])
    net.step()
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 1)
    assert nodes['B2'].uid in result['nodes_deleted']
    for i in range(101):
        net.step()
    result = micropsi.get_nodespace_changes(fixed_nodenet, [None], 1)
    assert nodes['B2'].uid not in result['nodes_deleted']
Example #5
0
def get_nodenet_changes(nodenet_uid, nodespaces=[], since_step=0):
    """ Return a diff of the nodenets state between the given since_step and the current state. optionally filtered by nodespaces"""
    data = runtime.get_nodenet_activation_data(nodenet_uid, nodespaces=nodespaces, last_call_step=int(since_step))
    if data['has_changes']:
        data['changes'] = runtime.get_nodespace_changes(nodenet_uid, nodespaces=nodespaces, since_step=int(since_step))
    else:
        data['changes'] = {}
    return True, data
Example #6
0
def get_nodespace_changes(nodenet_uid, nodespaces, since_step):
    return runtime.get_nodespace_changes(nodenet_uid, nodespaces, since_step)