Skip to content
Harish Rajagopal edited this page Nov 24, 2021 · 9 revisions

How do I modify an environment to make it easier to learn?

The short answer is: don't. Environments are intended to have various levels of difficulty, in order to benchmark the ability of reinforcement learning agents to solve them. Many of the environments are beyond the current state of the art, so don't expect to solve all of them. (If you do, please apply).

If you want to experiment with a variant of an environment that behaves differently, you should give it a new name so that you won't erroneously compare your agent running on an easy variant to someone else's agent running on the original environment. For instance, the MountainCar environment is hard partly because there's a limit of 200 timesteps after which it resets to the beginning. Successful agents must solve it in less than 200 timesteps. For testing purposes, you could make a new environment MountainCarMyEasyVersion-v0 with different parameters by adapting one of the calls to register found in gym/gym/envs/__init__.py:

gym.envs.register(
    id='MountainCarMyEasyVersion-v0',
    entry_point='gym.envs.classic_control:MountainCarEnv',
    max_episode_steps=250,      # MountainCar-v0 uses 200
    reward_threshold=-110.0,
)
env = gym.make('MountainCarMyEasyVersion-v0')

Because these environment names are only known to your code, you won't be able to upload it to the scoreboard.

How do I export the run to a video file?

In your agent, import:

from gym import wrappers
from time import time # just to have timestamps in the files

Then, insert a wrapper call after you make the env.

env = gym.make(ENV_NAME)
env = wrappers.RecordVideo(env, './videos/' + str(time()) + '/')

This will save .mp4 files to ./videos/1234/something.mp4