An API standard for reinforcement learning with a diverse collection of reference environments
Gymnasium is a maintained fork of OpenAI’s Gym library. The Gymnasium interface is simple, pythonic, and capable of representing general RL problems, and has a migration guide for old Gym environments:
importgymnasiumasgym# Initialise the environmentenv=gym.make("LunarLander-v3",render_mode="human")# Reset the environment to generate the first observationobservation,info=env.reset(seed=42)for_inrange(1000):# this is where you would insert your policyaction=env.action_space.sample()# step (transition) through the environment with the action# receiving the next observation, reward and if the episode has terminated or truncatedobservation,reward,terminated,truncated,info=env.step(action)# If the episode has ended then we can reset to start a new episodeifterminatedortruncated:observation,info=env.reset()env.close()