Ejemplo n.º 1
0
def test_subproc_retro():
    env = retro.make("Airstriker-Genesis")
    with pytest.raises(RuntimeError):
        env = retro.make("Airstriker-Genesis")

    envs = [
        SubprocEnv(env_fn=make_retro_env,
                   env_kwargs=dict(game="Airstriker-Genesis"))
        for _ in range(2)
    ]
    env = ConcatEnv(envs)
    rew, ob, first = env.observe()
    assert np.array_equal(ob[0], ob[1])
Ejemplo n.º 2
0
def test_recorder():
    with tempfile.TemporaryDirectory() as tmpdir:
        ep_len1 = 3
        ep_len2 = 4
        env1 = IdentityEnv(
            space=types.TensorType(eltype=types.Discrete(256),
                                   shape=(3, 3, 3)),
            episode_len=ep_len1,
        )
        env2 = IdentityEnv(
            space=types.TensorType(eltype=types.Discrete(256),
                                   shape=(3, 3, 3)),
            episode_len=ep_len2,
            seed=1,
        )
        env = ConcatEnv([env1, env2])
        env = TrajectoryRecorderWrapper(env=env, directory=tmpdir)
        _, obs, _ = env.observe()
        action = types_np.zeros(env.ac_space, bshape=(env.num, ))
        action[1] = 1
        num_acs = 10
        for _ in range(num_acs):
            env.act(action)
        files = sorted(glob(os.path.join(tmpdir, "*.pickle")))
        print(files)
        assert len(files) == (num_acs // ep_len1) + (num_acs // ep_len2)

        with open(files[0], "rb") as f:
            loaded_traj = pickle.load(f)
        assert len(loaded_traj["ob"]) == ep_len1
        assert np.allclose(loaded_traj["ob"][0], obs[0])
        assert np.allclose(loaded_traj["act"][0], action[0])

        with open(files[1], "rb") as f:
            loaded_traj = pickle.load(f)
        assert len(loaded_traj["ob"]) == ep_len2
        assert np.allclose(loaded_traj["ob"][0], obs[1])
        assert np.allclose(loaded_traj["act"][0], action[1])