浏览代码

rename create empty to empty action

/develop/action-spec-gym
Andrew Cohen 4 年前
当前提交
c745bdd8
共有 4 个文件被更改,包括 12 次插入12 次删除
  1. 2
      ml-agents-envs/mlagents_envs/base_env.py
  2. 4
      ml-agents-envs/mlagents_envs/environment.py
  3. 6
      ml-agents-envs/mlagents_envs/tests/test_envs.py
  4. 12
      ml-agents-envs/mlagents_envs/tests/test_steps.py

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


"""
return len(self.discrete_branches)
def create_empty(self, n_agents: int) -> np.ndarray:
def empty_action(self, n_agents: int) -> np.ndarray:
"""
Generates a numpy array corresponding to an empty action (all zeros)
for a number of agents.

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


n_agents = len(self._env_state[group_name][0])
self._env_actions[group_name] = self._env_specs[
group_name
].action_spec.create_empty(n_agents)
].action_spec.empty_action(n_agents)
step_input = self._generate_step_input(self._env_actions)
with hierarchical_timer("communicator.exchange"):
outputs = self._communicator.exchange(step_input)

num_agents = len(self._env_state[behavior_name][0])
action = action_spec._validate_action(action, num_agents, behavior_name)
if behavior_name not in self._env_actions:
self._env_actions[behavior_name] = action_spec.create_empty(num_agents)
self._env_actions[behavior_name] = action_spec.empty_action(num_agents)
try:
index = np.where(self._env_state[behavior_name][0].agent_id == agent_id)[0][
0

6
ml-agents-envs/mlagents_envs/tests/test_envs.py


env.step()
decision_steps, terminal_steps = env.get_steps("RealFakeBrain")
n_agents = len(decision_steps)
env.set_actions("RealFakeBrain", spec.action_spec.create_empty(n_agents))
env.set_actions("RealFakeBrain", spec.action_spec.empty_action(n_agents))
env.set_actions("RealFakeBrain", spec.action_spec.create_empty(n_agents - 1))
env.set_actions("RealFakeBrain", spec.action_spec.empty_action(n_agents - 1))
env.set_actions("RealFakeBrain", spec.action_spec.create_empty(n_agents) - 1)
env.set_actions("RealFakeBrain", spec.action_spec.empty_action(n_agents) - 1)
env.step()
env.close()

12
ml-agents-envs/mlagents_envs/tests/test_steps.py


assert specs.discrete_branches == ()
assert specs.discrete_size == 0
assert specs.continuous_size == 3
assert specs.create_empty(5).shape == (5, 3)
assert specs.create_empty(5).dtype == np.float32
assert specs.empty_action(5).shape == (5, 3)
assert specs.empty_action(5).dtype == np.float32
assert specs.create_empty(5).shape == (5, 1)
assert specs.create_empty(5).dtype == np.int32
assert specs.empty_action(5).shape == (5, 1)
assert specs.empty_action(5).dtype == np.int32
def test_action_generator():

zero_action = specs.create_empty(4)
zero_action = specs.empty_action(4)
assert np.array_equal(zero_action, np.zeros((4, action_len), dtype=np.float32))
random_action = specs.random_action(4)
assert random_action.dtype == np.float32

# Discrete
action_shape = (10, 20, 30)
specs = ActionSpec.create_discrete(action_shape)
zero_action = specs.create_empty(4)
zero_action = specs.empty_action(4)
assert np.array_equal(zero_action, np.zeros((4, len(action_shape)), dtype=np.int32))
random_action = specs.random_action(4)

正在加载...
取消
保存