浏览代码

Fix set_action_for_agent (#4691)

* fixes

* Update CHANGELOG.md

Co-authored-by: Chris Elion <chris.elion@unity3d.com>
/MLA-1734-demo-provider
GitHub 4 年前
当前提交
559e0ee5
共有 3 个文件被更改,包括 4 次插入3 次删除
  1. 1
      com.unity.ml-agents/CHANGELOG.md
  2. 4
      ml-agents-envs/mlagents_envs/base_env.py
  3. 2
      ml-agents-envs/mlagents_envs/environment.py

1
com.unity.ml-agents/CHANGELOG.md


### Minor Changes
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- `ActionSpec.validate_action()` now enforces that `UnityEnvironment.set_action_for_agent()` receives a 1D `np.array`.
### Bug Fixes
#### com.unity.ml-agents (C#)

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


return action
def _validate_action(
self, actions: np.ndarray, n_agents: int, name: str
self, actions: np.ndarray, n_agents: Optional[int], name: str
) -> np.ndarray:
"""
Validates that action has the correct action dim

_size = self.continuous_size
else:
_size = self.discrete_size
_expected_shape = (n_agents, _size)
_expected_shape = (n_agents, _size) if n_agents else (_size,)
if actions.shape != _expected_shape:
raise UnityActionException(
f"The behavior {name} needs an input of dimension "

2
ml-agents-envs/mlagents_envs/environment.py


return
action_spec = self._env_specs[behavior_name].action_spec
num_agents = len(self._env_state[behavior_name][0])
action = action_spec._validate_action(action, num_agents, behavior_name)
action = action_spec._validate_action(action, None, behavior_name)
if behavior_name not in self._env_actions:
self._env_actions[behavior_name] = action_spec.empty_action(num_agents)
try:

正在加载...
取消
保存