forked from facebookresearch/BenchMARL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
130 lines (114 loc) · 4.08 KB
/
conftest.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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 pytest
import torch_geometric.nn.conv
from benchmarl.experiment import ExperimentConfig
from benchmarl.models import CnnConfig, GnnConfig, GruConfig, LstmConfig, MlpConfig
from benchmarl.models.common import ModelConfig, SequenceModelConfig
from torch import nn
@pytest.fixture
def experiment_config(tmp_path) -> ExperimentConfig:
save_dir = tmp_path
save_dir.mkdir(exist_ok=True)
experiment_config: ExperimentConfig = ExperimentConfig.get_from_yaml()
experiment_config.save_folder = str(save_dir)
experiment_config.max_n_iters = 3
experiment_config.on_policy_n_minibatch_iters = 1
experiment_config.on_policy_minibatch_size = 2
experiment_config.on_policy_collected_frames_per_batch = (
experiment_config.off_policy_collected_frames_per_batch
) = 100
experiment_config.on_policy_n_envs_per_worker = (
experiment_config.off_policy_n_envs_per_worker
) = 2
experiment_config.off_policy_n_optimizer_steps = 2
experiment_config.off_policy_train_batch_size = 3
experiment_config.off_policy_memory_size = 200
experiment_config.evaluation = True
experiment_config.render = True
experiment_config.evaluation_episodes = 2
experiment_config.evaluation_interval = 500
experiment_config.loggers = ["csv"]
experiment_config.create_json = True
experiment_config.checkpoint_interval = 100
return experiment_config
@pytest.fixture
def mlp_sequence_config() -> ModelConfig:
return SequenceModelConfig(
model_configs=[
MlpConfig(num_cells=[8], activation_class=nn.Tanh, layer_class=nn.Linear),
MlpConfig(num_cells=[4], activation_class=nn.Tanh, layer_class=nn.Linear),
],
intermediate_sizes=[5],
)
@pytest.fixture
def cnn_sequence_config() -> ModelConfig:
return SequenceModelConfig(
model_configs=[
CnnConfig(
cnn_num_cells=[4, 3],
cnn_kernel_sizes=[3, 2],
cnn_strides=1,
cnn_paddings=0,
cnn_activation_class=nn.Tanh,
mlp_num_cells=[4],
mlp_activation_class=nn.Tanh,
mlp_layer_class=nn.Linear,
),
MlpConfig(num_cells=[4], activation_class=nn.Tanh, layer_class=nn.Linear),
],
intermediate_sizes=[5],
)
@pytest.fixture
def mlp_gnn_sequence_config() -> ModelConfig:
return SequenceModelConfig(
model_configs=[
MlpConfig(num_cells=[8], activation_class=nn.Tanh, layer_class=nn.Linear),
GnnConfig(
topology="full",
self_loops=False,
gnn_class=torch_geometric.nn.conv.GATv2Conv,
),
MlpConfig(num_cells=[4], activation_class=nn.Tanh, layer_class=nn.Linear),
],
intermediate_sizes=[5, 3],
)
@pytest.fixture
def gru_mlp_sequence_config() -> ModelConfig:
return SequenceModelConfig(
model_configs=[
GruConfig(
hidden_size=13,
mlp_num_cells=[],
mlp_activation_class=nn.Tanh,
mlp_layer_class=nn.Linear,
n_layers=1,
bias=True,
dropout=0,
compile=False,
),
MlpConfig(num_cells=[4], activation_class=nn.Tanh, layer_class=nn.Linear),
],
intermediate_sizes=[5],
)
@pytest.fixture
def lstm_mlp_sequence_config() -> ModelConfig:
return SequenceModelConfig(
model_configs=[
LstmConfig(
hidden_size=13,
mlp_num_cells=[],
mlp_activation_class=nn.Tanh,
mlp_layer_class=nn.Linear,
n_layers=1,
bias=True,
dropout=0,
compile=False,
),
MlpConfig(num_cells=[4], activation_class=nn.Tanh, layer_class=nn.Linear),
],
intermediate_sizes=[5],
)