Пример #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 generate_config(exp, sim_params, Nagents=None, life_params={}):
    config = copy.deepcopy(exp_types[exp])
    config['experiment'] = exp
    config['sim_params'] = sim_params
    config['life_params'] = life_params

    if type(config['env_params'])==str :
        config['env_params']=loadConf(config['env_params'], 'Env')

    if Nagents is not None:
        config['env_params']['larva_params']['Larva']['N'] = Nagents
    for k,v in config['env_params']['larva_params'].items():
        if type(v['model'])==str :
            v['model']=loadConf(v['model'], 'Model')
    # print(config['env_params']['larva_params']['Larva']['model'])
    # raise
    return config
Пример #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 get_env(window, values, collapsibles, source_units, border_list, larva_groups, source_groups):
    env = {}
    env['larva_params'] = larva_groups
    env['food_params'] = {}
    env['food_params']['source_groups'] = source_groups
    env['food_params']['food_grid'] = collapsibles['FOOD_GRID'].get_dict(values, window)
    env['food_params']['source_units'] = source_units
    env['border_list'] = border_list
    env['arena_params'] = collapsibles['ARENA'].get_dict(values, window)

    for k, v in env['larva_params'].items():
        if type(v['model']) == str:
            v['model'] = loadConf(v['model'], 'Model')
    return copy.deepcopy(env)
Пример #5
0
def update_sim(window, values, collapsibles, output_keys):
    exp = values['EXP']
    exp_conf = copy.deepcopy(exp_types[exp])
    env = exp_conf['env_params']
    if type(env) == str:
        window.Element('ENV_CONF').Update(value=env)
        env = loadConf(env, 'Env')
    source_units, border_list, larva_groups, source_groups = update_env(env, window, collapsibles)

    output_dict = dict(zip(output_keys, [True if k in exp_conf['collections'] else False for k in output_keys]))
    collapsibles['OUTPUT'].update(window, output_dict)

    window.Element('sim_id').Update(value=f'{exp}_{next_idx(exp)}')
    window.Element('path').Update(value=f'single_runs/{exp}')
    return source_units, border_list, larva_groups, source_groups
Пример #6
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