浏览代码

fix llapi and gym yamato (#4709)

/fix-conflict-base-env
GitHub 4 年前
当前提交
f70d89aa
共有 2 个文件被更改,包括 10 次插入22 次删除
  1. 10
      gym-unity/gym_unity/envs/__init__.py
  2. 22
      ml-agents/tests/yamato/scripts/run_llapi.py

10
gym-unity/gym_unity/envs/__init__.py


import gym
from gym import error, spaces
from mlagents_envs.base_env import BaseEnv
from mlagents_envs.base_env import ActionTuple, BaseEnv
from mlagents_envs.base_env import DecisionSteps, TerminalSteps
from mlagents_envs import logging_util

action = self._flattener.lookup_action(action)
action = np.array(action).reshape((1, self.action_size))
self._env.set_actions(self.name, action)
action_tuple = ActionTuple()
if self.group_spec.action_spec.is_continuous():
action_tuple.add_continuous(action)
else:
action_tuple.add_discrete(action)
self._env.set_actions(self.name, action_tuple)
self._env.step()
decision_step, terminal_step = self._env.get_steps(self.name)

22
ml-agents/tests/yamato/scripts/run_llapi.py


import argparse
import numpy as np
from mlagents_envs.environment import UnityEnvironment
from mlagents_envs.side_channel.engine_configuration_channel import (

episode_rewards = 0
tracked_agent = -1
while not done:
if group_spec.action_spec.is_continuous():
action = np.random.randn(
len(decision_steps), group_spec.action_spec.continuous_size
)
elif group_spec.action_spec.is_discrete():
branch_size = group_spec.action_spec.discrete_branches
action = np.column_stack(
[
np.random.randint(
0, branch_size[i], size=(len(decision_steps))
)
for i in range(len(branch_size))
]
)
else:
# Should never happen
action = None
action_tuple = group_spec.action_spec.random_action(len(decision_steps))
env.set_actions(group_name, action)
env.set_actions(group_name, action_tuple)
env.step()
decision_steps, terminal_steps = env.get_steps(group_name)
done = False

正在加载...
取消
保存