Esempio n. 1
0
def test_register_runner_condition_step(test_nodenet):
    import time
    success, data = micropsi.set_runner_condition(test_nodenet, steps=7)
    assert data['step'] == 7
    assert data['step_amount'] == 7
    micropsi.start_nodenetrunner(test_nodenet)
    assert micropsi.nodenets[test_nodenet].is_active
    time.sleep(1)
    assert micropsi.nodenets[test_nodenet].current_step == 7
    assert not micropsi.nodenets[test_nodenet].is_active
    # test that the condition stays active.
    micropsi.start_nodenetrunner(test_nodenet)
    assert micropsi.nodenets[test_nodenet].is_active
    time.sleep(1)
    assert micropsi.nodenets[test_nodenet].current_step == 14
    assert not micropsi.nodenets[test_nodenet].is_active
Esempio n. 2
0
def test_register_runner_condition_step(test_nodenet):
    import time
    success, data = micropsi.set_runner_condition(test_nodenet, steps=7)
    assert data['step'] == 7
    assert data['step_amount'] == 7
    micropsi.start_nodenetrunner(test_nodenet)
    assert micropsi.nodenets[test_nodenet].is_active
    time.sleep(1)
    assert micropsi.nodenets[test_nodenet].current_step == 7
    assert not micropsi.nodenets[test_nodenet].is_active
    # test that the condition stays active.
    micropsi.start_nodenetrunner(test_nodenet)
    assert micropsi.nodenets[test_nodenet].is_active
    time.sleep(1)
    assert micropsi.nodenets[test_nodenet].current_step == 14
    assert not micropsi.nodenets[test_nodenet].is_active
Esempio n. 3
0
def test_register_runner_condition_monitor(test_nodenet):
    import time
    nn = micropsi.nodenets[test_nodenet]
    node = nn.netapi.create_node('Register', None)
    nn.netapi.link(node, 'gen', node, 'gen', weight=2)
    node.activation = 0.1
    uid = micropsi.add_gate_monitor(test_nodenet, node.uid, 'gen')
    micropsi.set_runner_condition(test_nodenet, monitor={
        'uid': uid,
        'value': 0.8
    })
    micropsi.start_nodenetrunner(test_nodenet)
    assert micropsi.nodenets[test_nodenet].is_active
    time.sleep(1)
    assert not micropsi.nodenets[test_nodenet].is_active
    assert micropsi.nodenets[test_nodenet].current_step == 3
    assert round(nn.get_node(node.uid).get_gate('gen').activation, 4) == 0.8
Esempio n. 4
0
def test_register_runner_condition_monitor(test_nodenet):
    import time
    nn = micropsi.nodenets[test_nodenet]
    node = nn.netapi.create_node('Register', None)
    nn.netapi.link(node, 'gen', node, 'gen', weight=2)
    node.activation = 0.1
    uid = micropsi.add_gate_monitor(test_nodenet, node.uid, 'gen')
    micropsi.set_runner_condition(test_nodenet,
                                  monitor={
                                      'uid': uid,
                                      'value': 0.8
                                  })
    micropsi.start_nodenetrunner(test_nodenet)
    assert micropsi.nodenets[test_nodenet].is_active
    time.sleep(1)
    assert not micropsi.nodenets[test_nodenet].is_active
    assert micropsi.nodenets[test_nodenet].current_step == 3
    assert round(nn.get_node(node.uid).get_gate('gen').activation, 4) == 0.8
Esempio n. 5
0
def test_plot_from_nodefunc(test_nodenet, resourcepath):
    import os
    from random import random
    from time import sleep
    nodenet = micropsi.get_nodenet(test_nodenet)
    vizapi = nodenet.netapi.vizapi
    activations = [random() for i in range(256)]
    plot = vizapi.NodenetPlot(plotsize=(2, 2))
    plot.add_activation_plot(activations)
    filepath = os.path.join(resourcepath, "plot.png")
    returnpath = plot.save_to_file(filepath)
    assert os.path.abspath(returnpath) == os.path.abspath(filepath)
    assert os.path.isfile(filepath)
    os.remove(filepath)
    os.mkdir(os.path.join(resourcepath, 'plotter'))
    nodetype_file = os.path.join(resourcepath, "plotter", "nodetypes.json")
    nodefunc_file = os.path.join(resourcepath, "plotter", "nodefunctions.py")
    with open(nodetype_file, 'w') as fp:
        fp.write("""{"Plotter": {
            "name": "Plotter",
            "slottypes": [],
            "nodefunction_name": "plotfunc",
            "gatetypes": [],
            "parameters": ["plotpath"]}}""")
    with open(nodefunc_file, 'w') as fp:
        fp.write("""
def plotfunc(netapi, node=None, **params):
    import os
    from random import random
    filepath = os.path.join(params['plotpath'], 'plot.png')
    activations = [random() for i in range(256)]
    plot = netapi.vizapi.NodenetPlot(plotsize=(2, 2))
    plot.add_activation_plot(activations)
    plot.save_to_file(filepath)
""")
    micropsi.reload_native_modules()
    node = nodenet.netapi.create_node("Plotter", None, name="Plotter")
    node.set_parameter("plotpath", resourcepath)
    micropsi.start_nodenetrunner(test_nodenet)
    sleep(2)
    micropsi.stop_nodenetrunner(test_nodenet)
    assert micropsi.MicropsiRunner.last_nodenet_exception == {}
    assert os.path.isfile(os.path.join(resourcepath, "plot.png"))
Esempio n. 6
0
def test_plot_from_nodefunc(test_nodenet, resourcepath):
    import os
    from random import random
    from time import sleep
    nodenet = micropsi.get_nodenet(test_nodenet)
    vizapi = nodenet.netapi.vizapi
    activations = [random() for i in range(256)]
    plot = vizapi.NodenetPlot(plotsize=(2, 2))
    plot.add_activation_plot(activations)
    filepath = os.path.join(resourcepath, "plot.png")
    returnpath = plot.save_to_file(filepath)
    assert os.path.abspath(returnpath) == os.path.abspath(filepath)
    assert os.path.isfile(filepath)
    os.remove(filepath)
    os.mkdir(os.path.join(resourcepath, 'plotter'))
    nodetype_file = os.path.join(resourcepath, "plotter", "nodetypes.json")
    nodefunc_file = os.path.join(resourcepath, "plotter", "nodefunctions.py")
    with open(nodetype_file, 'w') as fp:
        fp.write("""{"Plotter": {
            "name": "Plotter",
            "slottypes": [],
            "nodefunction_name": "plotfunc",
            "gatetypes": [],
            "parameters": ["plotpath"]}}""")
    with open(nodefunc_file, 'w') as fp:
        fp.write("""
def plotfunc(netapi, node=None, **params):
    import os
    from random import random
    filepath = os.path.join(params['plotpath'], 'plot.png')
    activations = [random() for i in range(256)]
    plot = netapi.vizapi.NodenetPlot(plotsize=(2, 2))
    plot.add_activation_plot(activations)
    plot.save_to_file(filepath)
""")
    micropsi.reload_native_modules()
    node = nodenet.netapi.create_node("Plotter", None, name="Plotter")
    node.set_parameter("plotpath", resourcepath)
    micropsi.start_nodenetrunner(test_nodenet)
    sleep(2)
    micropsi.stop_nodenetrunner(test_nodenet)
    assert micropsi.MicropsiRunner.last_nodenet_exception == {}
    assert os.path.isfile(os.path.join(resourcepath, "plot.png"))
Esempio n. 7
0
def start_calculation(nodenet_uid):
    return runtime.start_nodenetrunner(nodenet_uid)
Esempio n. 8
0
def start_nodenetrunner(nodenet_uid):
    return runtime.start_nodenetrunner(nodenet_uid)
Esempio n. 9
0
def start_calculation(nodenet_uid):
    """ Start the runner of the given nodenet """
    return runtime.start_nodenetrunner(nodenet_uid)