示例#1
0
            sys.exit(
                str(e) + '\n' +
                'map_config import error. File not exist or map_config not specified'
            )
        from gym.envs.registration import register

        register(
            id='MonsterKong-v0',
            entry_point='baselines.ple.gym_env.monsterkong:MonsterKongEnv',
            kwargs={'map_config': map_config},
        )

        env = gym.make('MonsterKong-v0')
        env = ProcessFrame(env)
    else:
        env = create_atari_environment(args.env, sticky_actions=False)
        env = FrameStack(env, 4)
    if args.seed > 0:
        set_global_seeds(args.seed)
        env.unwrapped.seed(args.seed)
    print("obs shape", env.observation_space.shape)
    # env = GIFRecorder(video_path=args.video_path + "/{}/".format(args.comment), record_video=True, env=env)
    subdir = (datetime.datetime.now()
              ).strftime("%m-%d-%Y-%H:%M:%S") + " " + args.comment
    tf_writer = tf.summary.FileWriter(os.path.join(args.log_dir, subdir),
                                      tf.get_default_graph())
    value_summary = tf.Summary()
    qec_summary = tf.Summary()
    value_summary.value.add(tag='discount_reward_mean')
    value_summary.value.add(tag='non_discount_reward_mean')
    # value_summary.value.add(tag='episode')
示例#2
0
文件: util.py 项目: MouseHu/emdqn
def create_env(args):
    if args.env == "MK" or args.env == "mk":
        import imp

        try:
            map_config_file = mk_map_config.get(args.env_name,
                                                mk_map_config["small"])
            map_config = imp.load_source('map_config',
                                         map_config_file).map_config
        except Exception as e:
            sys.exit(
                str(e) + '\n' +
                'map_config import error. File not exist or map_config not specified'
            )
        from gym.envs.registration import register

        register(
            id='MonsterKong-v{}'.format(args.number),
            entry_point='baselines.ple.gym_env.monsterkong:MonsterKongEnv',
            kwargs={
                'map_config': map_config,
                'noise_size': args.noise_size
            },
        )

        env = gym.make('MonsterKong-v{}'.format(args.number))

        env = ProcessFrame(env)
        env = MKPreprocessing(env, frame_skip=3, no_jump=True)
    elif args.env == "GW" or args.env == "gw":
        if args.env_name == "fourrooms":
            env = ImageInputWarpper(Fourrooms())
        elif args.env_name == "fourrooms_noise":
            env = ImageNoisyEnv(ImageInputWarpper(Fourrooms()),
                                args.noise_size, 400)
        elif args.env_name == "fourroomscoin":
            env = ImageInputWarpper(FourroomsCoin())
        else:
            env = ImageNoisyEnv(ImageInputWarpper(FourroomsCoin()),
                                args.noise_size, 400)
    elif args.env == "doom" or args.env == "Doom":
        params = load_params(args.param_dir, args.env_name)
        env = DoomEnvironment(**params['env_params'])
        env = DoomPreprocessing(env, frame_skip=4)
    elif args.env == "atari" or args.env == "Atari":
        env = create_atari_environment(args.env_name, sticky_actions=False)
        env = FrameStack(env, 4)
        # if args.env_name == "Pong":
        #     env = CropWrapper(env, 34, 15)
    elif args.env == "vast":

        params = load_params("../atari/", args.env_name)
        params["env_params"]['game'] = args.env_name
        env = atari_env_vast(**params["env_params"])
    elif args.env == "mujoco":
        from gym.envs.registration import register
        goal_args = [[0.0, 16.0], [0 + 1e-3, 16 + 1e-3], [0.0, 6.0],
                     [15 + 1e-3, 10 + 1e-3]]
        random_start = False

        # The episode  length for test is 500

        max_timestep = 500
        register(
            id='PointMazeTest-v10',
            entry_point='mujoco.create_maze_env:create_maze_env',
            kwargs={
                'env_name': 'DiscretePointBlock',
                'goal_args': goal_args,
                'maze_size_scaling': 4,
                'random_start': random_start,
                'env_args': {
                    'amplify': args.amplify
                }
            },
            max_episode_steps=max_timestep,
        )
        env = gym.make('PointMazeTest-v10')
    elif args.env == "noise_atari" or args.env == "atari_noise":
        game_version = 'v0'
        env = gym.make('{}-{}'.format(args.env_name, game_version))
        env = NoisyEnv(env, args.noise_dim, args.noise_var)

    elif args.env == "noise_mujoco" or args.env == "mujoco_noise":
        from gym.envs.registration import register
        if args.env_name == "flip":
            goal_args = [[0.0, 16.0], [0 + 1e-3, 16 + 1e-3], [0.0, 6.0],
                         [15 + 1e-3, 10 + 1e-3]]
        else:
            goal_args = [[16.0, 16.0], [16 + 1e-3, 16 + 1e-3], [1.0, 6.0],
                         [16 + 1e-3, 10 + 1e-3]]
        random_start = False
        # The episode length for test is 500
        max_timestep = 500
        try:
            register(
                id='PointMazeTest-v10',
                entry_point='mujoco.create_maze_env:create_maze_env',
                kwargs={
                    'env_name': 'DiscretePointBlock',
                    'goal_args': goal_args,
                    'maze_size_scaling': 4,
                    'random_start': random_start
                },
                max_episode_steps=max_timestep,
            )
        except gym.error.Error:
            pass
        env = gym.make('PointMazeTest-v10')

        env = DynamicNoisyEnv(env,
                              args.noise_dim,
                              args.noise_var,
                              seed=args.seed)
        # env = StaticNoisyEnv(env, args.noise_dim, args.noise_var, seed=args.seed)
    elif args.env == "dreamer":
        task = dreamer_tasks.cheetah_run({}, {'max_length': 500})
        env = task[1]()
        env = DiscreteWrapper(env)
    elif args.env == "coinrun" or args.env == "CoinRun":
        CoinrunConfig.initialize_args(False)
        from coinrun.coinrun.coinrunenv import init_args_and_threads
        init_args_and_threads(4)

        # env_id = coinrun_game_versions.get(args.env_name,1000)
        print("create env", args.env_name)
        env = CoinRunVecEnv(args.env_name, 1)
    # elif args.env == "d4rl":
    #     import d4rl
    #     env = gym.make(args.env_name)
    #
    #     if "maze" in args.env_name:
    #         env = D4RLDiscreteMazeEnvWrapper(env)

    else:
        raise NotImplementedError
    if args.seed > 0:
        set_global_seeds(args.seed)
        env.unwrapped.seed(args.seed)
    return env