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

Colab Jupyter Notebook Demo #1300

Merged
merged 183 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
da23fc7
Added ipynb for single agent example.
Adaickalavan Dec 16, 2021
2c81d01
Update single agent ipynb.
Adaickalavan Dec 16, 2021
384c2af
Edit markdown.
Adaickalavan Dec 16, 2021
d0f517f
Add envision display.
Adaickalavan Dec 16, 2021
3aeb4aa
Check for google colab.
Adaickalavan Dec 16, 2021
94b3a3b
Cleaned.
Adaickalavan Dec 16, 2021
1dcecf1
update
Adaickalavan Dec 16, 2021
7d205b9
Upgrade pip
Adaickalavan Dec 16, 2021
2772ee5
Remove version
Adaickalavan Dec 17, 2021
e4197be
Use importlib
Adaickalavan Dec 17, 2021
06ae578
Run in background.
Adaickalavan Dec 17, 2021
7e0827e
Fix importlib
Adaickalavan Dec 17, 2021
4dde7f6
Change to importlib_metadata
Adaickalavan Dec 17, 2021
e1c8c43
Update
Adaickalavan Dec 17, 2021
6a8d113
Install latest sumo
Adaickalavan Dec 17, 2021
db34e92
Update ipynb
Adaickalavan Dec 17, 2021
6b85987
Add envision command.
Adaickalavan Dec 17, 2021
8cfe7b0
More changes.
Adaickalavan Dec 18, 2021
a36c660
Update
Adaickalavan Dec 17, 2021
504cdc6
Changes.
Adaickalavan Dec 18, 2021
9d5a188
Update
Adaickalavan Dec 18, 2021
32b1f4e
Hide importlib_metadata
Adaickalavan Dec 20, 2021
de6ef03
Include version
Adaickalavan Dec 20, 2021
a0f3d76
Update
Adaickalavan Dec 20, 2021
3850d51
Changes.
Adaickalavan Dec 20, 2021
711b81c
Change to http
Adaickalavan Dec 20, 2021
eef56fc
Revert to ws
Adaickalavan Dec 20, 2021
23a9726
Update
Adaickalavan Dec 21, 2021
e69263f
Hide comment.
Adaickalavan Dec 21, 2021
2d83a50
Use 127.0.0.1
Adaickalavan Dec 21, 2021
e7e8a85
Update
Adaickalavan Dec 21, 2021
e576c18
print scen dir
Adaickalavan Dec 21, 2021
b59457f
Try 0.0.0.0
Adaickalavan Dec 21, 2021
8c587f8
Debug
Adaickalavan Dec 21, 2021
ffeb52d
Test
Adaickalavan Dec 21, 2021
0d660a6
Try
Adaickalavan Dec 22, 2021
1783b0d
Try 127.0.0.1
Adaickalavan Dec 22, 2021
d4d40ff
Try comands together.
Adaickalavan Dec 22, 2021
0349810
Change port to 8087.
Adaickalavan Dec 22, 2021
b7e9e0a
Use figure eight.
Adaickalavan Dec 22, 2021
91ddc0c
Revert
Adaickalavan Dec 22, 2021
e6c9821
Extract out the envision endpoint.
Adaickalavan Dec 23, 2021
435be60
Try
Adaickalavan Dec 23, 2021
2fd7080
test sim name
Adaickalavan Dec 23, 2021
8714389
Try 2.
Adaickalavan Dec 23, 2021
43381c3
Ngrok
Adaickalavan Dec 25, 2021
f0967b1
Updates.
Adaickalavan Feb 1, 2022
9fcbc15
Add visdom
Adaickalavan Feb 1, 2022
c45bc48
Change inputs.
Adaickalavan Feb 1, 2022
956aded
Background processes.
Adaickalavan Feb 1, 2022
a5dd5bd
Background processes.
Adaickalavan Feb 1, 2022
293e5c4
Add offscreen renderer.
Adaickalavan Feb 1, 2022
075524a
Add offscreen renderer.
Adaickalavan Feb 1, 2022
0c14008
Test offscreen renderer.
Adaickalavan Feb 1, 2022
046b326
Non editable.
Adaickalavan Feb 1, 2022
bf75345
Correct dependencies.
Adaickalavan Feb 1, 2022
8517c51
Correct dependencies.
Adaickalavan Feb 2, 2022
6dbd18e
Set max steps.
Adaickalavan Feb 2, 2022
23b4b48
Add pip uninstall
Adaickalavan Feb 2, 2022
da00e90
Update ipynb.
Adaickalavan Feb 3, 2022
b9c4bf3
Basic colab single agent example.
Adaickalavan Feb 3, 2022
f398693
Rectify branch name.
Adaickalavan Feb 3, 2022
f9ae678
Include camera-obs.
Adaickalavan Feb 3, 2022
14668c6
Update versions.
Adaickalavan Feb 3, 2022
5a05509
Remove unnecessary code.
Adaickalavan Feb 3, 2022
19e4f0c
Fix opencv version.
Adaickalavan Feb 3, 2022
4d0d0b4
Reorganize extra dependencies.
Adaickalavan Feb 3, 2022
18269a5
Add multi-agent example.
Adaickalavan Feb 3, 2022
2a7296c
Cleaned.
Adaickalavan Feb 4, 2022
68ab50e
Revert smarts.__init__.py
Adaickalavan Feb 4, 2022
669ae39
Force reinstall.
Adaickalavan Feb 4, 2022
384a553
Checkout a tag.
Adaickalavan Feb 4, 2022
1533e24
Pip uninstall.
Adaickalavan Feb 7, 2022
2d76150
Try
Adaickalavan Feb 17, 2022
18953fa
Remove unnecessary changes.
Adaickalavan Feb 17, 2022
21469a8
Remove unnecessary changes.
Adaickalavan Feb 17, 2022
4c47fb5
Autoreload.
Adaickalavan Feb 17, 2022
6f00cb7
Fix dependencies
Gamenot Feb 18, 2022
65d3d64
Downgrade click
Gamenot Feb 18, 2022
8978821
Downgrade protobuf
Gamenot Feb 18, 2022
a7983b6
Loosen grpcio
Gamenot Feb 18, 2022
2922c2e
Loosen gym
Gamenot Feb 18, 2022
880efb6
Move opendrive utilities to extra
Gamenot Feb 18, 2022
a6e6815
Bump minimum gym version
Gamenot Feb 18, 2022
37283f7
Move opendrive to extra
Gamenot Feb 18, 2022
2d36ef1
black format
Gamenot Feb 18, 2022
a7332dd
Add file header
Gamenot Feb 18, 2022
ec1f880
Add docstring to exception required_to
Gamenot Feb 18, 2022
d558acb
Constrain gym from higher versions
Gamenot Feb 18, 2022
85c1db9
Fix injected attribute missing
Gamenot Feb 19, 2022
7d1974f
Upload working colab notebook
Gamenot Feb 19, 2022
35a6a76
Remove explicit scenario build call from demo
Gamenot Feb 20, 2022
a3953b9
Update metadata
Gamenot Feb 20, 2022
316ff96
Attempt to get rendering working
Gamenot Feb 21, 2022
0305077
Update the demo notebook
Gamenot Feb 21, 2022
6b8bc1c
Update demo to working state
Gamenot Feb 21, 2022
2e59c10
Working demo
Gamenot Feb 22, 2022
0bdd0b4
Format for image
Gamenot Feb 22, 2022
8ee4aa0
Fix gif rendering
Gamenot Feb 22, 2022
70e63af
Finish mock demo
Gamenot Feb 25, 2022
c17966b
Further improve mock example
Gamenot Feb 25, 2022
c4acd3c
Update mock
Gamenot Feb 26, 2022
53de23a
Fix some issues with demo
Gamenot Feb 26, 2022
82c4114
Fix episode step
Gamenot Feb 26, 2022
03419fe
Mock demo works
Gamenot Feb 26, 2022
f5203be
Add headers
Gamenot Feb 26, 2022
c88d0b2
Run black
Gamenot Feb 26, 2022
51bc89e
Do rendering
Gamenot Feb 27, 2022
1b1860e
Get print utility working
Gamenot Feb 27, 2022
801d0fb
Fix mock notebook
Gamenot Feb 27, 2022
cda03e9
Upload demo result
Gamenot Feb 27, 2022
caf7bd5
Reintroduce last step
Gamenot Mar 1, 2022
ea47843
Update to properly use public interfaces
Gamenot Mar 23, 2022
0dc9020
Update demo notebook
Gamenot Mar 23, 2022
ff09c88
Update demo mock
Gamenot Mar 23, 2022
6804d3a
Add heading to sstudio build scenario.
Gamenot Mar 23, 2022
0d51d42
Update docstrings in episode loggers.
Gamenot Mar 23, 2022
4f794ff
Update docstrings in episode logging wrapper.
Gamenot Mar 23, 2022
e67ded2
Update docstrings in video recorder.
Gamenot Mar 23, 2022
194cbda
Update single agent notebook.
Gamenot Mar 24, 2022
f7f776d
Remove rendering wrapper
Gamenot Mar 24, 2022
b2455ed
Remove extra cruft from notebooks
Gamenot Mar 24, 2022
3103243
Update to use rendering
Gamenot Mar 25, 2022
a2362ad
Update rendering
Gamenot Mar 25, 2022
c9287b1
Stack videos horizontally
Gamenot Mar 25, 2022
b0a7c42
Revert demo_mock back to current branch
Gamenot Mar 25, 2022
686e13f
Add colab option
Gamenot Mar 25, 2022
6f21858
Clamp grpcio version
Gamenot Mar 26, 2022
1f26513
try to resolve the grpcio denpendency issue with colab
Gamenot May 24, 2022
c4daa3d
Update demo_mock.ipynb
AisenGinn May 24, 2022
7f4a3b5
Update grpcio to 1.46.1
AisenGinn May 24, 2022
d87da30
update grpcio to 1.46.1
AisenGinn May 24, 2022
9154a04
Update requirements.txt
AisenGinn May 24, 2022
072370f
Update grpcio to 1.46.1
AisenGinn May 24, 2022
23b4652
update grpcio to 1.46.1
AisenGinn May 24, 2022
3f445d1
adding interface for agent_buffer, buffer_agent, add code for local_a…
Gamenot Jun 1, 2022
7990d5a
Finished adding local_agent, local_agent_buffer, and modify the code …
Gamenot Jun 2, 2022
c919627
deleting all grpc in requirement file, revert grpc tool back to 1.32.…
Gamenot Jun 7, 2022
a570a26
moving executor out of act function as a instance variable in local_a…
Gamenot Jun 7, 2022
504577b
fixed executor issue in local_agent. properly intialize and terminate…
Gamenot Jun 9, 2022
5745d87
Fix headers
Gamenot Jun 10, 2022
a6d1a12
Fix docstrings
Gamenot Jun 11, 2022
389abe8
Remove duplicate opendrive extra
Gamenot Jun 24, 2022
2babc26
Remove unused imports
Gamenot Jun 24, 2022
ab069ab
Remove unused image rendering code.
Gamenot Jun 24, 2022
c060a61
Rename done episode wrapper to closed.
Gamenot Jun 24, 2022
f122120
Revert grpcio removal in requirments files.
Gamenot Jun 24, 2022
367d6ee
Rename demo environment.
Gamenot Jun 24, 2022
32f0a30
Change import directory.
Gamenot Jun 24, 2022
18440d5
Share local agent executor.
Gamenot Jun 24, 2022
4fa6029
Wrap agent buffer.
Gamenot Jun 24, 2022
4f71ab7
Remove unused cloudpickle import
Gamenot Jun 24, 2022
d5bfe93
Fix agent buffer shutdown.
Gamenot Jun 24, 2022
c222b12
Add executor typehint to local agent
Gamenot Jun 24, 2022
51b02a3
Remove duplicate abstract requirement code.
Gamenot Jun 24, 2022
67f00c9
Use a wrapper instead of executor to wait for grpc conversion.
Gamenot Jun 24, 2022
6a864e8
Remove current agent tracking in rgb camera wrapper.
Gamenot Jun 24, 2022
95cbec0
Fix exception import issue and move exceptions.
Gamenot Jun 24, 2022
6eeb987
Fix opendrive error description
Gamenot Jun 24, 2022
06f184f
Support multi-agent done in examples.
Gamenot Jun 24, 2022
221e07e
Fix error.
Gamenot Jun 24, 2022
55f6b7a
Use new terminology.
Gamenot Jun 24, 2022
abfec26
Remove optional
Gamenot Jun 24, 2022
b43691d
Fix episodes bug.
Gamenot Jun 24, 2022
fb4e01e
Add missing init python file.
Gamenot Jun 24, 2022
1069522
Update demo notebook smarts location.
Gamenot Jun 24, 2022
c1e8f04
Add docstrings
Gamenot Jun 24, 2022
a0863a6
Fix exception docstring.
Gamenot Jun 27, 2022
e73a441
Fix local agent buffer num cpus.
Gamenot Jun 27, 2022
b572007
Fix pytype issues.
Gamenot Jun 27, 2022
4b7d66b
Convert the rgb rendering to a utility.
Gamenot Jun 27, 2022
cefb151
Fix use of dict where tuple needed
Gamenot Jul 8, 2022
0c37be4
Rename figure eight environment
Gamenot Jul 8, 2022
40ba338
Clarify shift to boolean instead of None.
Gamenot Jul 8, 2022
63eab1b
Add figure eight environment
Gamenot Jul 8, 2022
2f9561c
Black format
Gamenot Jul 8, 2022
da27c40
Update comments.
Gamenot Jul 8, 2022
f6810bb
Add type return
Gamenot Jul 8, 2022
884f673
Remove unused utility.
Gamenot Jul 8, 2022
1135b30
Fix episode log
Gamenot Jul 8, 2022
a63385a
Fix missing log forwarding.
Gamenot Jul 8, 2022
05717f0
Update zoo address dictionary call to get
Gamenot Jul 12, 2022
d6556a0
Do final updates.
Gamenot Jul 12, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-base-tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
. ${{env.venv_dir}}/bin/activate
pip install --upgrade pip
pip install --upgrade wheel
pip install -e .[camera-obs,opendrive,rllib,test,torch,train]
pip install -e .[camera-obs,opendrive,rllib,test,test-notebook,torch,train]
- name: Run smoke tests
run: |
. ${{env.venv_dir}}/bin/activate
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-base-tests-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
pip install --upgrade pip
pip install --upgrade wheel
pip install -r utils/setup/mac_requirements.txt
pip install -e .[camera-obs,opendrive,rllib,test,torch,train]
pip install -e .[camera-obs,opendrive,rllib,test,test-notebook,torch,train]
- name: Run smoke tests
run: |
. ${{env.venv_dir}}/bin/activate
Expand Down
101 changes: 7 additions & 94 deletions cli/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,88 +52,24 @@ def scenario_cli():
)
@click.argument("scenario", type=click.Path(exists=True), metavar="<scenario>")
def build_scenario(clean: bool, allow_offset_map: bool, scenario: str):
_build_single_scenario(clean, allow_offset_map, scenario)


def _build_single_scenario(clean: bool, allow_offset_map: bool, scenario: str):
click.echo(f"build-scenario {scenario}")
if clean:
_clean(scenario)

scenario_root = Path(scenario)
scenario_root_str = str(scenario_root)
from smarts.sstudio.build_scenario import build_single_scenario

scenario_py = scenario_root / "scenario.py"
if scenario_py.exists():
_install_requirements(scenario_root)
subprocess.check_call([sys.executable, "scenario.py"], cwd=scenario_root)

from smarts.core.scenario import Scenario

traffic_histories = Scenario.discover_traffic_histories(scenario_root_str)
# don't shift maps for scenarios with traffic histories since history data must line up with map
shift_to_origin = not allow_offset_map and not bool(traffic_histories)

map_spec = Scenario.discover_map(scenario_root_str, shift_to_origin=shift_to_origin)
road_map, _ = map_spec.builder_fn(map_spec)
if not road_map:
click.echo(
"No reference to a RoadNetwork file was found in {}, or one could not be created. "
"Please make sure the path passed is a valid Scenario with RoadNetwork file required "
"(or a way to create one) for scenario building.".format(scenario_root_str)
)
return

road_map.to_glb(os.path.join(scenario_root, "map.glb"))
build_single_scenario(clean, allow_offset_map, scenario, click.echo)


def _build_single_scenario_proc(
clean: bool, allow_offset_map: bool, scenario: str, semaphore: synchronize.Semaphore
):
from smarts.sstudio.build_scenario import build_single_scenario

semaphore.acquire()
try:
_build_single_scenario(clean, allow_offset_map, scenario)
build_single_scenario(clean, allow_offset_map, scenario, click.echo)
finally:
semaphore.release()


def _install_requirements(scenario_root):
import importlib.resources as pkg_resources

requirements_txt = scenario_root / "requirements.txt"
if requirements_txt.exists():
import zoo.policies

with pkg_resources.path(zoo.policies, "") as path:
# Serve policies through the static file server, then kill after
# we've installed scenario requirements
pip_index_proc = subprocess.Popen(
["twistd", "-n", "web", "--path", path],
# Hide output to keep display simple
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)

pip_install_cmd = [
sys.executable,
"-m",
"pip",
"install",
"-r",
str(requirements_txt),
]

click.echo(
f"Installing scenario dependencies via '{' '.join(pip_install_cmd)}'"
)

try:
subprocess.check_call(pip_install_cmd, stdout=subprocess.DEVNULL)
finally:
pip_index_proc.terminate()
pip_index_proc.wait()


def _is_scenario_folder_to_build(path: str) -> bool:
if os.path.exists(os.path.join(path, "waymo.yaml")):
# for now, don't try to build Waymo scenarios...
Expand Down Expand Up @@ -195,32 +131,9 @@ def build_all_scenarios(clean: bool, allow_offset_maps: bool, scenarios: str):
)
@click.argument("scenario", type=click.Path(exists=True), metavar="<scenario>")
def clean_scenario(scenario: str):
_clean(scenario)
from smarts.sstudio.build_scenario import clean_scenario


def _clean(scenario: str):
to_be_removed = [
"map.glb",
"map_spec.pkl",
"bubbles.pkl",
"missions.pkl",
"flamegraph-perf.log",
"flamegraph.svg",
"flamegraph.html",
"*.rou.xml",
"*.rou.alt.xml",
"social_agents/*",
"traffic/*.rou.xml",
"traffic/*.smarts.xml",
"history_mission.pkl",
"*.shf",
"*-AUTOGEN.net.xml",
]
p = Path(scenario)
for file_name in to_be_removed:
for f in p.glob(file_name):
# Remove file
f.unlink()
clean_scenario(scenario)


@scenario_cli.command(name="replay", help="Play saved Envision data files in Envision.")
Expand Down
3 changes: 3 additions & 0 deletions docs/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ To setup the simulator, which is called SMARTS, run the following commands,
# OPTIONAL: install [camera-obs] version of python package with the panda3D dependencies if you want to render camera sensor observations in your simulations
pip install -e .[camera-obs]

# OPTIONAL: install [opendrive] version of python package with the OpenDRIVE related dependencies if you are using the any OpenDRIVE related scenarios
pip install -e .[opendrive]

# make sure you can run sanity-test (and verify they are passing)
# if tests fail, check './sanity_test_result.xml' for test report.
pip install -e .[test]
Expand Down
1 change: 1 addition & 0 deletions envision/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def read_and_send(
wait_between_retries: float = 0.5,
):
"""Send a pre-recorded envision simulation to the envision server."""

client = Client(
endpoint=endpoint,
wait_between_retries=wait_between_retries,
Expand Down
1 change: 1 addition & 0 deletions envision/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def get(self):

def make_app(scenario_dirs: Sequence, max_capacity_mb: float, debug: bool):
"""Create the envision web server application through composition of services."""

with pkg_resources.path(web_dist, ".") as dist_path:
return tornado.web.Application(
[
Expand Down
10 changes: 0 additions & 10 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
class RayException(Exception):
"""An exception raised if ray package is required but not available."""

@classmethod
def required_to(cls, thing):
return cls(
f"""Ray Package is required to simulate {thing}.
You may not have installed the [rllib] or [train] dependencies required to run the ray dependent example.
Install them first using the command `pip install -e .[train, rllib]` at the source directory to install the package ray[rllib]==1.0.1.post1"""
)
4 changes: 2 additions & 2 deletions examples/driving_in_traffic/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ websocket-client==1.2.1
Werkzeug==2.0.2
wrapt==1.12.1
yattag==1.14.0
zipp==3.6.0
zope.interface==5.4.0
zipp==3.7.0
zope.interface==5.4.0
152 changes: 152 additions & 0 deletions examples/env/create_run_visualize.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "wkR0YvENQni4"
},
"source": [
"**Setup dependencies**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "n1sQVa5mkMEA",
"outputId": "dbfa09f5-0fd9-4a51-f728-fc62230f1b84"
},
"outputs": [],
"source": [
"!git clone https://github.com/huawei-noah/SMARTS 2> /dev/null\n",
"!cd SMARTS && ls && git checkout develop && pip install .[camera-obs,remote_agent]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ubc6jEAqiCEq",
"outputId": "16e9facc-86bc-4f72-a4f2-2d8bb2961435"
},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(0, \"/content/SMARTS/\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "s7UtcphinvNv"
},
"source": [
"**Import Base Modules**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "HsnDWYx_ngdc"
},
"outputs": [],
"source": [
"import gym\n",
"\n",
"from smarts.zoo import registry\n",
"from smarts.env.wrappers.episode_logger import EpisodeLogger"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "LFoG7Z-FobPP"
},
"source": [
"**Run an episode**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "BBWj3wbAso3J",
"outputId": "63c1d665-b4a5-43b5-d926-b02b5bcce08f"
},
"outputs": [],
"source": [
"from smarts.core.utils.episodes import episode_range\n",
"from smarts.env.wrappers.record_video import RecordVideo\n",
"\n",
"import examples.env.figure_eight_env\n",
"env = gym.make(\"figure_eight-v0\")\n",
"env: gym.Env = RecordVideo(\n",
" env, video_folder=\"videos\", video_length=40, step_trigger=lambda s: s % 100 == 0\n",
")\n",
"env: gym.Env = EpisodeLogger(env)\n",
"\n",
"import zoo.policies.keep_lane_agent\n",
"agent = registry.make_agent(\"zoo.policies:keep-lane-agent-v0\")\n",
"\n",
"for episode in episode_range(max_steps=450):\n",
" observation = env.reset()\n",
" reward, done, info = None, False, None\n",
" while episode.continues(observation, reward, done, info):\n",
" action = agent.act(observation)\n",
" observation, reward, done, info = env.step(action)\n",
"\n",
"env.close()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from smarts.env.wrappers.utils.rendering import show_notebook_videos\n",
"show_notebook_videos()"
]
}
],
"metadata": {
"colab": {
"name": "mock_demo.ipynb",
"provenance": []
},
"interpreter": {
"hash": "11a534571de20c647cd170207b7bb5d28d7f55463a5594e721a86394d5987d81"
},
"kernelspec": {
"display_name": "Python 3.8.10 ('.venv': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
41 changes: 41 additions & 0 deletions examples/env/figure_eight_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pathlib import Path

import gym

from smarts.zoo.agent_spec import AgentSpec
from smarts.core.agent_interface import AgentInterface, AgentType
from smarts.env.wrappers.single_agent import SingleAgent

agent_spec = AgentSpec(
interface=AgentInterface.from_type(
AgentType.Laner,
max_episode_steps=150,
rgb=True,
ogm=True,
drivable_area_grid_map=True,
),
agent_builder=None,
)


def entry_point(*args, **kwargs):
from smarts.env.hiway_env import HiWayEnv

scenario = str((Path(__file__).parent / "../../scenarios/figure_eight").resolve())
## Note: can build the scenario here
from smarts.sstudio.build_scenario import build_single_scenario

build_single_scenario(clean=True, allow_offset_map=True, scenario=scenario)
hiwayenv = HiWayEnv(
agent_specs={"agent-007": agent_spec},
scenarios=[scenario],
headless=True,
sumo_headless=True,
)
hiwayenv.metadata["render.modes"] = set(hiwayenv.metadata["render.modes"]) | {
"rgb_array"
}
return SingleAgent(hiwayenv)


gym.register("figure_eight-v0", entry_point=entry_point)
Loading