Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

40 行
1.3 KiB

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