The Cart Pole Environment#

In this project we learn how to use gymnasium’s Cart Pole. The cart pole environment simulates a pole mounted on top of a car. If the car moves (and even if it does not move), the pole most likely will fall down. But if we control the car’s movements in the correct way, then we might be able to balance the pole.

Task: Read about the cart pole environment. Describe the set of states and the set of actions and the set of rewards. When does an episode end?

Solution:

# your answer

Task: Create a cart pole environment object and run one episode by choosing actions randomly. Display episode length. Don’t try to render the environment. Rendering will be discussed below.

Solution:

# your solution

Rendering via Env.render() does not work in Jupyter. But we may record a video and then show the video in the notebook. This workflow requires pygame and moviepy to be installed.

Task: Have a look at Gymnasium doc’s Recording Agents and at IPython.display.Video. Then record one episode and show the video in the notebook.

Solution:

# your solution