Gymnasium Library in Reinforcement Learning
Sources:
- --> Gymnasium github repo
- --> Documentation
Gymnasium is the successsor of the famous OpenAI Gym library. It's highly recommended to move to gymnasium since gym is not being maintained.
Gymnasium is maintained by the Farama Foundation, an open-Sources nonprofit foundation.
Install
On Linux:
1 | pip install gymnasium |
Tested on Ubuntu22.04 X86_64 with python=3.9
.
This does not include dependencies for all families of environments. According to your requirement, you may need to install dependencies for one family like pip install "gymnasium[atari]"
or use pip install "gymnasium[all]"
.
Customize
Make your own custom environment
https://gymnasium.farama.org/environments/box2d/car_racing/
https://gymnasium.farama.org/_modules/gymnasium/utils/play/
Flappybird
1 | conda create -n flappy_bird python==3.11 # Must be this version |
Scripts
Box2D
For box2d
environments, we must also install:
1 | pip install gymnasium[box2d] |
CarRacing
To play:
1 | git clone [email protected]:Farama-Foundation/Gymnasium.git |
Atari
For Atari environments, we must also install:
1 | pip install "gymnasium[atari, accept-rom-license]" |
Errors
OpenGL error: when running
1
python gymnasium/envs/box2d/car_racing.py
The output is
1
2
3
4
5
6
7libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 149 (GLX)
Minor opcode of failed request: 3 (X_GLXCreateContext)
Value in failed request: 0x0
Serial number of failed request: 153This problem occurs randomly. I can successfully run the experiment for one day and meet this error the next day with not any conguguration changed.
The solution is simple:
1
conda install -c conda-forge libffi
Works on my Ubuntu22.04 x86_64 Python=3.10 environment.
Can't create Atari environment:
1
gymnasium.error.NamespaceNotFound: Namespace ALE not found. Have you installed the proper package for ALE?
Solution: There seems sth wrong with gymnasium. We have to use gym instead of gymnasium, and
1
pip install "gym[atari, accept-rom-license]"
Run:
1
2
3
4import gym # or "import gymnasium as gym"
if __name__ == '__main__':
env = gym.make("ALE/Breakout-v5")The output is
1
2A.L.E: Arcade Learning Environment (version 0.8.1+53f58b7)
[Powered by Stella]