1

As a learning exercise to figure out how to use a custom Gym environment with rllib, I've set out to produce the simplest example possible of training against GymGo. So there's a way to register a gym env with rllib, but I'm going around in circles.

This is as far as I've gotten:

#!/usr/bin/env python

import ray
import gym

from ray import tune
from ray.rllib.agents.ppo import PPOTrainer
from ray.tune.registry import register_env

ray.init()

def env_creator(env_name):
    from custom_gym.envs.gym_go import gym_go as env #THIS DOESNT WORK
    return env


env = env_creator('go-v0')
tune.register_env('goEnv', lambda: config, env(config))
tune.run(PPOTrainer, config={"env": "goEnv", "num_workers":18})
$ python3 raytest2.py
Traceback (most recent call last):
  File "raytest2.py", line 17, in <module>
    env = env_creator('go-v0')
  File "raytest2.py", line 13, in env_creator
    from custom_gym.envs.gym_go import gym_go as env
ModuleNotFoundError: No module named 'custom_gym'

Any feedback would be greatly appreciated!

UPDATE: This appears to be an improvement, but more issues to work out

import ray
from ray import tune
from ray.rllib.agents.ppo import PPOTrainer
from ray.tune.registry import register_env

ray.init()

def create_my_env():
  import gym
  return gym.make('gym_go:go-v0', size=7, reward_method='real')

env_creator = lambda config: create_my_env()
tune.register_env('go-v0', env_creator)
tune.run(PPOTrainer, config={"env": "go-v0", "num_workers":18})
  • You did not define custom_gym anywhere. Did you mean to use just gym? Or to modify the default gym setup and assign it to custom_gym? – bobmcn Apr 15 '20 at 21:55
  • @bobmcn I was using [this post] (https://stackoverflow.com/questions/58551029/rllib-use-custom-registered-environments). I am a bit baffled about where custom_gym came from. In any case I haven't seen a really good example of the use of tune.register_env. I also feel like I'm missing a few other pieces. – orange.kangaroo Apr 16 '20 at 12:07
  • Just to clarify, I'm trying to figure out how to use a 3rd party Gym environment, with Gym + Ray – orange.kangaroo Apr 16 '20 at 12:30

0 Answers0