diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 00000000..a9f27c8b --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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 diff --git a/benchmarl/algorithms/iddpg.py b/benchmarl/algorithms/iddpg.py index df4d146e..f4edae55 100644 --- a/benchmarl/algorithms/iddpg.py +++ b/benchmarl/algorithms/iddpg.py @@ -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 ( diff --git a/benchmarl/algorithms/ippo.py b/benchmarl/algorithms/ippo.py index ea81df7b..22403a9d 100644 --- a/benchmarl/algorithms/ippo.py +++ b/benchmarl/algorithms/ippo.py @@ -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 diff --git a/benchmarl/algorithms/iql.py b/benchmarl/algorithms/iql.py index 5daffdbe..219d2b57 100644 --- a/benchmarl/algorithms/iql.py +++ b/benchmarl/algorithms/iql.py @@ -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 ( diff --git a/benchmarl/algorithms/isac.py b/benchmarl/algorithms/isac.py index 6d6b8c4c..e09d5717 100644 --- a/benchmarl/algorithms/isac.py +++ b/benchmarl/algorithms/isac.py @@ -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 diff --git a/benchmarl/algorithms/maddpg.py b/benchmarl/algorithms/maddpg.py index 48606dd3..fc083b8f 100644 --- a/benchmarl/algorithms/maddpg.py +++ b/benchmarl/algorithms/maddpg.py @@ -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 ( diff --git a/benchmarl/algorithms/mappo.py b/benchmarl/algorithms/mappo.py index 99f609ff..34223fbc 100644 --- a/benchmarl/algorithms/mappo.py +++ b/benchmarl/algorithms/mappo.py @@ -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 diff --git a/benchmarl/algorithms/masac.py b/benchmarl/algorithms/masac.py index 46df792f..cf489d5e 100644 --- a/benchmarl/algorithms/masac.py +++ b/benchmarl/algorithms/masac.py @@ -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 diff --git a/benchmarl/algorithms/qmix.py b/benchmarl/algorithms/qmix.py index aca1691f..a2849b38 100644 --- a/benchmarl/algorithms/qmix.py +++ b/benchmarl/algorithms/qmix.py @@ -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 ( diff --git a/benchmarl/algorithms/vdn.py b/benchmarl/algorithms/vdn.py index 9c9363a2..faf0e8b9 100644 --- a/benchmarl/algorithms/vdn.py +++ b/benchmarl/algorithms/vdn.py @@ -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 ( diff --git a/benchmarl/models/__init__.py b/benchmarl/models/__init__.py index d3509727..2fefe7ab 100644 --- a/benchmarl/models/__init__.py +++ b/benchmarl/models/__init__.py @@ -1,3 +1,3 @@ -from models.mlp import MlpConfig +from .mlp import MlpConfig model_config_registry = {"mlp": MlpConfig} diff --git a/benchmarl/models/mlp.py b/benchmarl/models/mlp.py index 59c51b77..88cd2bfd 100644 --- a/benchmarl/models/mlp.py +++ b/benchmarl/models/mlp.py @@ -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): diff --git a/examples/simple_hydra_run.py b/examples/simple_hydra_run.py index 2aea53f4..aeaeaa1a 100644 --- a/examples/simple_hydra_run.py +++ b/examples/simple_hydra_run.py @@ -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 diff --git a/requirements.txt b/requirements.txt index a628f6d7..e2d09241 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -torchrl +hydra-core diff --git a/test/test_algorithms.py b/test/test_algorithms.py index fcacdceb..b925a124 100644 --- a/test/test_algorithms.py +++ b/test/test_algorithms.py @@ -1,5 +1,4 @@ import pytest - from benchmarl.algorithms import algorithm_config_registry from benchmarl.environments import VmasTask from benchmarl.experiment import Experiment, ExperimentConfig @@ -7,6 +6,7 @@ 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()) @@ -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], )