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

Long-duration determinism test #479

Merged
merged 7 commits into from
Jan 28, 2021
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
**/.spyproject
**/supervisord.log
**/supervisord.pid
**/*.tar
**/.tox/
**/traffic_histories.pkl
**/*.trips.xml
Expand All @@ -58,5 +59,7 @@

# Keep manually generated sumo route files
!zoo/evaluation/scenarios/**/traffic/*.rou.xml
!smarts/sstudio/tests/*.rou.xml

# Keep model assets
!**/models/*.glb
3 changes: 2 additions & 1 deletion .github/workflows/ci-base-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ jobs:
-n auto \
${{matrix.tests}} \
--ignore=./smarts/core/tests/test_smarts_memory_growth.py \
--ignore=./smarts/env/tests/test_benchmark.py \
--ignore=./smarts/env/tests/test_learning.py \
--ignore=./smarts/env/tests/test_benchmark.py
-k 'not test_long_determinism'
42 changes: 42 additions & 0 deletions .github/workflows/ci-test-long-determinism.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: SMARTS CI Long Determinism

on:
schedule:
- cron: '0 23 * * 6'
# Time is in UTC
# Runs at 11.00pm, UTC , every Saturday
# Runs at 6.00pm, UTC-5, every Saturday
workflow_dispatch:

env:
venv_dir: .venv

jobs:
test_learning:
runs-on: ubuntu-18.04
container: huaweinoah/smarts:v0.4.3-pre
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: develop
- name: Setup package
run: |
/usr/bin/Xorg \
-noreset \
+extension GLX \
+extension RANDR \
+extension RENDER \
-logfile ./xdummy.log \
-config /etc/X11/xorg.conf :1 &
cd $GITHUB_WORKSPACE
python3.7 -m venv ${{env.venv_dir}}
. ${{env.venv_dir}}/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .[train,test]
- name: Verify long determinism
run: |
cd $GITHUB_WORKSPACE
. ${{env.venv_dir}}/bin/activate
make test-long-determinism
6 changes: 3 additions & 3 deletions .github/workflows/ci-test-memory-growth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: SMARTS CI Memory

on:
schedule:
- cron: '0 23 * * 2'
- cron: '0 23 * * 4'
# Time is in UTC
# Runs at 11.00pm, UTC , every Tuesday
# Runs at 6.00pm, UTC-5, every Tuesday
# Runs at 11.00pm, UTC , every Thursday
# Runs at 6.00pm, UTC-5, every Thursday
workflow_dispatch:

env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ traffic_histories.pkl

# Manually generated sumo route files
!zoo/evaluation/scenarios/**/traffic/*.rou.xml
!smarts/sstudio/tests/*.rou.xml

# but keep model assets
!**/models/*.glb
Expand Down
48 changes: 19 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,56 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8

RUN echo "Installing dependencies"
RUN apt-get update --fix-missing && \
apt-get install -y \
wget

# Install libraries
RUN apt-get update --fix-missing && \
apt-get install -y \
software-properties-common && \
add-apt-repository -y ppa:deadsnakes/ppa && \
add-apt-repository -y ppa:sumo/stable && \
apt-get update && \
apt-get install -y \
wget \
libsm6 \
libspatialindex-dev \
libxext6 \
libxrender-dev \
python3.7 \
python3.7-dev \
python3.7-venv \
sumo \
sumo-tools \
sumo-doc \
libspatialindex-dev \
libsm6 \
libxext6 \
libxrender-dev
sumo-tools \
wget \
x11-apps \
xserver-xorg-video-dummy && \
apt-get autoremove && \
rm -rf /var/lib/apt/lists/*

# Update default python version
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1

# Install pip dependencies
# Install pip
RUN wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py && \
python get-pip.py && \
pip install --upgrade pip

RUN echo "Installing XDummy"
# Setup DISPLAY
ENV DISPLAY :1

RUN apt-get install -y \
xserver-xorg-video-dummy \
x11-apps

# VOLUME /tmp/.X11-unix
RUN wget -O /etc/X11/xorg.conf http://xpra.org/xorg.conf
RUN cp /etc/X11/xorg.conf /usr/share/X11/xorg.conf.d/xorg.conf

RUN echo "Cleaning-up"
RUN apt-get autoremove && \
rm -rf /var/lib/apt/lists/*
RUN wget -O /etc/X11/xorg.conf http://xpra.org/xorg.conf && \
cp /etc/X11/xorg.conf /usr/share/X11/xorg.conf.d/xorg.conf

RUN echo "Setup SMARTS Dependencies"
# Setup SUMO
ENV SUMO_HOME /usr/share/sumo

# Install requirements.txt
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# Copy source files and install SMARTS
ENV PYTHONPATH=/src
COPY . /src
RUN cd /usr/local/lib/python3.7 && \
mkdir site-packages && \
cd site-packages && \
python /src/setup.py develop
WORKDIR /src
RUN pip install --no-cache-dir -e .[train,test,dev]

# For Envision
EXPOSE 8081
Expand Down
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ test: build-all-scenarios
--forked \
--dist=loadscope \
-n `nproc --ignore 1` \
./tests ./smarts/core ./smarts/env ./smarts/contrib ./smarts/sstudio ./envision \
--ignore=./smarts/env/tests/test_learning.py \
./envision ./smarts/contrib ./smarts/core ./smarts/env ./smarts/sstudio ./tests \
--ignore=./smarts/core/tests/test_smarts_memory_growth.py \
--ignore=./smarts/env/tests/test_benchmark.py

.PHONY: benchmark
benchmark: build-all-scenarios
pytest -v ./smarts/env/tests/test_benchmark.py
--ignore=./smarts/env/tests/test_benchmark.py \
--ignore=./smarts/env/tests/test_learning.py \
-k 'not test_long_determinism'

.PHONY: test-learning
test-learning: build-all-scenarios
Expand All @@ -30,6 +27,17 @@ test-memory-growth: build-all-scenarios
-n `nproc --ignore 1` \
./smarts/core/tests/test_smarts_memory_growth.py

.PHONY: test-long-determinism
test-long-determinism:
scl scenario build --clean scenarios/minicity
PYTHONHASHSEED=42 pytest -v \
--forked \
./smarts/env/tests/test_determinism.py::test_long_determinism

.PHONY: benchmark
benchmark: build-all-scenarios
pytest -v ./smarts/env/tests/test_benchmark.py

.PHONY: test-zoo
test-zoo: build-all-scenarios
cd smarts/zoo/policies && make test
Expand Down
2 changes: 2 additions & 0 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .envision import envision_cli
from .studio import scenario_cli
from .zoo import zoo_cli
from .ultra import ultra_cli


@click.group()
Expand All @@ -32,6 +33,7 @@ def scl():
scl.add_command(envision_cli)
scl.add_command(scenario_cli)
scl.add_command(zoo_cli)
scl.add_command(ultra_cli)


if __name__ == "__main__":
Expand Down
79 changes: 79 additions & 0 deletions cli/ultra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os
import sys
import glob
import shutil
import subprocess
from pathlib import Path

import click
from rich import print


@click.group(name="ultra")
def ultra_cli():
pass


@ultra_cli.command(name="build", help="Build a policy")
@click.argument("policy", type=click.Path(exists=True), metavar="<policy>")
def build_policy(policy):
def clean():
subprocess.check_call([sys.executable, "setup.py", "clean", "--all"])

def build():
cwd = Path(os.getcwd())
subprocess.check_call([sys.executable, "setup.py", "bdist_wheel"])
results = sorted(glob.glob("./dist/*.whl"), key=os.path.getmtime, reverse=True)
assert len(results) > 0, f"No policy package was built at path={cwd}"

wheel = Path(results[0])
dst_path = cwd / wheel.name
shutil.move(wheel.resolve(), cwd / wheel.name)
return dst_path

os.chdir(policy)
clean()
wheel_path = build()
clean()
print(
f"""
Policy built successfully and is available at,

\t[bold]{wheel_path}[/bold]

You can now add it to the policy ultra if you want to make it available to scenarios.
"""
)


@ultra_cli.command(name="worker", help="Start the agent worker")
@click.argument("auth_key", type=str, default=None)
@click.argument("port", default=7432, type=int)
def worker(auth_key, port):
from smarts.zoo.worker import listen

auth_key = auth_key if auth_key else ""
listen(port, auth_key)


ultra_cli.add_command(build_policy)
ultra_cli.add_command(worker)
8 changes: 4 additions & 4 deletions gen_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ files=""

if [[ $# -eq 0 ]]; then
# No specific file specified, collate all files excluding auto generated files of *_pb2.py and *_pb2_grpc.py
python_files="$(find ./cli ./smarts ./benchmark ./envision -name '*.py' ! -name '*_pb2.py' ! -name '*_pb2_grpc.py')"
python_files="$(find ./cli ./smarts ./benchmark ./envision ./ultra -name '*.py' ! -name '*_pb2.py' ! -name '*_pb2_grpc.py')"
js_files="$(find ./envision/web/src -name '*.js')"
files="$python_files $js_files"
files="$python_files $js_files"
else
# use files specified in the args
for file in "$@"; do
files="$files $file"
done
fi
done
fi

# Check and add license notice
for file in $files; do
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ hyperlink==20.0.1
idna==2.10
imageio==2.9.0
importlib-metadata==2.0.0
importlib-resources==5.1.0
incremental==17.5.0
iniconfig==1.1.1
Jinja2==2.11.2
Expand Down
1 change: 1 addition & 0 deletions smarts/core/smarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def destroy(self):
self._visdom.teardown()

self._agent_manager.destroy()
self._traffic_sim.destroy()
self._bullet_client.disconnect()

super().destroy()
Expand Down
9 changes: 3 additions & 6 deletions smarts/core/sumo_traffic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def __init__(
self._reserved_areas = dict()
self._allow_reload = allow_reload

atexit.register(self._destroy)

def __repr__(self):
return f"""SumoTrafficSim(
_scenario={repr(self._scenario)},
Expand All @@ -109,11 +107,10 @@ def __repr__(self):
def __str__(self):
return repr(self)

def _destroy(self):
if atexit:
atexit.unregister(self._destroy)

def destroy(self):
self._close_traci_and_pipes()
if not self._is_setup:
return
self._sumo_proc.terminate()
self._sumo_proc.wait()

Expand Down
Loading