Skip to content

Commit

Permalink
Fix CI (metadriverse#727)
Browse files Browse the repository at this point in the history
* fix navi infor collection

* fix pstats bug

* format

* fix lane line detecor test

* add time sleep for python garbage collection

* use test
  • Loading branch information
QuanyiLi committed Jun 1, 2024
1 parent 233a3a1 commit 05ec6c8
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 255 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@
/documentation/**/**.gif
/documentation/source/img.png
/documentation/source/demo.png

# ignore documentation build output
**/filtered_dataset
**/semantics.png
11 changes: 0 additions & 11 deletions documentation/source/debug_mode.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,6 @@
"In addition to the errors raised from MetaDrive, sometimes the game engine, Panda3D, will throw errors and warnings about the rendering service. To enable the logging of Panda3D, set `env_config[\"debug_panda3d\"]=True`. Besides, you can turn on Panda3D's profiler via `env_config[\"pstats\"]=True` and launch the `pstats` in the terminal. It can be used to analyze your program in terms of the time consumed for different functions like rendering, physics and so on, which is very useful if you are developing some graphics related features."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b3e2ecb",
"metadata": {},
"outputs": [],
"source": [
"# launch pstats (bash)\n",
"!pstats"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
20 changes: 9 additions & 11 deletions documentation/source/obs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"cell_type": "markdown",
"id": "72c167e8",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
Expand Down Expand Up @@ -415,7 +414,6 @@
"execution_count": 4,
"id": "ff7a70aa",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
Expand Down Expand Up @@ -544,7 +542,6 @@
"execution_count": 45,
"id": "3562290f",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
Expand Down Expand Up @@ -592,7 +589,6 @@
"execution_count": 12,
"id": "995d5314-92a7-4e68-8bb8-05f1bd8ab718",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
Expand All @@ -619,7 +615,6 @@
"execution_count": 13,
"id": "7f20c293-77f9-451c-a552-882def3d6257",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
Expand Down Expand Up @@ -712,7 +707,6 @@
"execution_count": 10,
"id": "9ea9966f-f123-40e8-a432-1ac19f396431",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
Expand Down Expand Up @@ -806,13 +800,16 @@
"from metadrive.envs.metadrive_env import MetaDriveEnv\n",
"from metadrive.obs.state_obs import LidarStateObservation\n",
"from metadrive.component.sensors.rgb_camera import RGBCamera\n",
"import os\n",
"test_doc = os.getenv('TEST_DOC')\n",
"sensor_size = (84, 60) if test_doc else (200, 100)\n",
"\n",
"env = MetaDriveEnv(config=dict(\n",
" use_render=False,\n",
" agent_observation=LidarStateObservation,\n",
" image_observation=True,\n",
" norm_pixel=False,\n",
" sensors=dict(rgb_camera=(RGBCamera, 512, 256)),\n",
" sensors=dict(rgb_camera=(RGBCamera, *sensor_size)),\n",
"))\n",
"\n",
"obs, info = env.reset()\n",
Expand All @@ -822,9 +819,10 @@
"image = env.engine.get_sensor(\"rgb_camera\").perceive(to_float=False)\n",
"image = image[..., [2, 1, 0]]\n",
"\n",
"import matplotlib.pyplot as plt\n",
"plt.imshow(image)\n",
"plt.show()"
"if not test_doc:\n",
" import matplotlib.pyplot as plt\n",
" plt.imshow(image)\n",
" plt.show()"
]
}
],
Expand All @@ -844,7 +842,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.7.13"
},
"mystnb": {
"execution_mode": "force"
Expand Down
50 changes: 25 additions & 25 deletions metadrive/component/vehicle/base_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,37 @@ def before_step(self, action=None):
return step_info

def after_step(self):
step_info = {}
if self.navigation and self.config["navigation_module"]:
self.navigation.update_localization(self)
lanes_heading = self.navigation.navi_arrow_dir
lane_0_heading = lanes_heading[0]
lane_1_heading = lanes_heading[1]
navigation_straight = False
navigation_turn_left = False
navigation_turn_right = False
if abs(wrap_to_pi(lane_0_heading - lane_1_heading)) < 10 / 180 * math.pi:
navigation_straight = True
else:
dir_0 = np.array([math.cos(lane_0_heading), math.sin(lane_0_heading), 0])
dir_1 = np.array([math.cos(lane_1_heading), math.sin(lane_1_heading), 0])
cross_product = np.cross(dir_1, dir_0)
navigation_turn_left = True if cross_product[-1] < 0 else False
navigation_turn_right = not navigation_turn_left
step_info.update(
{
"navigation_command": "forward" if navigation_straight else
("left" if navigation_turn_left else "right"),
"navigation_forward": navigation_straight,
"navigation_left": navigation_turn_left,
"navigation_right": navigation_turn_right
}
)
self._state_check()
self.update_dist_to_left_right()
step_energy, episode_energy = self._update_energy_consumption()
self.out_of_route = self._out_of_route()
step_info = self._update_overtake_stat()
step_info.update(self._update_overtake_stat())
my_policy = self.engine.get_policy(self.name)
step_info.update(
{
Expand All @@ -250,30 +274,6 @@ def after_step(self):
"policy": my_policy.name if my_policy is not None else my_policy
}
)

lanes_heading = self.navigation.navi_arrow_dir
lane_0_heading = lanes_heading[0]
lane_1_heading = lanes_heading[1]
navigation_straight = False
navigation_turn_left = False
navigation_turn_right = False
if abs(wrap_to_pi(lane_0_heading - lane_1_heading)) < 10 / 180 * math.pi:
navigation_straight = True
else:
dir_0 = np.array([math.cos(lane_0_heading), math.sin(lane_0_heading), 0])
dir_1 = np.array([math.cos(lane_1_heading), math.sin(lane_1_heading), 0])
cross_product = np.cross(dir_1, dir_0)
navigation_turn_left = True if cross_product[-1] < 0 else False
navigation_turn_right = not navigation_turn_left
step_info.update(
{
"navigation_command": "forward" if navigation_straight else
("left" if navigation_turn_left else "right"),
"navigation_forward": navigation_straight,
"navigation_left": navigation_turn_left,
"navigation_right": navigation_turn_right
}
)
return step_info

def _out_of_route(self):
Expand Down
14 changes: 14 additions & 0 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from metadrive.engine.logger import get_logger
from metadrive.utils.utils import is_mac, setup_logger
import logging
import subprocess
from metadrive.utils.utils import is_port_occupied

logger = get_logger()

Expand Down Expand Up @@ -121,9 +123,21 @@ def __init__(self, global_config):
self.pid = os.getpid()
EngineCore.global_config = global_config
self.mode = global_config["_render_mode"]
self.pstats_process = None
if self.global_config["pstats"]:
# pstats debug provided by panda3d
loadPrcFileData("", "want-pstats 1")
if not is_port_occupied(5185):
self.pstats_process = subprocess.Popen(['pstats'])
logger.info(
"pstats is launched successfully, tutorial is at: "
"https://docs.panda3d.org/1.10/python/optimization/using-pstats"
)
else:
logger.warning(
"pstats is already launched! tutorial is at: "
"https://docs.panda3d.org/1.10/python/optimization/using-pstats"
)

# Setup onscreen render
if self.global_config["use_render"]:
Expand Down
Loading

0 comments on commit 05ec6c8

Please sign in to comment.