Skip to content

Commit

Permalink
Update the simulation section (#572)
Browse files Browse the repository at this point in the history
* suppress device warning

* add system design

* add system design to .ipynb

* text

* system design

* more update

* fix simple pbr to 0.10.0

* format
  • Loading branch information
QuanyiLi committed Dec 5, 2023
1 parent e001457 commit 73187f6
Show file tree
Hide file tree
Showing 15 changed files with 798 additions and 32 deletions.
41 changes: 38 additions & 3 deletions documentation/source/action.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@
"metadata": {},
"source": [
"### ReplayPolicy\n",
"Usually, we use [ScenarioNet](https://metadriverse.github.io/scenarionet/) to convert scenarios collected by Waymo, nuScenes, nuPlan, and Argoverse to internal [Scenario Description](TODO) and rebuild the scenarios in MetaDrive. Thus this policy is used to load and replay the recorded traffic trajectories for these real-world scenarios. There are two replay policies for replaying the trajectories of ego car and traffic participants, respectively:\n",
"Usually, we use [ScenarioNet](https://metadriverse.github.io/scenarionet/) to convert scenarios collected by Waymo, nuScenes, nuPlan, and Argoverse to internal [Scenario Description](description.ipynb) and rebuild the scenarios in MetaDrive. Thus this policy is used to load and replay the recorded traffic trajectories for these real-world scenarios. There are two replay policies for replaying the trajectories of ego car and traffic participants, respectively:\n",
"* **ReplayEgoCarPolicy**\n",
"* **ReplayTrafficParticipantPolicy**\n",
"\n",
Expand Down Expand Up @@ -950,7 +950,42 @@
"metadata": {},
"source": [
"## Customization\n",
"To make a new policy suiting your need, just create a subclass of `BasePolicy` and override mainly the function `def act()`. If this policy will be assigned to an agent, it has to have a correctly defined `get_input_space`, which will be used to create `env.action_space`. "
"To make a new policy suiting your need, just create a subclass of `BasePolicy` and override mainly the function `def act()`. If this policy will be assigned to an agent, it has to have a correctly defined `get_input_space`, which will be used to create `env.action_space`. \n",
"The following example shows how to create a policy always executing a left-turning command."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "91f88dc8-80d6-466e-9033-793e49ec03fe",
"metadata": {},
"outputs": [],
"source": [
"from metadrive.policy.base_policy import BasePolicy\n",
"from metadrive.envs import MetaDriveEnv\n",
"from IPython.display import clear_output, Image\n",
"\n",
"class LeftTurningPolicy(BasePolicy):\n",
" def act(self, *args, **kwargs):\n",
" # Always turn left\n",
" return [0.4, 0.4]\n",
"\n",
"env = MetaDriveEnv(dict(agent_policy=LeftTurningPolicy,\n",
" map=\"S\"))\n",
"try:\n",
" env.reset()\n",
" for _ in range(220):\n",
" env.step([-1, -1]) # it doesn't take effect \n",
" env.render(mode=\"topdown\", \n",
" window=False,\n",
" screen_size=(200, 250),\n",
" camera_position=(0, 20),\n",
" screen_record=True)\n",
" env.top_down_renderer.generate_gif()\n",
"finally:\n",
" env.close()\n",
" clear_output()\n",
"Image(open(\"demo.gif\", 'rb').read())"
]
}
],
Expand All @@ -970,7 +1005,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.13"
"version": "3.9.17"
},
"mystnb": {
"execution_mode": "auto"
Expand Down
18 changes: 0 additions & 18 deletions documentation/source/concept.rst

This file was deleted.

13 changes: 12 additions & 1 deletion documentation/source/config_system.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@
"assert not SCENARIO_ENV_CONFIG[\"show_sidewalk\"]"
]
},
{
"cell_type": "markdown",
"id": "5dab9545-cc22-4634-addf-6553e78abd06",
"metadata": {},
"source": [
"### Programming with Configs\n",
"\n",
"The configs can be accessed everywhere in the program just like the simulation engine instance, so we can use these parameters to adjust the behavior of the simulation.\n",
"A tutorial of accessing configs when programming new environments is available at <a href=\"system_design.html#config\">config</a>."
]
},
{
"cell_type": "markdown",
"id": "e43d0c22",
Expand Down Expand Up @@ -257,7 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.13"
"version": "3.9.17"
},
"mystnb": {
"execution_mode": "force"
Expand Down
33 changes: 33 additions & 0 deletions documentation/source/description.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6bac10fe-c1e7-4896-8925-53801b27f796",
"metadata": {},
"source": [
"# Scenario Description "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.17"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added documentation/source/figs/execution_queue.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/source/figs/sim.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion documentation/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ Please feel free to contact us if you have any suggestions or ideas!
:maxdepth: 2
:caption: Concepts and Customization

concept.rst
system_design.ipynb
development.rst
top_down_render.ipynb
policy.rst
navigation.ipynb
sensors.ipynb
gui.ipynb
description.ipynb
record_replay.ipynb

.. toctree::
Expand Down

0 comments on commit 73187f6

Please sign in to comment.