From 0b08a41610580a26950c4437bc5b2cbc76070dd1 Mon Sep 17 00:00:00 2001 From: Minghao Zhang <37171450+Mehooz@users.noreply.github.com> Date: Thu, 2 Apr 2020 08:49:19 +0800 Subject: [PATCH] move mujoco to examples (#12) * move mujoco to examples * fix the import mujoco bug * flake8 * flake8 * rm __init__.py --- examples/mujoco/__init__.py | 0 .../env => examples}/mujoco/assets/point.xml | 0 .../env => examples}/mujoco/maze_env_utils.py | 0 {tianshou/env => examples}/mujoco/point.py | 0 .../env => examples}/mujoco/point_maze_env.py | 0 examples/mujoco/register.py | 27 +++++++++++++++++++ examples/point_maze_td3.py | 2 ++ tianshou/env/__init__.py | 2 -- tianshou/env/mujoco/__init__.py | 25 ----------------- 9 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 examples/mujoco/__init__.py rename {tianshou/env => examples}/mujoco/assets/point.xml (100%) rename {tianshou/env => examples}/mujoco/maze_env_utils.py (100%) rename {tianshou/env => examples}/mujoco/point.py (100%) rename {tianshou/env => examples}/mujoco/point_maze_env.py (100%) create mode 100644 examples/mujoco/register.py delete mode 100644 tianshou/env/mujoco/__init__.py diff --git a/examples/mujoco/__init__.py b/examples/mujoco/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tianshou/env/mujoco/assets/point.xml b/examples/mujoco/assets/point.xml similarity index 100% rename from tianshou/env/mujoco/assets/point.xml rename to examples/mujoco/assets/point.xml diff --git a/tianshou/env/mujoco/maze_env_utils.py b/examples/mujoco/maze_env_utils.py similarity index 100% rename from tianshou/env/mujoco/maze_env_utils.py rename to examples/mujoco/maze_env_utils.py diff --git a/tianshou/env/mujoco/point.py b/examples/mujoco/point.py similarity index 100% rename from tianshou/env/mujoco/point.py rename to examples/mujoco/point.py diff --git a/tianshou/env/mujoco/point_maze_env.py b/examples/mujoco/point_maze_env.py similarity index 100% rename from tianshou/env/mujoco/point_maze_env.py rename to examples/mujoco/point_maze_env.py diff --git a/examples/mujoco/register.py b/examples/mujoco/register.py new file mode 100644 index 0000000..82acac2 --- /dev/null +++ b/examples/mujoco/register.py @@ -0,0 +1,27 @@ +from gym.envs.registration import register + + +def reg(): + register( + id='PointMaze-v0', + entry_point='mujoco.point_maze_env:PointMazeEnv', + kwargs={ + "maze_size_scaling": 4, + "maze_id": "Maze2", + "maze_height": 0.5, + "manual_collision": True, + "goal": (1, 3), + } + ) + + register( + id='PointMaze-v1', + entry_point='mujoco.point_maze_env:PointMazeEnv', + kwargs={ + "maze_size_scaling": 2, + "maze_id": "Maze2", + "maze_height": 0.5, + "manual_collision": True, + "goal": (1, 3), + } + ) diff --git a/examples/point_maze_td3.py b/examples/point_maze_td3.py index e723518..5475921 100644 --- a/examples/point_maze_td3.py +++ b/examples/point_maze_td3.py @@ -10,6 +10,7 @@ from tianshou.trainer import offpolicy_trainer from tianshou.data import Collector, ReplayBuffer from tianshou.env import VectorEnv, SubprocVectorEnv from continuous_net import Actor, Critic +from mujoco.register import reg def get_args(): @@ -44,6 +45,7 @@ def get_args(): def test_td3(args=get_args()): + reg() env = gym.make(args.task) args.state_shape = env.observation_space.shape or env.observation_space.n args.action_shape = env.action_space.shape or env.action_space.n diff --git a/tianshou/env/__init__.py b/tianshou/env/__init__.py index 878c800..81f2014 100644 --- a/tianshou/env/__init__.py +++ b/tianshou/env/__init__.py @@ -2,10 +2,8 @@ from tianshou.env.utils import CloudpickleWrapper from tianshou.env.common import EnvWrapper, FrameStack from tianshou.env.vecenv import BaseVectorEnv, VectorEnv, \ SubprocVectorEnv, RayVectorEnv -from tianshou.env import mujoco __all__ = [ - 'mujoco', 'EnvWrapper', 'FrameStack', 'BaseVectorEnv', diff --git a/tianshou/env/mujoco/__init__.py b/tianshou/env/mujoco/__init__.py deleted file mode 100644 index 2e52e12..0000000 --- a/tianshou/env/mujoco/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -from gym.envs.registration import register - -register( - id='PointMaze-v0', - entry_point='tianshou.env.mujoco.point_maze_env:PointMazeEnv', - kwargs={ - "maze_size_scaling": 4, - "maze_id": "Maze2", - "maze_height": 0.5, - "manual_collision": True, - "goal": (1, 3), - } -) - -register( - id='PointMaze-v1', - entry_point='tianshou.env.mujoco.point_maze_env:PointMazeEnv', - kwargs={ - "maze_size_scaling": 2, - "maze_id": "Maze2", - "maze_height": 0.5, - "manual_collision": True, - "goal": (1, 3), - } -)