|
| 1 | +from experiments.utils.exp_setup import DlStreamConfigWriter |
| 2 | +import click |
| 3 | + |
| 4 | +@click.command() |
| 5 | +@click.option('--default', 'default', is_flag=True) |
| 6 | +def design_experiment(default): |
| 7 | + config = DlStreamConfigWriter() |
| 8 | + input_dict = dict(EXPERIMENT = None, |
| 9 | + TRIGGER = None, |
| 10 | + PROCESS = None, |
| 11 | + STIMULATION = None) |
| 12 | + |
| 13 | + def get_input(input_name): |
| 14 | + click.echo(f'Choosing {input_name}... \n Available {input_name}s are: ' + ', '.join(config.get_available_module_names(input_name))) |
| 15 | + input_value = click.prompt(f'Enter a base {input_name} module',type=str) |
| 16 | + while not config.check_if_default_exists(input_value,input_name): |
| 17 | + click.echo(f'{input_name} {input_value} does not exists.') |
| 18 | + input_value = click.prompt(f'Enter a base {input_name} module',type=str) |
| 19 | + return input_value |
| 20 | + """Experiment""" |
| 21 | + |
| 22 | + input_value = get_input('EXPERIMENT') |
| 23 | + input_dict['EXPERIMENT'] = input_value |
| 24 | + if input_value == 'BaseOptogeneticExperiment': |
| 25 | + input_dict['STIMULATION'] = 'BaseStimulation' |
| 26 | + input_dict['PROCESS'] = 'BaseProtocolProcess' |
| 27 | + |
| 28 | + elif input_value == 'BaseTrialExperiment': |
| 29 | + click.echo(f'Available Triggers are: ' + ', '.join(config.get_available_module_names('TRIGGER'))) |
| 30 | + click.echo('Note, that you cannot select the same Trigger as selected in TRIGGER.') |
| 31 | + |
| 32 | + input_value = click.prompt(f'Enter TRIAL_TRIGGER for BaseTrialExperiment', type=str) |
| 33 | + while not config.check_if_default_exists(input_value, 'TRIGGER'): |
| 34 | + click.echo(f'TRIGGER {input_value} does not exists.') |
| 35 | + input_value = click.prompt(f'Enter a base TRIGGER module', type=str) |
| 36 | + |
| 37 | + input_dict['TRIAL_TRIGGER'] = input_value |
| 38 | + click.echo(f'TRIAL_TRIGGER for BaseTrialExperiment set to {input_value}.') |
| 39 | + |
| 40 | + """TRIGGER""" |
| 41 | + |
| 42 | + input_value = get_input('TRIGGER') |
| 43 | + input_dict['TRIGGER'] = input_value |
| 44 | + |
| 45 | + |
| 46 | + """Process""" |
| 47 | + |
| 48 | + if input_dict['PROCESS'] is None: |
| 49 | + input_value = get_input('PROCESS') |
| 50 | + input_dict['PROCESS'] = input_value |
| 51 | + |
| 52 | + """STIMULATION""" |
| 53 | + if input_dict['STIMULATION'] is None: |
| 54 | + input_value = get_input('STIMULATION') |
| 55 | + input_dict['STIMULATION'] = input_value |
| 56 | + |
| 57 | + """Setting Process Type""" |
| 58 | + |
| 59 | + if input_dict['EXPERIMENT'] == 'BaseTrialExperiment': |
| 60 | + input_dict['PROCESS_TYPE'] = 'trial' |
| 61 | + elif input_dict['STIMULATION'] == 'BaseStimulation': |
| 62 | + input_dict['PROCESS_TYPE'] = 'switch' |
| 63 | + elif input_dict['STIMULATION'] == 'ScreenStimulation' or input_dict['STIMULATION'] == 'RewardDispenser': |
| 64 | + input_dict['PROCESS_TYPE'] = 'supply' |
| 65 | + |
| 66 | + |
| 67 | + if input_dict['EXPERIMENT'] == 'BaseTrialExperiment': |
| 68 | + config.import_default(experiment_name=input_dict['EXPERIMENT'], trigger_name=input_dict['TRIGGER'], |
| 69 | + process_name=input_dict['PROCESS'], stimulation_name=input_dict['STIMULATION'], |
| 70 | + trial_trigger_name=input_dict['TRIAL_TRIGGER']) |
| 71 | + |
| 72 | + else: |
| 73 | + config.import_default(experiment_name=input_dict['EXPERIMENT'], trigger_name=input_dict['TRIGGER'], |
| 74 | + process_name=input_dict['PROCESS'], stimulation_name=input_dict['STIMULATION']) |
| 75 | + |
| 76 | + if 'PROCESS_TYPE' in input_dict.keys(): |
| 77 | + config._change_parameter(module_name=input_dict['PROCESS'],parameter_name='TYPE', |
| 78 | + parameter_value=input_dict['PROCESS_TYPE']) |
| 79 | + |
| 80 | + |
| 81 | + if click.confirm('Do you want to set parameters as well (Not recommended)? \n Note, that you can change them in the created file later.'): |
| 82 | + current_config = config.get_current_config() |
| 83 | + ignore_list = ['EXPERIMENT', 'BaseProtocolProcess'] |
| 84 | + inner_ignore_list = ['EXPERIMENTER', 'PROCESS', 'STIMULATION', 'TRIGGER', 'DEBUG'] |
| 85 | + try: |
| 86 | + for module in current_config.keys(): |
| 87 | + parameter_dict = config.get_parameters(module) |
| 88 | + if module not in ignore_list: |
| 89 | + for input_key in parameter_dict.keys(): |
| 90 | + if input_key not in inner_ignore_list: |
| 91 | + click.echo(f'Default {input_key} is: ' + str(parameter_dict[input_key])) |
| 92 | + input_value = click.prompt(f'Enter new value: ',type=str) |
| 93 | + config._change_parameter(module_name=module,parameter_name=input_key, |
| 94 | + parameter_value=input_value) |
| 95 | + except: |
| 96 | + click.echo('Failed to set individual parameters. Please change them later in the config file...') |
| 97 | + else: |
| 98 | + click.echo('Skipping parameters. Experiment config will be created with default values...') |
| 99 | + """Finish up""" |
| 100 | + # Name of experimentor |
| 101 | + experimenter = click.prompt('Enter an experimenter name',type=str) |
| 102 | + click.echo(f'Experimenter set to {experimenter}.') |
| 103 | + config.set_experimenter(experimenter) |
| 104 | + |
| 105 | + click.echo('Current modules are:\n BaseExperiment: {}\n Trigger: {}\n Process: {} \n Stimulation: {}'.format( |
| 106 | + input_dict['EXPERIMENT'], |
| 107 | + input_dict['TRIGGER'], |
| 108 | + input_dict['PROCESS'], |
| 109 | + input_dict['STIMULATION'])) |
| 110 | + |
| 111 | + |
| 112 | + if click.confirm('Do you want to continue?'): |
| 113 | + config.write_ini() |
| 114 | + click.echo('Config was created. It can be found in experiments/configs') |
| 115 | + |
| 116 | + |
| 117 | +if __name__ == '__main__': |
| 118 | + design_experiment() |
0 commit comments