浏览代码

Add __eq__ and __str__ to ActionSpec

/develop/action-spec-gym
Andrew Cohen 4 年前
当前提交
b47327a9
共有 2 个文件被更改,包括 12 次插入18 次删除
  1. 9
      ml-agents-envs/mlagents_envs/base_env.py
  2. 21
      ml-agents/mlagents/trainers/demo_loader.py

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


num_continuous_actions: int
discrete_branch_sizes: Tuple[int, ...]
def __eq__(self, other):
return (
self.continuous_size == other.continuous_size
and self.discrete_branches == other.discrete_branches
)
def __str__(self):
return f"Continuous: {self.continuous_size}, Discrete: {self.discrete_branches}"
# For backwards compatibility
def is_discrete(self) -> bool:
"""

21
ml-agents/mlagents/trainers/demo_loader.py


demo_buffer = make_demo_buffer(info_action_pair, behavior_spec, sequence_length)
if expected_behavior_spec:
# check action dimensions in demonstration match
if (
behavior_spec.action_spec.continuous_size
!= expected_behavior_spec.action_spec.continuous_size
):
if behavior_spec.action_spec != expected_behavior_spec.action_spec:
"The continuous action dimensions {} in demonstration do not match the policy's {}.".format(
behavior_spec.action_spec.continuous_size,
expected_behavior_spec.action_spec.continuous_size,
)
)
if (
behavior_spec.action_spec.discrete_branches
!= expected_behavior_spec.action_spec.discrete_branches
):
raise RuntimeError(
"The discrete action dimensions {} in demonstration do not match the policy's {}.".format(
behavior_spec.action_spec.discrete_branches,
expected_behavior_spec.action_spec.discrete_branches,
"The action spaces {} in demonstration do not match the policy's {}.".format(
behavior_spec.action_spec, expected_behavior_spec.action_spec
)
)
# check observations match

正在加载...
取消
保存