浏览代码

add defaults to ActionTuple constructor

/develop/action-spec-gym
Andrew Cohen 4 年前
当前提交
3b5acb5c
共有 4 个文件被更改,包括 10 次插入8 次删除
  1. 10
      ml-agents-envs/mlagents_envs/base_env.py
  2. 4
      ml-agents/mlagents/trainers/env_manager.py
  3. 2
      ml-agents/mlagents/trainers/simple_env_manager.py
  4. 2
      ml-agents/mlagents/trainers/subprocess_env_manager.py

10
ml-agents-envs/mlagents_envs/base_env.py


respectively.
"""
def __init__(self, continuous: np.ndarray, discrete: np.ndarray):
if continuous.dtype != np.float32:
def __init__(
self,
continuous: Optional[np.ndarray] = None,
discrete: Optional[np.ndarray] = None,
):
if continuous is not None and continuous.dtype != np.float32:
if discrete.dtype != np.int32:
if discrete is not None and discrete.dtype != np.int32:
discrete = discrete.astype(np.int32, copy=False)
self._discrete = discrete

4
ml-agents/mlagents/trainers/env_manager.py


return len(step_infos)
@staticmethod
def action_buffers_from_numpy_dict(
action_dict: Dict[str, np.ndarray]
) -> ActionTuple:
def action_tuple_from_numpy_dict(action_dict: Dict[str, np.ndarray]) -> ActionTuple:
continuous: np.ndarray = np.array([], dtype=np.float32)
discrete: np.ndarray = np.array([], dtype=np.int32)
if "continuous_action" in action_dict:

2
ml-agents/mlagents/trainers/simple_env_manager.py


self.previous_all_action_info = all_action_info
for brain_name, action_info in all_action_info.items():
_action = EnvManager.action_buffers_from_numpy_dict(action_info.action)
_action = EnvManager.action_tuple_from_numpy_dict(action_info.action)
self.env.set_actions(brain_name, _action)
self.env.step()
all_step_result = self._generate_all_results()

2
ml-agents/mlagents/trainers/subprocess_env_manager.py


all_action_info = req.payload
for brain_name, action_info in all_action_info.items():
if len(action_info.action) != 0:
_action = EnvManager.action_buffers_from_numpy_dict(
_action = EnvManager.action_tuple_from_numpy_dict(
action_info.action
)
env.set_actions(brain_name, _action)

正在加载...
取消
保存