예제 #1
0
def eval_model(event, values, window, collapsibles, module_keys, odor_gains):
    if event == 'LOAD_MODEL':
        if values['MODEL_CONF'] != '':
            conf = loadConf(values['MODEL_CONF'], 'Model')
            odor_gains = update_model(conf, window, collapsibles, odor_gains)

    elif event == 'SAVE_MODEL':
        l = [[sg.Text('Store new model', size=(20, 1)), sg.In(k='MODEL_ID', size=(10, 1))],
             [sg.Ok(), sg.Cancel()]]
        e, v = sg.Window('Model configuration', l).read(close=True)
        if e == 'Ok':
            model = get_model(window, values, module_keys, collapsibles, odor_gains)
            model_id = v['MODEL_ID']
            saveConf(model, 'Model', model_id)
            window['MODEL_CONF'].update(values=list(loadConfDict('Model').keys()))

    elif event == 'DELETE_MODEL':
        if values['MODEL_CONF'] != '':
            deleteConf(values['MODEL_CONF'], 'Model')
            window['MODEL_CONF'].update(values=list(loadConfDict('Model').keys()))
            window['MODEL_CONF'].update(value='')

    elif event == 'ODOR GAINS':
        odor_gains = set_agent_dict(odor_gains, odor_gain_pars, title='Odor gains')


    return odor_gains
예제 #2
0
def build_batch_tab(collapsibles):
    batch = copy.deepcopy(test_batch)
    space_search = batch['space_search']
    l_exp = [sg.Col([
        named_list_layout(text='Batch:', key='BATCH_CONF', choices=list(loadConfDict('Batch').keys())),
        [sg.Button('Load', key='LOAD_BATCH', **button_kwargs),
         sg.Button('Save', key='SAVE_BATCH', **button_kwargs),
         sg.Button('Delete', key='DELETE_BATCH', **button_kwargs),
         sg.Button('Run', key='RUN_BATCH', **button_kwargs)]
    ])]
    batch_conf = [[sg.Text('Batch id:', **text_kwargs), sg.In('unnamed_batch_0', key='batch_id', **text_kwargs)],
                  [sg.Text('Path:', **text_kwargs), sg.In('unnamed_batch', key='batch_path', **text_kwargs)],
                  # [sg.Text('Duration (min):', **text_kwargs), sg.In(3, key='batch_dur', **text_kwargs)],
                  # [sg.Text('Timestep (sec):', **text_kwargs), sg.In(0.1, key='dt', **text_kwargs)],
                  # collapsibles['OUTPUT'].get_section()
                  ]

    collapsibles['BATCH_CONFIGURATION'] = Collapsible('BATCH_CONFIGURATION', True, batch_conf)
    l_conf = collapsibles['BATCH_CONFIGURATION'].get_section()
    l_batch0 = [[sg.Col([l_exp,
                         l_conf,
                         [sg.Button('SPACE_SEARCH', **buttonM_kwargs)]])]]
    l_batch1 = [init_batch(batch, collapsibles)]
    l_batch = [[sg.Col(l_batch0), sg.Col(l_batch1)]]
    return l_batch, collapsibles, space_search
예제 #3
0
def eval_sim(event, values, window, sim_datasets, collapsibles, output_keys,
             source_units, border_list, larva_groups, source_groups):
    if event == 'LOAD_EXP' and values['EXP'] != '':
        source_units, border_list, larva_groups, source_groups = update_sim(window, values, collapsibles, output_keys)


    elif event == 'LOAD_ENV' and values['ENV_CONF'] != '':
        conf = loadConf(values['ENV_CONF'], 'Env')
        source_units, border_list, larva_groups, source_groups = update_env(conf, window, collapsibles)

    elif event == 'SAVE_ENV':
        env = get_env(window, values, collapsibles, source_units, border_list, larva_groups, source_groups)
        save_env(window, env)



    elif event == 'DELETE_ENV' and values['ENV_CONF'] != '':
        deleteConf(values['ENV_CONF'], 'Env')
        window['ENV_CONF'].update(values=list(loadConfDict('Env').keys()))
        window['ENV_CONF'].update(value='')


    elif event == 'LARVA GROUPS':
        larva_groups = set_agent_dict(larva_groups, distro_pars('Larva'), header='group', title='Larva distribution')

    elif event == 'SOURCE UNITS':
        source_units = set_agent_dict(source_units, agent_pars['Food'], title='Food distribution')

    elif event == 'SOURCE GROUPS':
        source_groups = set_agent_dict(source_groups, distro_pars('Food'), header='group', title='Food distribution')

    elif event == 'BORDERS':
        border_list = set_agent_dict(border_list, agent_pars['Border'], title='Impassable borders')


    elif event == 'CONF_ENV':
        env = get_env(window, values, collapsibles, source_units, border_list, larva_groups, source_groups)
        new_source_units, new_border_list = configure_sim(env_params=env)
        l = [
            [sg.Text('Food agents and borders have been individually stored.', size=(70, 1))],
            [sg.Text('If you choose to continue the existing group distributions will be erased.', size=(70, 1))],
            [sg.Text('Continue?', size=(70, 1))],
            [sg.Ok(), sg.Cancel()]]
        e, v = sg.Window('Environment configuration', l).read(close=True)
        if e == 'Ok':
            source_units = new_source_units
            border_list = new_border_list
            source_groups = {}


    elif event == 'Run' and values['EXP'] != '':
        sim_config = get_sim(window, values, collapsibles, output_keys, source_units, border_list, larva_groups,
                             source_groups)
        vis_kwargs = {'mode': 'video'}
        d = run_sim(**sim_config, **vis_kwargs)
        if d is not None:
            sim_datasets.append(d)
    return source_units, border_list, larva_groups, source_groups
예제 #4
0
def eval_batch(event, values, window, collapsibles, space_search):
    if event == 'LOAD_BATCH':
        if values['BATCH_CONF'] != '':
            # batch = copy.deepcopy(batch_types[values['BATCH_CONF']])
            batch=values['BATCH_CONF']
            window.Element('batch_id').Update(value=f'{batch}_{next_idx(batch, type="batch")}')
            window.Element('batch_path').Update(value=batch)
            conf = loadConf(batch, 'Batch')
            space_search = update_batch(conf, window, collapsibles, space_search)

    elif event == 'SAVE_BATCH':
        l = [[sg.Text('Store new batch', size=(20, 1)), sg.In(k='BATCH_ID', size=(10, 1))],
             [sg.Ok(), sg.Cancel()]]
        e, v = sg.Window('Batch configuration', l).read(close=True)
        if e == 'Ok':
            batch = get_batch(window, values, collapsibles)
            batch_id = v['BATCH_ID']
            saveConf(batch, 'Batch', batch_id)
            window['BATCH_CONF'].update(values=list(loadConfDict('Batch').keys()))

    elif event == 'DELETE_BATCH':
        if values['BATCH_CONF'] != '':
            deleteConf(values['BATCH_CONF'], 'Batch')
            window['BATCH_CONF'].update(values=list(loadConfDict('Batch').keys()))
            window['BATCH_CONF'].update(value='')

    elif event == 'RUN_BATCH':
        if values['BATCH_CONF'] != '' and values['EXP'] != '':
            from lib.sim.batch_lib import prepare_batch, batch_run
            batch = get_batch(window, values, collapsibles, space_search)
            batch_id = str(values['batch_id'])
            batch_path = str(values['batch_path'])
            # dir = f'{batch_path}/{batch["exp"]}'
            sim_params = get_sim_conf(window, values)
            life_params = collapsibles['LIFE'].get_dict(values, window)
            sim_config = generate_config(exp=batch["exp"], sim_params=sim_params, life_params=life_params)
            batch_kwargs = prepare_batch(batch, batch_id, sim_config)
            df=batch_run(**batch_kwargs)

            # run_batch(batch)

    elif event == 'SPACE_SEARCH':
        space_search = set_space_table(space_search)

    return space_search
예제 #5
0
def save_env(window, env):
    l = [[sg.Text('Store new environment', size=(20, 1)), sg.In(k='ENV_ID', size=(10, 1))],
         [sg.Ok(), sg.Cancel()]]
    e, v = sg.Window('Environment configuration', l).read(close=True)
    if e == 'Ok':
        env_id = v['ENV_ID']
        saveConf(env, 'Env', env_id)
        window['ENV_CONF'].update(values=list(loadConfDict('Env').keys()))
        window['ENV_CONF'].update(value=env_id)
예제 #6
0
def build_sim_tab(collapsibles):
    sim_datasets = []

    env_params = copy.deepcopy(test_env)
    larva_groups = env_params['larva_params']
    source_units = env_params['food_params']['source_units']
    source_groups = env_params['food_params']['source_groups']
    border_list = {}

    l_exp = [sg.Col([
        named_list_layout(text='Experiment:', key='EXP', choices=list(exp_types.keys())),
        [sg.Button('Load', key='LOAD_EXP', **button_kwargs), sg.Button('Run', **button_kwargs)]
    ])]
    output_keys = list(effector_collection.keys())
    output_dict = dict(zip(output_keys, [False] * len(output_keys)))
    collapsibles['OUTPUT'] = CollapsibleDict('OUTPUT', False, dict=output_dict)

    sim_conf = [[sg.Text('Sim id:', **text_kwargs), sg.In('unnamed_sim', key='sim_id', **text_kwargs)],
                [sg.Text('Path:', **text_kwargs), sg.In('single_runs', key='path', **text_kwargs)],
                [sg.Text('Duration (min):', **text_kwargs), sg.In(3, key='sim_dur', **text_kwargs)],
                [sg.Text('Timestep (sec):', **text_kwargs), sg.In(0.1, key='dt', **text_kwargs)],
                named_bool_button('Box2D', False),
                collapsibles['OUTPUT'].get_section()
                ]

    collapsibles['CONFIGURATION'] = Collapsible('CONFIGURATION', True, sim_conf)

    l_conf1 = collapsibles['CONFIGURATION'].get_section()

    life_dict = {'starvation_hours': None,
                 'hours_as_larva': 0.0,
                 'deb_base_f': 1.0}
    collapsibles['LIFE'] = CollapsibleDict('LIFE', False, dict=life_dict, type_dict=life_pars_dict)
    l_life = collapsibles['LIFE'].get_section()

    l_conf = [[sg.Col([l_exp, l_conf1, l_life])]]

    l_env0 = [sg.Col([
        [sg.Text('Environment:', **header_kwargs),
         sg.Combo(list(loadConfDict('Env').keys()), key='ENV_CONF', enable_events=True, readonly=True, **text_kwargs)],
        [sg.Button('Load', key='LOAD_ENV', **button_kwargs),
         sg.Button('Configure', key='CONF_ENV', **button_kwargs),
         sg.Button('Save', key='SAVE_ENV', **button_kwargs),
         sg.Button('Delete', key='DELETE_ENV', **button_kwargs)]
    ])]
    l_env1 = init_env(env_params, collapsibles)

    l_env = [[sg.Col([l_env0, l_env1])]]

    l_sim = [[sg.Col(l_conf), sg.Col(l_env)]]

    return l_sim, sim_datasets, collapsibles, output_keys, source_units, border_list, larva_groups, source_groups
예제 #7
0
def build_model_tab(collapsibles):
    larva_model = copy.deepcopy(test_larva)
    odor_gains = larva_model['neural_params']['olfactor_params']['odor_dict']
    module_dict = larva_model['neural_params']['modules']
    module_keys = list(module_dict.keys())

    l_mod0 = [sg.Col([
        [sg.Text('Larva model:', **header_kwargs),
         sg.Combo(list(loadConfDict('Model').keys()), key='MODEL_CONF', enable_events=True, readonly=True,
                  **text_kwargs)],
        [sg.Button('Load', key='LOAD_MODEL', **button_kwargs),
         sg.Button('Save', key='SAVE_MODEL', **button_kwargs),
         sg.Button('Delete', key='DELETE_MODEL', **button_kwargs)]
    ])]

    l_mod1 = init_model(larva_model, collapsibles)

    l_mod = [[sg.Col([l_mod0, l_mod1])]]
    return l_mod, collapsibles, module_keys, odor_gains
예제 #8
0
def distro_pars(class_name):
    larva_distros = [
        'normal', 'defined', 'identical', 'uniform', 'uniform_circ', 'spiral',
        'facing_right'
    ]

    food_distros = [
        'normal',
        # 'defined',
        'uniform'
    ]

    agent_distros = {
        'Larva': larva_distros,
        'Food': food_distros,
    }

    common_distro_pars = {
        'group': str,
        'default_color': str,
        'mode': agent_distros[class_name],
        'N': int,
        'loc': Tuple[float, float],
        'scale': float,
    }
    if class_name == 'Food':
        return {
            **common_distro_pars,
            **base_food_pars,
            # 'pars': base_food_pars,
        }
    elif class_name == 'Larva':
        from lib.stor.datagroup import loadConfDict
        return {
            'model': list(loadConfDict('Model').keys()),
            **common_distro_pars, 'orientation': float
        }