forked from facebookresearch/BenchMARL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_smacv2.py
104 lines (95 loc) · 3.25 KB
/
test_smacv2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import packaging
import pytest
import torchrl
from benchmarl.algorithms import algorithm_config_registry, MappoConfig, QmixConfig
from benchmarl.algorithms.common import AlgorithmConfig
from benchmarl.environments import Smacv2Task
from benchmarl.experiment import Experiment
from utils import _has_smacv2
@pytest.mark.skipif(not _has_smacv2, reason="SMACv2 not found")
class TestSmacv2:
@pytest.mark.parametrize("algo_config", algorithm_config_registry.values())
@pytest.mark.parametrize("task", [Smacv2Task.PROTOSS_5_VS_5])
def test_all_algos(
self, algo_config: AlgorithmConfig, task, experiment_config, mlp_sequence_config
):
if algo_config.supports_discrete_actions():
task = task.get_from_yaml()
experiment = Experiment(
algorithm_config=algo_config.get_from_yaml(),
model_config=mlp_sequence_config,
seed=0,
config=experiment_config,
task=task,
)
experiment.run()
else:
pytest.skip("No support for discrete actions")
@pytest.mark.parametrize("algo_config", [QmixConfig, MappoConfig])
@pytest.mark.parametrize(
"task",
[
Smacv2Task.PROTOSS_5_VS_5,
Smacv2Task.ZERG_5_VS_5,
Smacv2Task.TERRAN_5_VS_5,
],
)
def test_all_tasks(
self, algo_config: AlgorithmConfig, task, experiment_config, mlp_sequence_config
):
task = task.get_from_yaml()
experiment = Experiment(
algorithm_config=algo_config.get_from_yaml(),
model_config=mlp_sequence_config,
seed=0,
config=experiment_config,
task=task,
)
experiment.run()
@pytest.mark.parametrize("algo_config", [QmixConfig])
@pytest.mark.parametrize("task", [Smacv2Task.PROTOSS_5_VS_5])
def test_gnn(
self,
algo_config,
task,
experiment_config,
mlp_gnn_sequence_config,
):
task = task.get_from_yaml()
experiment = Experiment(
algorithm_config=algo_config.get_from_yaml(),
model_config=mlp_gnn_sequence_config,
critic_model_config=mlp_gnn_sequence_config,
seed=0,
config=experiment_config,
task=task,
)
experiment.run()
@pytest.mark.parametrize("algo_config", [QmixConfig])
@pytest.mark.parametrize("task", [Smacv2Task.PROTOSS_5_VS_5])
@pytest.mark.skipif(
packaging.version.parse(torchrl.__version__).local is None,
reason="gru model needs torchrl from github",
)
def test_gru(
self,
algo_config,
task,
experiment_config,
gru_mlp_sequence_config,
):
task = task.get_from_yaml()
experiment = Experiment(
algorithm_config=algo_config.get_from_yaml(),
model_config=gru_mlp_sequence_config,
critic_model_config=gru_mlp_sequence_config,
seed=0,
config=experiment_config,
task=task,
)
experiment.run()