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

CI test for RL examples: Drive and VehicleFollowing #2062

Merged
merged 7 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
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
56 changes: 50 additions & 6 deletions .github/workflows/ci-base-tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
venv_dir: .venv

jobs:
base-tests-linux:
base-tests:
Copy link
Collaborator

@Gamenot Gamenot Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not against it but is there any reason to change the name of the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the addition of more jobs in the same workflow, following the original naming style, each of the job would have been suffixed with -linux. The suffix appeared a little repetitive, given the workflow's name of SMARTS CI Base Tests Linux which indicates it is for Linux. In short, the change was for aesthetics. This is how the test results look like now.

Tests

runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
container: ghcr.io/smarts-project/smarts:v0.6.1-minimal
Expand All @@ -19,8 +19,8 @@ jobs:
- ./smarts/env --ignore=./smarts/env/tests/test_rllib_hiway_env.py
- ./smarts/env/tests/test_rllib_hiway_env.py
- ./smarts/sstudio
- ./examples/tests --ignore=./examples/tests/test_learning.py
- ./smarts/ray
- ./examples/tests/test_examples.py
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -31,12 +31,25 @@ jobs:
pip install --upgrade pip
pip install wheel==0.38.4
pip install -e .[camera_obs,opendrive,test,test_notebook,torch,train,gym,argoverse,envision,sumo]
if echo ${{matrix.tests}} | grep -q -e "env" -e "examples"; then pip install -e .[rllib]; fi
if echo ${{matrix.tests}} | grep -q "/ray"; then pip install -e .[ray]; fi
if echo ${{matrix.tests}} | grep -q -e "test_rllib_hiway_env.py" -e "test_examples.py"; then pip install -e .[rllib]; fi
if echo ${{matrix.tests}} | grep -q -e "/smarts/ray"; then pip install -e .[ray]; fi
- name: Build scenarios
run: |
. ${{env.venv_dir}}/bin/activate
scl scenario build-all \
scenarios/open_drive/od_4lane \
scenarios/open_drive/od_merge \
scenarios/sumo/figure_eight \
scenarios/sumo/intersections/2lane \
scenarios/sumo/intersections/4lane \
scenarios/sumo/intersections/6lane \
scenarios/sumo/loop \
scenarios/sumo/straight/3lane_bubble \
scenarios/sumo/tests/multi_agents_loop \
scenarios/sumo/zoo_intersection
- name: Run smoke tests
run: |
. ${{env.venv_dir}}/bin/activate
make build-all-scenarios
PYTHONPATH=$PWD PYTHONHASHSEED=42 pytest -v \
--doctest-modules \
--forked \
Expand All @@ -49,5 +62,36 @@ jobs:
--ignore=./smarts/core/tests/test_smarts_memory_growth.py \
--ignore=./smarts/core/tests/test_env_frame_rate.py \
--ignore=./smarts/env/tests/test_benchmark.py \
--ignore=./examples/tests/test_learning.py \
-k 'not test_long_determinism'

examples-rl:
Copy link
Collaborator

@Gamenot Gamenot Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long do these two tests take to run? We would want the total to be ~2 mins or less.

Otherwise, we will need to put it on some other schedule than always run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Currently the examples-rl test takes ~20 minutes
  • By reducing the number of routes generated in the scenarios, the examples-rl test time may be reduced to ~12 minutes
  • Previously the base-tests test took ~53 minutes to run when it attempted to build all scenarios.
  • By only building the necessary scenarios, the base-tests now takes ~6 minutes.
  • For a quick benefit, we may make another PR consisting of only building the necessary scenarios which will hasten the base-tests, while we figure how to best do CI for examples-rl test.

runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
container: ghcr.io/smarts-project/smarts:v0.6.1-minimal
strategy:
matrix:
tests:
- drive
- platoon
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: |
cd ${GITHUB_WORKSPACE}/examples/rl/${{matrix.tests}}
python3.8 -m venv ${{env.venv_dir}}
. ${{env.venv_dir}}/bin/activate
pip install --upgrade pip
pip install wheel==0.38.4
pip install -e ./../../../.[camera_obs,argoverse,sumo,test]
pip install -e ./inference/
- name: Run smoke tests
run: |
cd ${GITHUB_WORKSPACE}/examples/rl/${{matrix.tests}}
. ${{env.venv_dir}}/bin/activate
PYTHONPATH=$PWD PYTHONHASHSEED=42 pytest -v \
--doctest-modules \
--forked \
--dist=no \
-n auto \
${GITHUB_WORKSPACE}/examples/tests/test_rl.py::test_${{matrix.tests}}
4 changes: 2 additions & 2 deletions cli/tests/test_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def test_scenario_generation_unchanged():
_hashseed = os.getenv("PYTHONHASHSEED")
assert _hashseed not in (None, "random"), f"PYTHONHASHSEED is {_hashseed}"

shutil.copytree("scenarios/sumo", loc1)
shutil.copytree("scenarios/sumo/loop", loc1)
build_scenarios(scenarios=[loc1], clean=True, seed=42)

shutil.copytree("scenarios/sumo", loc2)
shutil.copytree("scenarios/sumo/loop", loc2)
build_scenarios(scenarios=[loc2], clean=True, seed=42)

for dirpath, dirnames, files in os.walk(loc1):
Expand Down
3 changes: 1 addition & 2 deletions envision/tests/test_data_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from smarts.core.scenario import Scenario
from smarts.core.smarts import SMARTS
from smarts.core.sumo_traffic_simulation import SumoTrafficSimulation
from smarts.core.tests.helpers.bubbles import bubble_geometry
from smarts.core.tests.helpers.scenario import temp_scenario
from smarts.core.utils.file import unpack
from smarts.sstudio.genscenario import gen_scenario
Expand Down Expand Up @@ -321,7 +320,7 @@ def bubble():
actor=t.BoidAgentActor(
# TODO: Provide a more self-contained way to build agent locators for tests
name="hive-mind",
agent_locator="scenarios.sumo.straight.agent_prefabs:pose-boid-agent-v0",
agent_locator="scenarios.sumo.straight.3lane_bubble.agent_prefabs:pose-boid-agent-v0",
),
)

Expand Down
59 changes: 59 additions & 0 deletions examples/tests/test_rl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import argparse
from pathlib import Path
from unittest import mock

from smarts.core.utils import import_utils

import_utils.import_module_from_file(
"examples", Path(__file__).parents[1] / "__init__.py"
)


def _mock_load_config(load_config):
def func():
config = load_config()
config.alg["n_steps"] = 4
config.alg["batch_size"] = 2
config.alg["n_epochs"] = 2
config.epochs = 2 * len(config.scenarios)
config.train_steps = 8
config.checkpoint_freq = 10000
config.eval_freq = 10000
return config

return func


def test_platoon():
"""Tests RL training of `examples/rl/platoon` example."""

from examples.rl.platoon.train.run import load_config, main

args = argparse.Namespace()
args.mode = "train"
args.logdir = None
args.model = None
args.head = False

with mock.patch(
"examples.rl.platoon.train.run.load_config",
_mock_load_config(load_config),
):
main(args)


def test_drive():
"""Tests RL training of `examples/rl/drive` example."""
from examples.rl.drive.train.run import load_config, main

args = argparse.Namespace()
args.mode = "train"
args.logdir = None
args.model = None
args.head = False

with mock.patch(
"examples.rl.drive.train.run.load_config",
_mock_load_config(load_config),
):
main(args)
1 change: 0 additions & 1 deletion examples/tools/pybullet_linear_tire_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import math
from pathlib import Path
from unittest import mock

import matplotlib.pyplot as plt
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
("E8", 0, "E4", 0),
]

# Total route combinations = 14C1 + 14C2 + 14C3 + 14C4 = 1470
# Total route combinations
all_routes = vertical_routes + horizontal_routes + turn_left_routes + turn_right_routes
route_comb = [com for elems in range(4, 5) for com in combinations(all_routes, elems)]
traffic = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
("E8", 0, "E4", 0),
]

# Total route combinations = 14C1 + 14C2 + 14C3 + 14C4 = 1470
# Total route combinations
all_routes = vertical_routes + horizontal_routes + turn_left_routes + turn_right_routes
route_comb = [com for elems in range(4, 5) for com in combinations(all_routes, elems)]
traffic = {}
Expand Down
3 changes: 1 addition & 2 deletions scenarios/sumo/straight/cruise_2lane_agents_1/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
(1, 1),
]

# Traffic combinations = 3C2 + 3C3 = 3 + 1 = 4
# Repeated traffic combinations = 4 * 100 = 400
# Traffic combinations
min_flows = 2
max_flows = 2
route_comb = [
Expand Down
3 changes: 1 addition & 2 deletions scenarios/sumo/straight/cutin_2lane_agents_1/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
(1, 1),
]

# Traffic combinations = 3C2 + 3C3 = 3 + 1 = 4
# Repeated traffic combinations = 4 * 100 = 400
# Traffic combinations
min_flows = 1
max_flows = 3
route_comb = [
Expand Down
3 changes: 1 addition & 2 deletions scenarios/sumo/straight/overtake_2lane_agents_1/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
(1, 1),
]

# Traffic combinations = 3C2 + 3C3 = 3 + 1 = 4
# Repeated traffic combinations = 4 * 100 = 400
# Traffic combinations
min_flows = 2
max_flows = 2
route_comb = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,14 @@
speed=Distribution(sigma=0.2, mean=0.8),
)

# Social path = (start_lane, end_lane)
social_paths = [
(0, 0),
(0, 1),
(0, 2),
(1, 0),
(1, 1),
(1, 2),
(2, 0),
(2, 1),
(2, 2),
]
min_flows = 2
max_flows = 4
social_comb = [
com
for elems in range(min_flows, max_flows + 1)
for com in combinations(social_paths, elems)
]

# Leader path = (start_lane, end_lane)
leader_paths = [0, 1, 2]

# Overall routes
route_comb = product(social_comb, leader_paths)
route_comb = leader_paths

traffic = {}
for name, (social_path, leader_path) in enumerate(route_comb):
for name, leader_path in enumerate(route_comb):
traffic[str(name)] = Traffic(
engine="SUMO",
flows=[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,14 @@

leader = TrafficActor(name="Leader-007", depart_speed=0)

# Social path = (start_lane, end_lane)
social_paths = [
(0, 0),
(0, 1),
(1, 0),
(1, 1),
]
min_flows = 2
max_flows = 3
social_comb = [
com
for elems in range(min_flows, max_flows + 1)
for com in combinations(social_paths, elems)
] * 10

# Leader path = (start_lane, end_lane)
leader_paths = [(0, 0), (0, 1)]

# Overall routes
route_comb = product(social_comb, leader_paths)
route_comb = leader_paths

traffic = {}
for name, (social_path, leader_path) in enumerate(route_comb):
for name, leader_path in enumerate(route_comb):
traffic[str(name)] = Traffic(
engine="SUMO",
flows=[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,13 @@

leader = TrafficActor(name="Leader-007", depart_speed=0)

# Social path = (start_lane, end_lane)
social_paths = [(0, 0), (0, 2), (2, 0), (2, 2)]
min_flows = 2
max_flows = 4
social_comb = [
com
for elems in range(min_flows, max_flows + 1)
for com in combinations(social_paths, elems)
]

# Leader path = (start_lane, end_lane)
leader_paths = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]

# Overall routes
route_comb = product(social_comb, leader_paths)
route_comb = leader_paths
traffic = {}
for name, (social_path, leader_path) in enumerate(route_comb):
for name, leader_path in enumerate(route_comb):
traffic[str(name)] = Traffic(
engine="SUMO",
flows=[],
Expand Down
4 changes: 0 additions & 4 deletions smarts/core/tests/test_bubble_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@
from helpers.scenario import temp_scenario

import smarts.sstudio.types as t
from smarts.core.agent_manager import AgentManager
from smarts.core.controllers import ActionSpaceType
from smarts.core.coordinates import Heading, Pose
from smarts.core.local_traffic_provider import LocalTrafficProvider
from smarts.core.observations import Observation
from smarts.core.scenario import Scenario
from smarts.core.smarts import SMARTS
from smarts.core.sumo_traffic_simulation import SumoTrafficSimulation
from smarts.core.tests.helpers.providers import MockProvider, MockTrafficProvider
from smarts.core.vehicle_index import VehicleIndex
from smarts.sstudio import gen_scenario
Expand Down
1 change: 0 additions & 1 deletion zoo/evaluation/scenarios/cross/ego_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from smarts.core.agent_interface import ActionSpaceType, AgentInterface
from smarts.core.utils.episodes import episodes
from smarts.zoo.agent_spec import AgentSpec
from zoo.policies.non_interactive_agent import NonInteractiveAgent

Expand Down