Skip to content

Commit

Permalink
[Test] Modularized tests and CI (#15)
Browse files Browse the repository at this point in the history
* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* empty

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* remove hydra dependency

Signed-off-by: Matteo Bettini <[email protected]>

* rename folder

Signed-off-by: Matteo Bettini <[email protected]>

* rename file

Signed-off-by: Matteo Bettini <[email protected]>

* update tasks

Signed-off-by: Matteo Bettini <[email protected]>

* update models

Signed-off-by: Matteo Bettini <[email protected]>

* update models

Signed-off-by: Matteo Bettini <[email protected]>

* amend

Signed-off-by: Matteo Bettini <[email protected]>

* update algos

Signed-off-by: Matteo Bettini <[email protected]>

* add test

Signed-off-by: Matteo Bettini <[email protected]>

---------

Signed-off-by: Matteo Bettini <[email protected]>
  • Loading branch information
matteobettini authored Sep 21, 2023
1 parent 00efda3 commit 64590d4
Show file tree
Hide file tree
Showing 50 changed files with 656 additions and 286 deletions.
16 changes: 16 additions & 0 deletions .github/unittest/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-cov hydra-core

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 .
22 changes: 22 additions & 0 deletions .github/unittest/install_smacv2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


root_dir="$(git rev-parse --show-toplevel)"
cd "${root_dir}"

starcraft_path="${root_dir}/StarCraftII"
map_dir="${starcraft_path}/Maps"
printf "* Installing StarCraft 2 and SMACv2 maps into ${starcraft_path}\n"
cd "${root_dir}"
wget https://blzdistsc2-a.akamaihd.net/Linux/SC2.4.10.zip
# The archive contains StarCraftII folder. Password comes from the documentation.
unzip -qo -P iagreetotheeula SC2.4.10.zip
mkdir -p "${map_dir}"
# Install Maps
wget https://github.com/oxwhirl/smacv2/releases/download/maps/SMAC_Maps.zip
unzip SMAC_Maps.zip
mkdir "${map_dir}/SMAC_Maps"
mv *.SC2Map "${map_dir}/SMAC_Maps"
printf "StarCraft II and SMAC are installed."

pip install numpy==1.23.0
pip install git+https://github.com/oxwhirl/smacv2.git
4 changes: 4 additions & 0 deletions .github/unittest/install_vmas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

python -m pip install vmas
sudo apt-get update
sudo apt-get install python3-opengl xvfb
45 changes: 45 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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: lint

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

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["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: Lint
run: |
python -m pip install --upgrade pip
pip install pre-commit
set +e
pre-commit run --all-files
if [ $? -ne 0 ]; then
git --no-pager diff
exit 1
fi
58 changes: 0 additions & 58 deletions .github/workflows/python-app.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/smacv2_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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: smacv2_tests

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

permissions:
contents: read

jobs:
build:
if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'smacv2') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["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: |
bash .github/unittest/install_dependencies.sh
- name: Install smacv2
run: |
bash .github/unittest/install_smacv2.sh
- name: Test with pytest
run: |
root_dir="$(git rev-parse --show-toplevel)"
export SC2PATH="${root_dir}/StarCraftII"
echo 'SC2PATH is set to ' "$SC2PATH"
pytest test/test_smacv2.py --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
37 changes: 37 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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: unit_tests

on:
push:
branches: [ $default-branch , "main" ]
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: |
bash .github/unittest/install_dependencies.sh
- name: Test with pytest
run: |
pytest test/ --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
39 changes: 39 additions & 0 deletions .github/workflows/vmas_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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: vmas_tests

on:
push:
branches: [ $default-branch , "main" ]
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: |
bash .github/unittest/install_dependencies.sh
- name: Install vmas
run: |
bash .github/unittest/install_vmas.sh
- name: Test with pytest
run: |
xvfb-run -s "-screen 0 1024x768x24" pytest test/test_vmas.py --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

# Hydra
outputs/
examples/outputs/
benchmarl/outputs/
multirun/
examples/multirun/
benchmarl/multirun/


# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -43,6 +48,7 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
test/tmp/
htmlcov/
.tox/
.nox/
Expand Down
37 changes: 21 additions & 16 deletions benchmarl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
def load_hydra_schemas():
from hydra.core.config_store import ConfigStore
import importlib

from benchmarl.algorithms import algorithm_config_registry
from benchmarl.environments import _task_class_registry
from benchmarl.experiment import ExperimentConfig
_has_hydra = importlib.util.find_spec("hydra") is not None

# Create instance to load hydra schemas
cs = ConfigStore.instance()
# Load experiment schema
cs.store(name="experiment_config", group="experiment", node=ExperimentConfig)
# Load algos schemas
for algo_name, algo_schema in algorithm_config_registry.items():
cs.store(name=f"{algo_name}_config", group="algorithm", node=algo_schema)
# Load rask schemas
for task_schema_name, task_schema in _task_class_registry.items():
cs.store(name=task_schema_name, group="task", node=task_schema)
if _has_hydra:

def load_hydra_schemas():
from hydra.core.config_store import ConfigStore

load_hydra_schemas()
from benchmarl.algorithms import algorithm_config_registry
from benchmarl.environments import _task_class_registry
from benchmarl.experiment import ExperimentConfig

# Create instance to load hydra schemas
cs = ConfigStore.instance()
# Load experiment schema
cs.store(name="experiment_config", group="experiment", node=ExperimentConfig)
# Load algos schemas
for algo_name, algo_schema in algorithm_config_registry.items():
cs.store(name=f"{algo_name}_config", group="algorithm", node=algo_schema)
# Load task schemas
for task_schema_name, task_schema in _task_class_registry.items():
cs.store(name=task_schema_name, group="task", node=task_schema)

load_hydra_schemas()
11 changes: 2 additions & 9 deletions benchmarl/algorithms/iddpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@

class Iddpg(Algorithm):
def __init__(
self,
share_param_actor: bool = True,
share_param_critic: bool = True,
loss_function: str = "l2",
delay_value: bool = True,
**kwargs
self, share_param_critic: bool, loss_function: str, delay_value: bool, **kwargs
):
super().__init__(**kwargs)

self.share_param_actor = share_param_actor
self.share_param_critic = share_param_critic
self.delay_value = delay_value
self.loss_function = loss_function
Expand Down Expand Up @@ -142,7 +136,7 @@ def _get_policy_for_loss(
input_has_agent_dim=True,
n_agents=n_agents,
centralised=False,
share_params=self.share_param_actor,
share_params=self.experiment_config.share_policy_params,
device=self.device,
)

Expand Down Expand Up @@ -258,7 +252,6 @@ def get_value_module(self, group: str) -> TensorDictModule:

@dataclass
class IddpgConfig(AlgorithmConfig):
share_param_actor: bool = MISSING
share_param_critic: bool = MISSING
loss_function: str = MISSING
delay_value: bool = MISSING
Expand Down
Loading

0 comments on commit 64590d4

Please sign in to comment.