13

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?

Bill
  • 10,323
  • 10
  • 62
  • 85
Gulzar
  • 23,452
  • 27
  • 113
  • 201

2 Answers2

14

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.

makons
  • 522
  • 1
  • 11
  • 27
7

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)
Bill
  • 10,323
  • 10
  • 62
  • 85
Gulzar
  • 23,452
  • 27
  • 113
  • 201