Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass arguments to openai-gym environments upon init

Tags:

openai-gym

Following this (unreadable) forum post, I thought it was fitting to post it up on stack overflow for future generations who search for it.

How to pass arguments for gym environments on init?

like image 842
Gulzar Avatar asked Jan 18 '19 18:01

Gulzar


People also ask

How do you cite the OpenAI gym?

Citation in Harvard styleBrockman, G. et al., 2016. Openai gym. arXiv preprint arXiv:1606.01540.

What is observation space in OpenAI gym?

The observation_space defines the structure as well as the legitimate values for the observation of the state of the environment. The observation can be different things for different environments.

Does OpenAI gym work on Windows?

Even though it can be installed on Windows using Conda or PIP, it cannot be visualized on Windows. If you run it on a headless server (such as a virtual machine on the cloud), then it needs PyVirtualDisplay, which doesn't work on Windows either. Therefore, playing the OpenAI Gym on Windows is inconvenient.


2 Answers

In the meantime the support for arguments in gym.make has been implemented, so you can pass key word arguments to make right after environment name:

your_env = gym.make('YourEnv', some_kwarg=your_vars)

The gym version that I'm running is 0.12.4.

UPDATE: This is supported from version 0.10.10.. Reference. Thanks @Wojciech.

like image 56
makons Avatar answered Oct 22 '22 18:10

makons


Method 1 - Use the built in register functionality:

Re-register the environment with a new name

For example:

'Blackjack-natural-v0'

Instead of the original

'Blackjack-v0'

First you need to import the register function:

from gym.envs.registration import register

Then you use the register function like this:

register( id='Blackjack-natural-v0', entry_point='gym.envs.toy_text:BlackjackEnv', kwargs={'natural': True} )

Method 2 - Add an extra method to your env:

If you can just call another init method after gym.make, then you can just do:

your_env = gym.make("YourEnv")
your_env.env.your_init(your_vars)
like image 42
Gulzar Avatar answered Oct 22 '22 18:10

Gulzar