Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MAT network test #273

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions tests/test_modules/test_networks/test_MAT_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2023 The OpenRL Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""""""

import os
import sys

import numpy as np
import pytest
from gymnasium import spaces

from openrl.configs.config import create_config_parser
from openrl.modules.networks.MAT_network import MultiAgentTransformer


@pytest.fixture(scope="module", params=[""])
def config(request):
cfg_parser = create_config_parser()
cfg = cfg_parser.parse_args(request.param.split())
return cfg


@pytest.mark.unittest
def test_MAT_network(config):
net = MultiAgentTransformer(
config,
input_space=spaces.Discrete(2),
action_space=spaces.Discrete(2),
)
net.get_actor_para()
net.get_critic_para()

obs = np.zeros([1, 2])
rnn_states = np.zeros(2)
masks = np.zeros(2)
action = np.zeros(1)
net.get_actions(obs=obs, masks=masks)
net.eval_actions(
obs=obs, rnn_states=rnn_states, action=action, masks=masks, action_masks=None
)
net.get_values(critic_obs=obs, masks=masks)


if __name__ == "__main__":
sys.exit(pytest.main(["-sv", os.path.basename(__file__)]))