vincentpierre
5 年前
当前提交
419611f4
共有 4 个文件被更改,包括 59 次插入 和 73 次删除
-
34ml-agents-envs/mlagents_envs/gym_to_unity_wrapper.py
-
1ml-agents-envs/setup.py
-
40ml-agents-envs/mlagents_envs/tests/test_gym_to_unity_wrapper.py
-
57ml-agents-envs/mlagents_envs/tests/test_gym_wrapper.py
|
|||
from mlagents_envs.gym_to_unity_wrapper import GymToUnityWrapper |
|||
from mlagents_envs.base_env import ActionType |
|||
import gym |
|||
|
|||
import pytest |
|||
|
|||
|
|||
GYM_ENVS = ["CartPole-v1", "MountainCar-v0"] |
|||
|
|||
|
|||
@pytest.mark.parametrize("name", GYM_ENVS, ids=GYM_ENVS) |
|||
def test_creation(name): |
|||
env = GymToUnityWrapper(gym.make(name), name) |
|||
env.close() |
|||
|
|||
|
|||
@pytest.mark.parametrize("name", GYM_ENVS, ids=GYM_ENVS) |
|||
def test_specs(name): |
|||
gym_env = gym.make(name) |
|||
env = GymToUnityWrapper(gym_env, name) |
|||
assert env.get_behavior_names()[0] == name |
|||
if isinstance(gym_env.action_space, gym.spaces.Box): |
|||
assert env.get_behavior_spec(name).action_type == ActionType.CONTINUOUS |
|||
elif isinstance(gym_env.action_space, gym.spaces.Discrete): |
|||
assert env.get_behavior_spec(name).action_type == ActionType.DISCRETE |
|||
else: |
|||
raise NotImplementedError("Test for this action space type not implemented") |
|||
env.close() |
|||
|
|||
|
|||
@pytest.mark.parametrize("name", GYM_ENVS, ids=GYM_ENVS) |
|||
def test_steps(name): |
|||
env = GymToUnityWrapper(gym.make(name), name) |
|||
spec = env.get_behavior_spec(name) |
|||
env.reset() |
|||
for _ in range(200): |
|||
d_steps, t_steps = env.get_steps(name) |
|||
env.set_actions(name, spec.create_empty_action(len(d_steps))) |
|||
env.step() |
|||
env.close() |
|
|||
from mlagents_envs.gym_to_unity_wrapper import GymToUnityWrapper |
|||
from mlagents_envs.base_env import ActionType |
|||
|
|||
try: |
|||
import gym |
|||
|
|||
_GYM_IMPORTED = True |
|||
except ImportError: |
|||
_GYM_IMPORTED = False |
|||
|
|||
import pytest |
|||
|
|||
GYM_ENVS = ["CartPole-v1", "MountainCar-v0"] |
|||
|
|||
|
|||
@pytest.mark.parametrize("name", GYM_ENVS, ids=GYM_ENVS) |
|||
def test_creation(name): |
|||
if not _GYM_IMPORTED: |
|||
raise RuntimeError( |
|||
"gym is not installed, gym required to test the GymToUnityWrapper" |
|||
) |
|||
env = GymToUnityWrapper(gym.make(name), name) |
|||
env.close() |
|||
|
|||
|
|||
@pytest.mark.parametrize("name", GYM_ENVS, ids=GYM_ENVS) |
|||
def test_specs(name): |
|||
if not _GYM_IMPORTED: |
|||
raise RuntimeError( |
|||
"gym is not installed, gym required to test the GymToUnityWrapper" |
|||
) |
|||
gym_env = gym.make(name) |
|||
env = GymToUnityWrapper(gym_env, name) |
|||
assert env.get_behavior_names()[0] == name |
|||
if isinstance(gym_env.action_space, gym.spaces.Box): |
|||
assert env.get_behavior_spec(name).action_type == ActionType.CONTINUOUS |
|||
elif isinstance(gym_env.action_space, gym.spaces.Discrete): |
|||
assert env.get_behavior_spec(name).action_type == ActionType.DISCRETE |
|||
else: |
|||
raise NotImplementedError("Test for this action space type not implemented") |
|||
env.close() |
|||
|
|||
|
|||
@pytest.mark.parametrize("name", GYM_ENVS, ids=GYM_ENVS) |
|||
def test_steps(name): |
|||
if not _GYM_IMPORTED: |
|||
raise RuntimeError( |
|||
"gym is not installed, gym required to test the GymToUnityWrapper" |
|||
) |
|||
env = GymToUnityWrapper(gym.make(name), name) |
|||
spec = env.get_behavior_spec(name) |
|||
env.reset() |
|||
for _ in range(200): |
|||
d_steps, t_steps = env.get_steps(name) |
|||
env.set_actions(name, spec.create_empty_action(len(d_steps))) |
|||
env.step() |
|||
env.close() |
撰写
预览
正在加载...
取消
保存
Reference in new issue