示例#1
0
def edit_runner_properties():
    user_id, permissions, token = get_request_data()
    if len(request.params) > 0:
        runtime.set_runner_properties(int(request.params['timestep']), int(request.params['factor']))
        return dict(status="success", msg="Settings saved")
    else:
        return template("runner_form", action="/config/runner", value=runtime.get_runner_properties())
示例#2
0
def pytest_cmdline_main(config):
    """ called for performing the main command line action. The default
    implementation will invoke the configure hooks and runtest_mainloop. """
    if config.getoption('agents'):
        config.args = [orig_agent_dir]
        config._inicache['python_functions'] = []
        config.addinivalue_line('norecursedirs', 'experiments')
        config.addinivalue_line('python_files', '*.py')
        config.addinivalue_line('python_functions', '_test*')
        cfg['paths']['agent_directory'] = orig_agent_dir
        micropsi_runtime.initialize(config=cfg)
    elif config.getoption('worlds'):
        config.args = [orig_world_dir]
        config.addinivalue_line('python_functions', 'test_*')
        cfg['paths']['world_directory'] = orig_world_dir
        micropsi_runtime.initialize(config=cfg)
    else:
        config.addinivalue_line('python_functions', 'test_*')
        micropsi_runtime.initialize(config=cfg)

    from micropsi_server.micropsi_app import usermanager
    usermanager.create_user('Pytest User', 'test', 'Administrator', uid='Pytest User')
    usermanager.start_session('Pytest User', 'test', True)
    set_logging_levels()
    micropsi_runtime.set_runner_properties(1, True)
示例#3
0
def pytest_runtest_setup(item):
    engine_marker = item.get_marker("engine")
    if engine_marker is not None:
        engines = engine_marker.args
        engine_marker = engine_marker.args[0]
        if item.callspec.params['engine'] not in engines:
            pytest.skip("test requires engine %s" % engine_marker)
    for uid in list(micropsi_runtime.nodenets.keys()):
        micropsi_runtime.stop_nodenetrunner(uid)
    for uid in list(micropsi_runtime.nodenets.keys()):
        micropsi_runtime.delete_nodenet(uid)
    for uid in list(micropsi_runtime.worlds.keys()):
        micropsi_runtime.delete_world(uid)

    for item in os.listdir(testpath):
        path = os.path.join(testpath, item)
        if os.path.isdir(path):
            shutil.rmtree(path)
        else:
            os.remove(path)

    open(os.path.join(testpath, '__init__.py'), 'w').close()
    os.mkdir(os.path.join(testpath, 'worlds'))
    os.mkdir(os.path.join(testpath, 'nodenets'))
    os.mkdir(os.path.join(testpath, 'nodenets', '__autosave__'))
    os.mkdir(os.path.join(testpath, 'nodetypes'))
    os.mkdir(os.path.join(testpath, 'recipes'))
    os.mkdir(os.path.join(testpath, 'operations'))
    os.mkdir(os.path.join(testpath, 'nodetypes', 'Test'))
    open(os.path.join(testpath, 'nodetypes', 'Test', '__init__.py'), 'w').close()
    micropsi_runtime.reload_code()
    micropsi_runtime.logger.clear_logs()
    micropsi_runtime.set_runner_properties(0, True)
    set_logging_levels()
示例#4
0
def test_register_runner_condition_step(test_nodenet):
    import time
    micropsi.set_runner_properties(1, 1)
    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
示例#5
0
def test_register_runner_condition_step(test_nodenet):
    import time
    micropsi.set_runner_properties(1, 1)
    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
示例#6
0
def test_register_runner_condition_monitor(test_nodenet):
    import time
    micropsi.set_runner_properties(1, 1)
    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
示例#7
0
def pytest_runtest_setup(item):
    engine_marker = item.get_marker("engine")
    if engine_marker is not None:
        engine_marker = engine_marker.args[0]
        if engine_marker != item.callspec.params['engine']:
            pytest.skip("test requires engine %s" % engine_marker)
    for item in os.listdir(testpath):
        if item != 'worlds' and item != 'nodenets':
            path = os.path.join(testpath, item)
            if os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.remove(path)
    os.mkdir(os.path.join(testpath, 'Test'))
    open(os.path.join(testpath, 'Test', '__init__.py'), 'w').close()
    micropsi.reload_native_modules()
    micropsi.logger.clear_logs()
    micropsi.set_runner_properties(1, 1)
    set_logging_levels()
示例#8
0
def test_register_runner_condition_monitor(test_nodenet):
    import time
    micropsi.set_runner_properties(1, 1)
    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
def test_actuators_do_not_reset_each_others_datatarget(test_world, test_nodenet):
    world = runtime.worlds[test_world]
    nodenet = runtime.get_nodenet(test_nodenet)
    runtime.load_nodenet(test_nodenet)
    nodenet.world = world
    runtime.set_runner_properties(200, 1)
    runtime.set_nodenet_properties(nodenet.uid, worldadapter='Braitenberg', world_uid=world.uid)
    actor1 = nodenet.netapi.create_node("Actor", "Root")
    actor2 = nodenet.netapi.create_node("Actor", "Root")
    actor1.set_parameter('datatarget', 'engine_r')
    actor2.set_parameter('datatarget', 'engine_r')
    reg1 = nodenet.netapi.create_node("Register", "Root")
    reg2 = nodenet.netapi.create_node("Register", "Root")
    nodenet.netapi.link(reg1, 'gen', actor1, 'gen')
    nodenet.netapi.link(reg2, 'gen', actor2, 'gen')
    reg1.activation = 0.7
    reg2.activation = 0.3
    runtime.step_nodenet(test_nodenet)
    actor1.node_function()
    actor2.node_function()
    assert world.agents[test_nodenet].datatargets['engine_r'] == 1
示例#10
0
def test_actuators_do_not_reset_each_others_datatarget(test_world, test_nodenet):
    world = runtime.worlds[test_world]
    nodenet = runtime.get_nodenet(test_nodenet)
    runtime.load_nodenet(test_nodenet)
    nodenet.world = test_world
    runtime.set_runner_properties(200, 1)
    runtime.set_nodenet_properties(nodenet.uid, worldadapter='Braitenberg', world_uid=world.uid)
    actor1 = nodenet.netapi.create_node("Actor", None)
    actor2 = nodenet.netapi.create_node("Actor", None)
    actor1.set_parameter('datatarget', 'engine_r')
    actor2.set_parameter('datatarget', 'engine_r')
    reg1 = nodenet.netapi.create_node("Register", None)
    reg2 = nodenet.netapi.create_node("Register", None)
    nodenet.netapi.link(reg1, 'gen', actor1, 'gen')
    nodenet.netapi.link(reg2, 'gen', actor2, 'gen')
    reg1.activation = 0.7
    reg2.activation = 0.3
    mock_reset = mock.Mock(return_value=None)
    world.agents[test_nodenet].reset_datatargets = mock_reset
    runtime.step_nodenet(test_nodenet)
    assert world.agents[test_nodenet].datatargets['engine_r'] == 1
示例#11
0
def edit_runner_properties():
    user_id, permissions, token = get_request_data()
    if len(request.params) > 0:
        log_levels = {
            'agent': request.params.get('log_level_agent'),
            'system': request.params.get('log_level_system'),
            'world': request.params.get('log_level_world')
        }
        result, msg = runtime.set_runner_properties(
            int(request.params['timestep']),
            bool(request.params.get('infguard')),
            bool(request.params.get('profile_nodenet')),
            bool(request.params.get('profile_world')),
            log_levels,
            request.params.get('log_file'))
        return dict(status="success" if result else "error", msg="Settings saved" if result else msg)
    else:
        return template("runner_form", action="/config/runner", value=runtime.get_runner_properties())
示例#12
0
def set_runner_properties(timestep, factor):
    return runtime.set_runner_properties(timestep, factor)
示例#13
0
def set_runner_properties(timestep, infguard=False, profile_nodenet=False, profile_world=False, log_levels={}, log_file=None):
    """ Configure the server-settings for the runner """
    return runtime.set_runner_properties(int(timestep), tools.parse_bool(infguard), tools.parse_bool(profile_nodenet), tools.parse_bool(profile_world), log_levels, log_file)