6

I know env=gym.make('CartPole-v0') is of type gym.wrappers.time_limit.TimeLimit

And I also know env is an "instance" of the class cartpole.py. My question is how, by just giving the name 'CartPole-v0', I got the access to the cartpole.py class. Where is that process implemented? I was trying to look for it on the gym folder from the site-package folder but I couldn't find/understand where that process takes place. I'm not sure if my statements above are accurate, I'm asking this question to understand the process behind the execution of gym.make('CartPole-v0') and of any topic related to it in order to learn more about coding in general. My guess is that I am misunderstanding something

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Diego Orellana
  • 994
  • 1
  • 9
  • 20

1 Answers1

4

https://github.com/openai/gym/blob/e689f93a425d97489e590bba0a7d4518de0dcc03/gym/envs/__init__.py#L53-L58

As you can see in this line in __init__.py of gym.envs module, the environment is registered with all other environments. The entry point tells gym what python class to use when this version of environment is to be used. Along with that you can pass other key-worded arguements to the environment constructor.

gym.make at its core calls the constructor corresponding to the environment id as seen in these lines, along with some additional steps.

https://github.com/openai/gym/blob/e689f93a425d97489e590bba0a7d4518de0dcc03/gym/envs/registration.py#L85-L86

Joy Chopra
  • 120
  • 1
  • 2
  • 11