浏览代码

Fix Gym for ActionSpec

/develop/action-spec-gym
Ervin Teng 4 年前
当前提交
670e1bd6
共有 2 个文件被更改,包括 9 次插入9 次删除
  1. 10
      gym-unity/gym_unity/envs/__init__.py
  2. 8
      gym-unity/gym_unity/tests/test_gym.py

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


self._previous_decision_step = decision_steps
# Set action spaces
if self.group_spec.is_action_discrete():
branches = self.group_spec.discrete_action_branches
if self.group_spec.action_size == 1:
if self.group_spec.action_spec.is_action_discrete():
branches = self.group_spec.action_spec.discrete_action_branches
if self.group_spec.action_spec.discrete_action_size == 1:
self._action_space = spaces.Discrete(branches[0])
else:
if flatten_branched:

"The environment has a non-discrete action space. It will "
"not be flattened."
)
high = np.array([1] * self.group_spec.action_shape)
high = np.array([1] * self.group_spec.action_spec.continuous_action_size)
self._action_space = spaces.Box(-high, high, dtype=np.float32)
# Set observations space

action = self._flattener.lookup_action(action)
spec = self.group_spec
action = np.array(action).reshape((1, spec.action_size))
action = np.array(action).reshape((1, spec.action_spec.action_size))
self._env.set_actions(self.name, action)
self._env.step()

8
gym-unity/gym_unity/tests/test_gym.py


from gym_unity.envs import UnityToGymWrapper
from mlagents_envs.base_env import (
BehaviorSpec,
ActionType,
ActionSpec,
DecisionSteps,
TerminalSteps,
BehaviorMapping,

Creates a mock BrainParameters object with parameters.
"""
# Avoid using mutable object as default param
act_type = ActionType.DISCRETE
act_type = ActionType.CONTINUOUS
action_spec = ActionSpec(vector_action_space_size, ())
action_spec = ActionSpec(0, vector_action_space_size)
return BehaviorSpec(obs_shapes, act_type, vector_action_space_size)
return BehaviorSpec(obs_shapes, action_spec)
def create_mock_vector_steps(specs, num_agents=1, number_visual_observations=0):

正在加载...
取消
保存