-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test] Better tests and multi OS (#89)
* amend * amend * [CI] Rerun tests * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * amend * faster tests * faster tests
- Loading branch information
1 parent
685b7f1
commit abf7b67
Showing
26 changed files
with
732 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Copyright (c) 2024. | ||
# ProrokLab (https://www.proroklab.org/) | ||
# All rights reserved. | ||
# | ||
|
||
|
||
python -m pip install --upgrade pip | ||
python -m pip install flake8 pytest pytest-cov tqdm matplotlib | ||
python -m pip install cvxpylayers # Navigation heuristic | ||
|
||
pip install -e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
name: pre-commit | ||
|
||
|
||
on: | ||
push: | ||
branches: [ $default-branch , "main" , "dev" ] | ||
pull_request: | ||
branches: [ $default-branch , "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
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 }} | ||
- uses: pre-commit/[email protected] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
name: pytest-linux | ||
|
||
on: | ||
push: | ||
branches: [ $default-branch , "main" , "dev" ] | ||
pull_request: | ||
branches: [ $default-branch , "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
python-version: ["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: | | ||
sudo apt-get update | ||
sudo apt-get install python3-opengl xvfb | ||
bash .github/unittest/install_dependencies.sh | ||
- name: Test with pytest | ||
run: | | ||
xvfb-run -s "-screen 0 1024x768x24" pytest tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html | ||
- if: matrix.python-version == '3.10' | ||
name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
with: | ||
fail_ci_if_error: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
|
||
name: pytest-mac | ||
|
||
on: | ||
push: | ||
branches: [ $default-branch , "main" , "dev" ] | ||
pull_request: | ||
branches: [ $default-branch , "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ macos-latest ] | ||
python-version: ["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 tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
|
||
name: pytest-windows | ||
|
||
on: | ||
push: | ||
branches: [ $default-branch , "main" , "dev" ] | ||
pull_request: | ||
branches: [ $default-branch , "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ windows-latest ] | ||
python-version: ["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 tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage: | ||
status: | ||
patch: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
# Copyright (c) 2022-2023. | ||
# Copyright (c) 2022-2024. | ||
# ProrokLab (https://www.proroklab.org/) | ||
# All rights reserved. | ||
import unittest | ||
|
||
import pytest | ||
import torch | ||
|
||
from vmas import make_env | ||
from vmas.scenarios import balance | ||
|
||
|
||
class TestBalance(unittest.TestCase): | ||
class TestBalance: | ||
def setup_env( | ||
self, | ||
n_envs, | ||
**kwargs, | ||
) -> None: | ||
super().setUp() | ||
self.n_agents = kwargs.get("n_agents", 4) | ||
|
||
self.continuous_actions = True | ||
self.n_envs = 15 | ||
self.env = make_env( | ||
scenario="balance", | ||
num_envs=self.n_envs, | ||
num_envs=n_envs, | ||
device="cpu", | ||
continuous_actions=self.continuous_actions, | ||
# Environment specific variables | ||
**kwargs, | ||
) | ||
self.env.seed(0) | ||
|
||
def test_heuristic(self): | ||
@pytest.mark.parametrize("n_agents", [2, 5]) | ||
def test_heuristic(self, n_agents, n_steps=50, n_envs=4): | ||
self.setup_env( | ||
n_agents=n_agents, random_package_pos_on_line=False, n_envs=n_envs | ||
) | ||
policy = balance.HeuristicPolicy(self.continuous_actions) | ||
|
||
for n_agents in [2, 5, 6, 10]: | ||
self.setup_env(n_agents=n_agents, random_package_pos_on_line=False) | ||
policy = balance.HeuristicPolicy(self.continuous_actions) | ||
obs = self.env.reset() | ||
|
||
obs = self.env.reset() | ||
rews = None | ||
prev_package_dist_to_goal = obs[0][:, 8:10] | ||
|
||
for _ in range(100): | ||
actions = [] | ||
for i in range(n_agents): | ||
obs_agent = obs[i] | ||
for _ in range(n_steps): | ||
actions = [] | ||
for i in range(n_agents): | ||
obs_agent = obs[i] | ||
package_dist_to_goal = obs_agent[:, 8:10] | ||
|
||
action_agent = policy.compute_action( | ||
obs_agent, self.env.agents[i].u_range | ||
) | ||
action_agent = policy.compute_action( | ||
obs_agent, self.env.agents[i].u_range | ||
) | ||
|
||
actions.append(action_agent) | ||
actions.append(action_agent) | ||
|
||
obs, new_rews, dones, _ = self.env.step(actions) | ||
obs, new_rews, dones, _ = self.env.step(actions) | ||
|
||
if rews is not None: | ||
for i in range(self.n_agents): | ||
self.assertTrue((new_rews[i] >= rews[i]).all()) | ||
rews = new_rews | ||
assert ( | ||
torch.linalg.vector_norm(package_dist_to_goal, dim=-1) | ||
<= torch.linalg.vector_norm(prev_package_dist_to_goal, dim=-1) | ||
).all() | ||
prev_package_dist_to_goal = package_dist_to_goal |
Oops, something went wrong.