コード例 #1
0
    def test_vecnormalize(self):
        """
        Tests working of the VecNormalize wrapper
        """
        env = VectorEnv("CartPole-v1", 2)
        env = VecNormalize(
            env,
            norm_obs=True,
            norm_reward=True,
            clip_reward=1.0,
        )
        env.reset()
        _, rewards, _, _ = env.step(env.sample())
        env.close()

        assert np.all(-1.0 <= rewards)
        assert np.all(1.0 >= rewards)
コード例 #2
0
    def test_vecmonitor(self):
        """
        Tests working of the VecMonitor wrapper
        """
        env = VectorEnv("CartPole-v1", 2)
        env = VecMonitor(env, history_length=1)

        env.reset()
        _, _, _, info = env.step(env.sample())
        env.close()

        dones = [0, 0]
        while not dones[0]:
            _, _, dones, infos = env.step(env.sample())

        info = infos[0]["episode"]

        assert info["Episode Rewards"]
        assert info["Episode Length"]
        assert info["Time taken"]