2020-05-25 10:26:57 +02:00
|
|
|
import gym
|
|
|
|
import pytest
|
|
|
|
|
2020-06-24 11:44:47 +02:00
|
|
|
import mujoco_maze
|
|
|
|
|
2020-05-25 10:26:57 +02:00
|
|
|
|
2020-06-29 18:38:02 +02:00
|
|
|
@pytest.mark.parametrize("maze_id", mujoco_maze.TaskRegistry.keys())
|
2020-05-25 10:26:57 +02:00
|
|
|
def test_ant_maze(maze_id):
|
2020-09-28 13:05:08 +02:00
|
|
|
if "Billiard" in maze_id:
|
2020-09-27 06:33:14 +02:00
|
|
|
return
|
2020-07-06 16:16:34 +02:00
|
|
|
for i in range(2):
|
|
|
|
env = gym.make(f"Ant{maze_id}-v{i}")
|
2020-09-21 06:27:41 +02:00
|
|
|
s0 = env.reset()
|
2020-07-06 16:16:34 +02:00
|
|
|
s, _, _, _ = env.step(env.action_space.sample())
|
2020-09-27 06:33:14 +02:00
|
|
|
if not env.unwrapped.has_extended_obs:
|
2020-09-21 06:27:41 +02:00
|
|
|
assert s0.shape == (30,)
|
|
|
|
assert s.shape == (30,)
|
2020-05-25 10:26:57 +02:00
|
|
|
|
|
|
|
|
2020-06-29 18:38:02 +02:00
|
|
|
@pytest.mark.parametrize("maze_id", mujoco_maze.TaskRegistry.keys())
|
2020-05-25 10:26:57 +02:00
|
|
|
def test_point_maze(maze_id):
|
2020-07-06 16:16:34 +02:00
|
|
|
for i in range(2):
|
|
|
|
env = gym.make(f"Point{maze_id}-v{i}")
|
2020-09-21 06:27:41 +02:00
|
|
|
s0 = env.reset()
|
2020-09-26 11:37:20 +02:00
|
|
|
s, r, _, _ = env.step(env.action_space.sample())
|
2020-09-27 06:33:14 +02:00
|
|
|
if not env.unwrapped.has_extended_obs:
|
2020-09-21 06:27:41 +02:00
|
|
|
assert s0.shape == (7,)
|
|
|
|
assert s.shape == (7,)
|
2020-09-27 06:33:14 +02:00
|
|
|
if env.unwrapped._observe_balls:
|
|
|
|
assert s0.shape == (10,)
|
|
|
|
assert s.shape == (10,)
|
2020-09-26 11:37:20 +02:00
|
|
|
if i == 0:
|
|
|
|
assert r != 0.0
|
|
|
|
else:
|
|
|
|
assert r == env.unwrapped._task.PENALTY
|
|
|
|
assert r < 0.0
|
|
|
|
|
|
|
|
|
2020-09-29 10:52:46 +02:00
|
|
|
@pytest.mark.parametrize("maze_id", ["2Rooms", "4Rooms", "Billiard"])
|
|
|
|
def test_subgoal_envs(maze_id):
|
|
|
|
env = gym.make(f"Point{maze_id}-v2")
|
|
|
|
s0 = env.reset()
|
|
|
|
s, r, _, _ = env.step(env.action_space.sample())
|
|
|
|
if not env.unwrapped.has_extended_obs:
|
|
|
|
assert s0.shape == (7,)
|
|
|
|
assert s.shape == (7,)
|
|
|
|
elif env.unwrapped._observe_balls:
|
|
|
|
assert s0.shape == (10,)
|
|
|
|
assert s.shape == (10,)
|
|
|
|
assert len(env.unwrapped._task.goals) > 1
|
|
|
|
|
|
|
|
|
2020-09-26 11:37:20 +02:00
|
|
|
@pytest.mark.parametrize("maze_id", mujoco_maze.TaskRegistry.keys())
|
|
|
|
def test_reacher_maze(maze_id):
|
2020-09-28 13:05:08 +02:00
|
|
|
for inhibited in ["Fall", "Push", "Block", "Billiard"]:
|
2020-09-26 11:37:20 +02:00
|
|
|
if inhibited in maze_id:
|
|
|
|
return
|
|
|
|
for i in range(2):
|
|
|
|
env = gym.make(f"Reacher{maze_id}-v{i}")
|
|
|
|
s0 = env.reset()
|
|
|
|
s, _, _, _ = env.step(env.action_space.sample())
|
2020-09-27 06:33:14 +02:00
|
|
|
if not env.unwrapped.has_extended_obs:
|
2020-09-26 11:37:20 +02:00
|
|
|
assert s0.shape == (9,)
|
|
|
|
assert s.shape == (9,)
|
2020-09-16 18:27:38 +02:00
|
|
|
|
|
|
|
|
2020-09-24 16:40:33 +02:00
|
|
|
@pytest.mark.parametrize("maze_id", mujoco_maze.TaskRegistry.keys())
|
|
|
|
def test_swimmer_maze(maze_id):
|
2020-09-28 13:05:08 +02:00
|
|
|
for inhibited in ["Fall", "Push", "Block", "Billiard"]:
|
2020-09-26 11:37:20 +02:00
|
|
|
if inhibited in maze_id:
|
|
|
|
return
|
2020-09-24 16:40:33 +02:00
|
|
|
for i in range(2):
|
|
|
|
env = gym.make(f"Swimmer{maze_id}-v{i}")
|
|
|
|
s0 = env.reset()
|
|
|
|
s, _, _, _ = env.step(env.action_space.sample())
|
2020-09-27 06:33:14 +02:00
|
|
|
if not env.unwrapped.has_extended_obs:
|
2020-09-24 16:40:33 +02:00
|
|
|
assert s0.shape == (11,)
|
|
|
|
assert s.shape == (11,)
|
|
|
|
|
|
|
|
|
2020-09-16 18:27:38 +02:00
|
|
|
@pytest.mark.parametrize("v", [0, 1])
|
|
|
|
def test_maze_args(v):
|
2020-09-27 06:33:14 +02:00
|
|
|
env = gym.make(f"PointTRoom-v{v}", task_kwargs={"goal": (-2.0, -3.0)})
|
2020-09-26 11:37:20 +02:00
|
|
|
assert env.reset().shape == (7,)
|
|
|
|
s, _, _, _ = env.step(env.action_space.sample())
|
|
|
|
assert s.shape == (7,)
|