浏览代码

don't try/except for control flow (#4251)

/MLA-1734-demo-provider
GitHub 4 年前
当前提交
2c64d623
共有 2 个文件被更改,包括 9 次插入13 次删除
  1. 18
      ml-agents/mlagents/trainers/ghost/trainer.py
  2. 4
      ml-agents/mlagents/trainers/trainer_controller.py

18
ml-agents/mlagents/trainers/ghost/trainer.py


# # Unity ML-Agents Toolkit
# ## ML-Agent Learning (Ghost Trainer)
from typing import Deque, Dict, List, cast
from collections import defaultdict
from typing import Deque, Dict, DefaultDict, List, cast
import numpy as np

self._internal_trajectory_queues: Dict[str, AgentManagerQueue[Trajectory]] = {}
self._internal_policy_queues: Dict[str, AgentManagerQueue[Policy]] = {}
self._team_to_name_to_policy_queue: Dict[
self._team_to_name_to_policy_queue: DefaultDict[
] = {}
] = defaultdict(dict)
self._name_to_parsed_behavior_id: Dict[str, BehaviorIdentifiers] = {}

"""
super().publish_policy_queue(policy_queue)
parsed_behavior_id = self._name_to_parsed_behavior_id[policy_queue.behavior_id]
try:
self._team_to_name_to_policy_queue[parsed_behavior_id.team_id][
parsed_behavior_id.brain_name
] = policy_queue
except KeyError:
self._team_to_name_to_policy_queue[parsed_behavior_id.team_id] = {
parsed_behavior_id.brain_name: policy_queue
}
self._team_to_name_to_policy_queue[parsed_behavior_id.team_id][
parsed_behavior_id.brain_name
] = policy_queue
if parsed_behavior_id.team_id == self.wrapped_trainer_team:
# With a future multiagent trainer, this will be indexed by 'role'
internal_policy_queue: AgentManagerQueue[Policy] = AgentManagerQueue(

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


parsed_behavior_id = BehaviorIdentifiers.from_name_behavior_id(name_behavior_id)
brain_name = parsed_behavior_id.brain_name
trainerthread = None
try:
if brain_name in self.trainers:
except KeyError:
else:
trainer = self.trainer_factory.generate(brain_name)
self.trainers[brain_name] = trainer
if trainer.threaded:

正在加载...
取消
保存