def get_experiment_name(initial_experiment_name=''): match = None while match is None: if initial_experiment_name == '': experiment_name = screen.ask_input( "Please enter an experiment name: ") else: experiment_name = initial_experiment_name experiment_name = experiment_name.replace(" ", "_") match = re.match("^$|^[\w -/]{1,100}$", experiment_name) if match is None: screen.error( 'Experiment name must be composed only of alphanumeric letters, ' 'underscores and dashes and should not be longer than 100 characters.' ) return match.group(0)
def check_input_and_fill_run_dict(parser): args = parser.parse_args() # if no arg is given if len(sys.argv) == 1: parser.print_help() exit(0) # list available presets if args.list: presets_lists = list_all_classes_in_module(presets) screen.log_title("Available Presets:") for preset in presets_lists: print(preset) sys.exit(0) # check inputs try: # num_workers = int(args.num_workers) num_workers = int(re.match("^\d+$", args.num_workers).group(0)) except ValueError: screen.error("Parameter num_workers should be an integer.") preset_names = list_all_classes_in_module(presets) if args.preset is not None and args.preset not in preset_names: screen.error("A non-existing preset was selected. ") if args.checkpoint_restore_dir is not None and not os.path.exists(args.checkpoint_restore_dir): screen.error("The requested checkpoint folder to load from does not exist. ") if args.save_model_sec is not None: try: args.save_model_sec = int(args.save_model_sec) except ValueError: screen.error("Parameter save_model_sec should be an integer.") if args.preset is None and (args.agent_type is None or args.environment_type is None or args.exploration_policy_type is None) and not args.play: screen.error('When no preset is given for Coach to run, the user is expected to input the desired agent_type,' ' environment_type and exploration_policy_type to assemble a preset. ' '\nAt least one of these parameters was not given.') elif args.preset is None and args.play and args.environment_type is None: screen.error('When no preset is given for Coach to run, and the user requests human control over the environment,' ' the user is expected to input the desired environment_type and level.' '\nAt least one of these parameters was not given.') elif args.preset is None and args.play and args.environment_type: args.agent_type = 'Human' args.exploration_policy_type = 'ExplorationParameters' # get experiment name and path experiment_name = logger.get_experiment_name(args.experiment_name) experiment_path = logger.get_experiment_path(experiment_name) if args.play and num_workers > 1: screen.warning("Playing the game as a human is only available with a single worker. " "The number of workers will be reduced to 1") num_workers = 1 # fill run_dict run_dict = dict() run_dict['agent_type'] = args.agent_type run_dict['environment_type'] = args.environment_type run_dict['exploration_policy_type'] = args.exploration_policy_type run_dict['level'] = args.level run_dict['preset'] = args.preset run_dict['custom_parameter'] = args.custom_parameter run_dict['experiment_path'] = experiment_path run_dict['framework'] = Frameworks().get(args.framework) run_dict['play'] = args.play run_dict['evaluate'] = args.evaluate# or args.play # multi-threading parameters run_dict['num_threads'] = num_workers # checkpoints run_dict['save_model_sec'] = args.save_model_sec run_dict['save_model_dir'] = experiment_path if args.save_model_sec is not None else None run_dict['checkpoint_restore_dir'] = args.checkpoint_restore_dir # visualization run_dict['visualization.dump_gifs'] = args.dump_gifs run_dict['visualization.render'] = args.render run_dict['visualization.tensorboard'] = args.tensorboard return args, run_dict
# use the following command line to download and extract the CARLA dataset: # python rl_coach/utilities/carla_dataset_to_replay_buffer.py agent_params.memory.load_memory_from_file_path = "./datasets/carla_train_set_replay_buffer.p" agent_params.memory.state_key_with_the_class_index = 'high_level_command' agent_params.memory.num_classes = 4 # download dataset if it doesn't exist if not os.path.exists(agent_params.memory.load_memory_from_file_path): screen.log_title("The CARLA dataset is not present in the following path: {}" .format(agent_params.memory.load_memory_from_file_path)) result = screen.ask_yes_no("Do you want to download it now?") if result: create_dataset(None, "./datasets/carla_train_set_replay_buffer.p") else: screen.error("Please update the path to the CARLA dataset in the CARLA_CIL preset", crash=True) ############### # Environment # ############### env_params = CarlaEnvironmentParameters() env_params.level = 'town1' env_params.cameras = ['CameraRGB'] env_params.camera_height = 600 env_params.camera_width = 800 env_params.separate_actions_for_throttle_and_brake = True env_params.allow_braking = True env_params.quality = CarlaEnvironmentParameters.Quality.EPIC env_params.experiment_suite = CoRL2017('Town01')
def check_input_and_fill_run_dict(parser): args = parser.parse_args() # if no arg is given if len(sys.argv) == 1: parser.print_help() exit(0) # list available presets if args.list: presets_lists = list_all_classes_in_module(presets) screen.log_title("Available Presets:") for preset in presets_lists: print(preset) sys.exit(0) # check inputs try: # num_workers = int(args.num_workers) num_workers = int(re.match("^\d+$", args.num_workers).group(0)) except ValueError: screen.error("Parameter num_workers should be an integer.") exit(1) preset_names = list_all_classes_in_module(presets) if args.preset is not None and args.preset not in preset_names: screen.error("A non-existing preset was selected. ") exit(1) if args.checkpoint_restore_dir is not None and not os.path.exists( args.checkpoint_restore_dir): screen.error( "The requested checkpoint folder to load from does not exist. ") exit(1) if args.save_model_sec is not None: try: args.save_model_sec = int(args.save_model_sec) except ValueError: screen.error("Parameter save_model_sec should be an integer.") exit(1) if args.preset is None and (args.agent_type is None or args.environment_type is None or args.exploration_policy_type is None): screen.error( 'When no preset is given for Coach to run, the user is expected to input the desired agent_type,' ' environment_type and exploration_policy_type to assemble a preset. ' '\nAt least one of these parameters was not given.') exit(1) experiment_name = args.experiment_name if args.experiment_name == '': experiment_name = screen.ask_input("Please enter an experiment name: ") experiment_name = experiment_name.replace(" ", "_") match = re.match("^$|^\w{1,100}$", experiment_name) if match is None: screen.error( 'Experiment name must be composed only of alphanumeric letters and underscores and should not be ' 'longer than 100 characters.') exit(1) experiment_path = os.path.join('./experiments/', match.group(0)) experiment_path = get_experiment_path(experiment_path) # fill run_dict run_dict = dict() run_dict['agent_type'] = args.agent_type run_dict['environment_type'] = args.environment_type run_dict['exploration_policy_type'] = args.exploration_policy_type run_dict['preset'] = args.preset run_dict['custom_parameter'] = args.custom_parameter run_dict['experiment_path'] = experiment_path run_dict['framework'] = Frameworks().get(args.framework) # multi-threading parameters run_dict['num_threads'] = num_workers # checkpoints run_dict['save_model_sec'] = args.save_model_sec run_dict[ 'save_model_dir'] = experiment_path if args.save_model_sec is not None else None run_dict['checkpoint_restore_dir'] = args.checkpoint_restore_dir # visualization run_dict['visualization.dump_gifs'] = args.dump_gifs run_dict['visualization.render'] = args.render return args, run_dict
last_num_episodes = csv['Episode #'].values[-1] # check if reward is enough if np.any(averaged_rewards > preset.test_min_return_threshold): test_passed = True break time.sleep(1) # kill test and print result os.killpg(os.getpgid(p.pid), signal.SIGTERM) if test_passed: screen.success("Passed successfully") else: if csv_paths: screen.error("Failed due to insufficient reward", crash=False) screen.error( "preset.test_max_step_threshold: {}".format( preset.test_max_step_threshold), crash=False) screen.error( "preset.test_min_return_threshold: {}".format( preset.test_min_return_threshold), crash=False) screen.error( "averaged_rewards: {}".format(averaged_rewards), crash=False) screen.error("episode number: {}".format( csv['Episode #'].values[-1]), crash=False) else:
if csv['Episode #'].shape[0] - last_num_episodes <= 0: continue last_num_episodes = csv['Episode #'].values[-1] # check if reward is enough if np.any(averaged_rewards > preset.test_min_return_threshold): test_passed = True break time.sleep(1) # kill test and print result os.killpg(os.getpgid(p.pid), signal.SIGTERM) if test_passed: screen.success("Passed successfully") else: screen.error("Failed due to a mismatch with the golden", crash=False) fail_count += 1 shutil.rmtree(test_path) screen.separator() if fail_count == 0: screen.success(" Summary: " + str(test_count) + "/" + str(test_count) + " tests passed successfully") else: screen.error(" Summary: " + str(test_count - fail_count) + "/" + str(test_count) + " tests passed successfully")