ml.tasks.environments.utils

Utilities for working with environments.

This is analogous to ml.tasks.datasets.utils, but for environments instead of datasets. It’s useful when developing an environment because you can just add a small code snippet to the bottom of your file like so:

if __name__ == "__main__":
    from ml.tasks.environments.utils import test_environment

    test_environment(MyEnvironment(), save_path="env.mp4")

This will dump a video of your environment running for a few steps, which you can then inspect to make sure everything is working as expected.

ml.tasks.environments.utils.test_environment(env: Environment, *, max_steps: int = 100, save_path: str | Path | None = None, writer: Literal['ffmpeg', 'matplotlib', 'av', 'opencv'] = 'ffmpeg') None[source]

Samples a clip from the environment using a random policy.

Parameters:
  • env – The environment to test

  • max_steps – Maximum number of steps to loop through

  • save_path – Where to save the recorded clip

  • writer – The video writer to use