浏览代码

passing all tests locally

/asymm-envs
Andrew Cohen 5 年前
当前提交
579bbd88
共有 5 个文件被更改,包括 36 次插入18 次删除
  1. 2
      ml-agents/mlagents/trainers/ghost/trainer.py
  2. 1
      ml-agents/mlagents/trainers/stats.py
  3. 36
      ml-agents/mlagents/trainers/tests/test_ghost.py
  4. 7
      ml-agents/mlagents/trainers/tests/test_stats.py
  5. 8
      ml-agents/mlagents/trainers/tests/test_trainer_util.py

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


self.current_policy_snapshot = weights
self.trainer.add_policy(parsed_behavior_id, policy)
self._save_snapshot(policy) # Need to save after trainer initializes policy
self.learning_team = team_id
self.learning_team = self.controller.get_learning_team(self.ghost_step)
self.wrapped_trainer_team = team_id
else:
# for saving/swapping snapshots

1
ml-agents/mlagents/trainers/stats.py


class StatsPropertyType(Enum):
HYPERPARAMETERS = "hyperparameters"
SELF_PLAY = "selfplay"
SELF_PLAY_TEAM = "selfplayteam"
class StatsWriter(abc.ABC):

36
ml-agents/mlagents/trainers/tests/test_ghost.py


import yaml
from mlagents.trainers.ghost.trainer import GhostTrainer
from mlagents.trainers.ghost.controller import GhostController
from mlagents.trainers.behavior_id_utils import BehaviorIdentifiers
from mlagents.trainers.behavior_id_utils import BehaviorIdentifiers
from mlagents.trainers.tests import mock_brain as mb
from mlagents.trainers.tests.test_trajectory import make_fake_trajectory

dummy_config["summary_path"] = "./summaries/test_trainer_summary"
dummy_config["model_path"] = "./models/test_trainer_models/TestModel"
ppo_trainer = PPOTrainer(brain_name, 0, dummy_config, True, False, 0, "0")
trainer = GhostTrainer(ppo_trainer, brain_name, 0, dummy_config, True, "0")
controller = GhostController(100)
trainer = GhostTrainer(
ppo_trainer, brain_name, controller, 0, dummy_config, True, "0"
)
trainer.add_policy(brain_params_team0.brain_name, policy)
parsed_behavior_id0 = BehaviorIdentifiers.from_name_behavior_id(
brain_params_team0.brain_name
)
trainer.add_policy(parsed_behavior_id0, policy)
trainer.add_policy(brain_params_team1.brain_name, policy)
parsed_behavior_id1 = BehaviorIdentifiers.from_name_behavior_id(
brain_params_team1.brain_name
)
trainer.add_policy(parsed_behavior_id1, policy)
trajectory_queue1 = AgentManagerQueue(brain_params_team1.brain_name)
trainer.subscribe_trajectory_queue(trajectory_queue1)

vector_action_space_type=0,
)
brain_name = BehaviorIdentifiers.from_name_behavior_id(
parsed_behavior_id0 = BehaviorIdentifiers.from_name_behavior_id(
).brain_name
)
brain_name = parsed_behavior_id0.brain_name
brain_params_team1 = BrainParameters(
brain_name="test_brain?team=1",

dummy_config["summary_path"] = "./summaries/test_trainer_summary"
dummy_config["model_path"] = "./models/test_trainer_models/TestModel"
ppo_trainer = PPOTrainer(brain_name, 0, dummy_config, True, False, 0, "0")
trainer = GhostTrainer(ppo_trainer, brain_name, 0, dummy_config, True, "0")
controller = GhostController(100)
trainer = GhostTrainer(
ppo_trainer, brain_name, controller, 0, dummy_config, True, "0"
)
trainer.add_policy(brain_params_team0.brain_name, policy)
trainer.add_policy(parsed_behavior_id0, policy)
trainer.add_policy(brain_params_team1.brain_name, policy)
parsed_behavior_id1 = BehaviorIdentifiers.from_name_behavior_id(
brain_params_team1.brain_name
)
trainer.add_policy(parsed_behavior_id1, policy)
policy_queue1 = AgentManagerQueue(brain_params_team1.brain_name)
trainer.publish_policy_queue(policy_queue1)

7
ml-agents/mlagents/trainers/tests/test_stats.py


category = "category1"
console_writer = ConsoleWriter()
console_writer.add_property(category, StatsPropertyType.SELF_PLAY, True)
console_writer.add_property(category, StatsPropertyType.SELF_PLAY_TEAM, 1)
statssummary1 = StatsSummary(mean=1.0, std=1.0, num=1)
console_writer.write_stats(
category,

"Self-play/ELO": statssummary1,
"Self-play/Mean Opponent ELO": statssummary1,
"Self-play/Std Opponent ELO": statssummary1,
},
10,
)

)
self.assertIn(
"category1 Team 1: ELO: 1.000. Mean Opponent ELO: 1.000. Std Opponent ELO: 1.000.",
cm.output[1],
)

8
ml-agents/mlagents/trainers/tests/test_trainer_util.py


keep_checkpoints=keep_checkpoints,
train_model=train_model,
load_model=load_model,
ghost_swap=100,
seed=seed,
)
trainers = {}

keep_checkpoints=keep_checkpoints,
train_model=train_model,
load_model=load_model,
ghost_swap=100,
seed=seed,
)
trainers = {}

keep_checkpoints = 1
train_model = True
load_model = False
ghost_swap = 100
seed = 11
bad_config = dummy_bad_config
BrainParametersMock.return_value.brain_name = "testbrain"

keep_checkpoints=keep_checkpoints,
train_model=train_model,
load_model=load_model,
ghost_swap=ghost_swap,
seed=seed,
)
trainers = {}

keep_checkpoints=keep_checkpoints,
train_model=train_model,
load_model=load_model,
ghost_swap=ghost_swap,
seed=seed,
)
trainers = {}

keep_checkpoints=keep_checkpoints,
train_model=train_model,
load_model=load_model,
ghost_swap=ghost_swap,
seed=seed,
)
trainers = {}

keep_checkpoints=1,
train_model=True,
load_model=False,
ghost_swap=100,
seed=42,
)
trainer_factory.generate(brain_parameters.brain_name)

keep_checkpoints=1,
train_model=True,
load_model=False,
ghost_swap=100,
seed=42,
)
with pytest.raises(TrainerConfigError):

正在加载...
取消
保存