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})