Make a GIF of an episode in a Gymnasium environment.
The algorithms of bitrl train on Gymnasium environments that run on the
bitrl-rest-api server. This script renders an episode of what they learned,
in two ways:
- with --policy FILE, it plays the policy that MaxTabularPolicy::save wrote,
a state and an action per row, for environments with discrete states such
as FrozenLake and CliffWalking;
- with --actions FILE, it replays the actions an example wrote, one per row,
as numbers separated by commas; a first line "# seed N" gives the seed the
episode was reset with. The environment is the same Gymnasium version, so
the episode is the same.
Usage:
python episode_gif.py --env FrozenLake-v1 --kwargs is_slippery=False --policy policy.csv --out run.gif
python episode_gif.py --env CartPole-v1 --actions episode.csv --out run.gif --title "REINFORCE"
Needs gymnasium, with pygame for the pictures, imageio and Pillow.