Skip to content

Commit

Permalink
[CI] Tests (#10)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Matteo Bettini <[email protected]>
  • Loading branch information
matteobettini authored Sep 11, 2023
1 parent 486f512 commit c265330
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 25 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions


name: pytest

on:
push:
branches: [ $default-branch , "main" , "dev" ]
pull_request:
branches: [ $default-branch , "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install vmas
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install --pre torch --extra-index-url https://download.pytorch.org/whl/nightly/cpu --force-reinstall
cd ..
python -m pip install git+https://github.com/pytorch-labs/tensordict.git
git clone https://github.com/pytorch/rl.git
cd rl
python setup.py develop
cd ../BenchMARL
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 benchmarl/ --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 benchmarl/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=E203,W503
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pip install tqdm
pytest test/ --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
3 changes: 1 addition & 2 deletions benchmarl/algorithms/iddpg.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Tuple, Type

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from torchrl.data import (
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/ippo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Tuple, Type

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from tensordict.nn.distributions import NormalParamExtractor
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/iql.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Type, Tuple

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from torchrl.data import (
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/isac.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type, Union
from typing import Dict, Optional, Tuple, Type, Union

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import NormalParamExtractor, TensorDictModule, TensorDictSequential
from torch.distributions import Categorical
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/maddpg.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Tuple, Type

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from torchrl.data import (
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/mappo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Tuple, Type

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from tensordict.nn.distributions import NormalParamExtractor
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/masac.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type, Union
from typing import Dict, Optional, Tuple, Type, Union

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import NormalParamExtractor, TensorDictModule, TensorDictSequential
from torch.distributions import Categorical
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/qmix.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Tuple, Type

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from torchrl.data import (
Expand Down
3 changes: 1 addition & 2 deletions benchmarl/algorithms/vdn.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dataclasses import dataclass, MISSING
from typing import Dict, Optional, Type
from typing import Dict, Optional, Tuple, Type

import torch
from black import Tuple
from tensordict import TensorDictBase
from tensordict.nn import TensorDictModule, TensorDictSequential
from torchrl.data import (
Expand Down
2 changes: 1 addition & 1 deletion benchmarl/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from models.mlp import MlpConfig
from .mlp import MlpConfig

model_config_registry = {"mlp": MlpConfig}
2 changes: 1 addition & 1 deletion benchmarl/models/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from tensordict import TensorDictBase
from torch import nn
from torchrl.modules import MLP, MultiAgentMLP
from utils import read_yaml_config

from benchmarl.models.common import Model, ModelConfig, parse_model_config
from benchmarl.utils import read_yaml_config


class Mlp(Model):
Expand Down
1 change: 0 additions & 1 deletion examples/simple_hydra_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from benchmarl.environments import task_config_registry
from benchmarl.experiment import Experiment

from benchmarl.hydra_run import load_model_from_hydra_config
from hydra.core.hydra_config import HydraConfig
from omegaconf import DictConfig, OmegaConf
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
torchrl
hydra-core
6 changes: 3 additions & 3 deletions test/test_algorithms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

from benchmarl.algorithms import algorithm_config_registry
from benchmarl.environments import VmasTask
from benchmarl.experiment import Experiment, ExperimentConfig
from benchmarl.hydra_run import load_experiment_from_hydra_config
from benchmarl.models.common import SequenceModelConfig
from benchmarl.models.mlp import MlpConfig
from hydra import compose, initialize
from torch import nn


@pytest.mark.parametrize("algo_config", algorithm_config_registry.values())
Expand All @@ -15,8 +15,8 @@ def test_all_algos_balance(algo_config, continuous):
task = VmasTask.BALANCE.get_from_yaml()
model_config = SequenceModelConfig(
model_configs=[
MlpConfig(num_cells=[8]),
MlpConfig(num_cells=[4]),
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],
)
Expand Down

0 comments on commit c265330

Please sign in to comment.