Skip to content

Commit

Permalink
Sync Linux Update (#488)
Browse files Browse the repository at this point in the history
* update logger/pip requirement

* linux use old model

* fix bug

* unify logger

* update logger

* format

* navi color

* update color

* release new version

* force pull asset
  • Loading branch information
QuanyiLi committed Aug 25, 2023
1 parent 206f575 commit bf59ebc
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
pip install cython
pip install numpy
pip install -e .
python -m metadrive.pull_asset
pip install pytest
pip install pytest-cov
pip install ray
Expand All @@ -56,6 +57,7 @@ jobs:
pip install numpy
pip install gym
pip install -e .
python -m metadrive.pull_asset
pip install pytest
pip install pytest-cov
pip install ray
Expand All @@ -75,6 +77,7 @@ jobs:
pip install cython
pip install numpy
pip install -e .
python -m metadrive.pull_asset
pip install pytest
pip install pytest-cov
pip install ray
Expand All @@ -94,6 +97,7 @@ jobs:
pip install cython
pip install numpy
pip install -e .
python -m metadrive.pull_asset
pip install pytest
pip install pytest-cov
pip install ray
Expand All @@ -113,6 +117,7 @@ jobs:
pip install cython
pip install numpy
pip install -e .
python -m metadrive.pull_asset
pip install pytest
pip install pytest-cov
pip install ray
Expand Down
6 changes: 5 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
recursive-include metadrive/examples/ *
recursive-include metadrive\\examples\\ *
recursive-include metadrive\examples\ *
recursive-include metadrive\examples\ *

recursive-include metadrive/render_pipeline/ *
recursive-include metadrive\\render_pipeline\\ *
recursive-include metadrive\render_pipeline\ *
3 changes: 2 additions & 1 deletion metadrive/component/vehicle/vehicle_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from metadrive.engine.asset_loader import AssetLoader
from metadrive.component.pg_space import ParameterSpace, VehicleParameterSpace
from metadrive.component.vehicle.base_vehicle import BaseVehicle
import platform


def convert_path(pth):
Expand Down Expand Up @@ -146,7 +147,7 @@ class SVehicle(BaseVehicle):

@property
def path(self):
if self.use_render_pipeline:
if self.use_render_pipeline and platform.system() != "Linux":
# vfs = VirtualFileSystem.get_global_ptr()
# vfs.mount(convert_path(AssetLoader.file_path("models", "beetle")), "/$$beetle_model", 0)
return ['beetle/vehicle.bam', (0.0077, 0.0077, 0.0077), (0.04512, -0.24 - 0.04512, 1.77), (-90, -90, 0)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import logging
from collections import deque

import numpy as np
from panda3d.core import NodePath, Material

from metadrive.engine.logger import get_logger
from metadrive.component.vehicle_navigation_module.base_navigation import BaseNavigation
from metadrive.engine.asset_loader import AssetLoader
from metadrive.utils.coordinates_shift import panda_vector
from metadrive.utils.math import norm, clip
from metadrive.utils.math import panda_vector
from metadrive.utils.math import wrap_to_pi

logger = logging.getLogger(__file__)


class TrajectoryNavigation(BaseNavigation):
"""
Expand All @@ -34,7 +31,7 @@ def __init__(
vehicle_config=None
):
if show_dest_mark or show_line_to_dest:
logging.warning("show_dest_mark and show_line_to_dest are not supported in TrajectoryNavigation")
get_logger().warning("show_dest_mark and show_line_to_dest are not supported in TrajectoryNavigation")
super(TrajectoryNavigation, self).__init__(
show_navi_mark=False,
random_navi_mark_color=random_navi_mark_color,
Expand All @@ -61,9 +58,9 @@ def __init__(
self._navi_point_model.setScale(0.5)
if self.engine.use_render_pipeline:
material = Material()
material.setBaseColor((1, 1, 1, 1))
material.setShininess(128)
material.setEmission((1, 1, 1, 1))
material.setBaseColor((19 / 255, 212 / 255, 237 / 255, 1))
material.setShininess(16)
material.setEmission((0.2, 0.2, 0.2, 0.2))
self._navi_point_model.setMaterial(material, True)
self._navi_point_model.instanceTo(model)
model.reparentTo(self.origin)
Expand Down
2 changes: 1 addition & 1 deletion metadrive/engine/asset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AssetLoader:
"""
Load model for each element when render is needed.
"""
logger = get_logger("Asset")
logger = get_logger()
loader = None
asset_path = pathlib.PurePosixPath(__file__).parent.parent.joinpath("assets") if not is_win(
) else pathlib.Path(__file__).resolve().parent.parent.joinpath("assets")
Expand Down
2 changes: 1 addition & 1 deletion metadrive/engine/core/image_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
setup_pbr=False,
engine=None
):
self.logger = get_logger(self.__class__.__name__)
self.logger = get_logger()
self._node_path_list = []

# from metadrive.engine.engine_utils import get_engine
Expand Down
29 changes: 18 additions & 11 deletions metadrive/engine/logger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import logging

global_logger = None


class CustomFormatter(logging.Formatter):
grey = "\x1b[38;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = "[%(levelname)s] %(message)s (%(name)s %(filename)s:%(lineno)d)"
# format = "[%(levelname)s] %(message)s (%(name)s %(filename)s:%(lineno)d)"
format = "[%(levelname)s] %(message)s (%(filename)s:%(lineno)d)"
simple_format = "[%(levelname)s] %(message)s"

FORMATS = {
Expand All @@ -24,13 +27,17 @@ def format(self, record):
return formatter.format(record)


def get_logger(name, level=logging.INFO, propagate=False):
logger = logging.getLogger(name)
logger.setLevel(level)
logger.propagate = propagate
# create console handler with a higher log level
ch = logging.StreamHandler()
# create formatter and add it to the handlers
ch.setFormatter(CustomFormatter())
logger.addHandler(ch)
return logger
def get_logger(level=logging.INFO, propagate=False):
global global_logger
if global_logger is None:
logger = logging.getLogger("MetaDrive")
logger.propagate = propagate
# create console handler with a higher log level
ch = logging.StreamHandler()
# create formatter and add it to the handlers
ch.setFormatter(CustomFormatter())
logger.addHandler(ch)
global_logger = logger
if global_logger.level != level:
global_logger.setLevel(level)
return global_logger
22 changes: 11 additions & 11 deletions metadrive/envs/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ def default_config(cls) -> Config:
def __init__(self, config: dict = None):
if config is None:
config = {}
self.logger = get_logger(
self.logger_name, config.get("log_level", logging.DEBUG if config.get("debug", False) else logging.INFO)
)
self.logger = get_logger(config.get("log_level", logging.DEBUG if config.get("debug", False) else logging.INFO))
merged_config = self.default_config().update(config, False, ["target_vehicle_configs", "sensors"])
global_config = self._post_process_config(merged_config)
global_config["vehicle_config"]["main_camera"] = global_config["window_size"]
Expand Down Expand Up @@ -286,13 +284,16 @@ def _post_process_config(self, config):

# Merge vehicle_panel config with sensors
to_use = []
for panel in config["interface_panel"]:
if panel == "dashboard":
config["sensors"]["dashboard"] = (VehiclePanel, )
if panel not in config["sensors"]:
self.logger.warning("Fail to add sensor: {} to the interface. Remove it from panel list!".format(panel))
else:
to_use.append(panel)
if not config["render_pipeline"]:
for panel in config["interface_panel"]:
if panel == "dashboard":
config["sensors"]["dashboard"] = (VehiclePanel, )
if panel not in config["sensors"]:
self.logger.warning(
"Fail to add sensor: {} to the interface. Remove it from panel list!".format(panel)
)
else:
to_use.append(panel)
config["interface_panel"] = to_use

# Check sensor existence
Expand Down Expand Up @@ -461,7 +462,6 @@ def reset(self, seed: Union[None, int] = None):
"""
if self.logger is None:
self.logger = get_logger(
self.logger_name,
self.config.get("log_level", logging.DEBUG if self.config.get("debug", False) else logging.INFO)
)
self.lazy_init() # it only works the first time when reset() is called to avoid the error when render
Expand Down
22 changes: 10 additions & 12 deletions metadrive/envs/scenario_env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
This environment can load all scenarios exported from other environments via env.export_scenarios()
"""
import logging

import numpy as np

from metadrive.component.sensors.vehicle_panel import VehiclePanel
Expand Down Expand Up @@ -169,13 +167,13 @@ def next_seed_reset(self):
if self.current_seed + 1 < self.config["start_scenario_index"] + self.config["num_scenarios"]:
self.reset(self.current_seed + 1)
else:
logging.warning("Can't load next scenario! current seed is already the max scenario index")
self.logger.warning("Can't load next scenario! current seed is already the max scenario index")

def last_seed_reset(self):
if self.current_seed - 1 >= self.config["start_scenario_index"]:
self.reset(self.current_seed - 1)
else:
logging.warning("Can't load last scenario! current seed is already the min scenario index")
self.logger.warning("Can't load last scenario! current seed is already the min scenario index")

def step(self, actions):
ret = super(ScenarioEnv, self).step(actions)
Expand Down Expand Up @@ -204,42 +202,42 @@ def msg(reason):

if self._is_arrive_destination(vehicle):
done = True
logging.info(msg("arrive_dest"))
self.logger.info(msg("arrive_dest"))
done_info[TerminationState.SUCCESS] = True

elif self._is_out_of_road(vehicle) or route_completion < -0.1:
done = True
logging.info(msg("out_of_road"))
self.logger.info(msg("out_of_road"))
done_info[TerminationState.OUT_OF_ROAD] = True
elif vehicle.crash_human and self.config["crash_human_done"]:
done = True
logging.info(msg("crash human"))
self.logger.info(msg("crash human"))
done_info[TerminationState.CRASH_HUMAN] = True
elif vehicle.crash_vehicle and self.config["crash_vehicle_done"]:
done = True
logging.info(msg("crash vehicle"))
self.logger.info(msg("crash vehicle"))
done_info[TerminationState.CRASH_VEHICLE] = True
elif vehicle.crash_object and self.config["crash_object_done"]:
done = True
done_info[TerminationState.CRASH_OBJECT] = True
logging.info(msg("crash object"))
self.logger.info(msg("crash object"))
elif vehicle.crash_building and self.config["crash_object_done"]:
done = True
done_info[TerminationState.CRASH_BUILDING] = True
logging.info(msg("crash building"))
self.logger.info(msg("crash building"))

elif self.config["horizon"] is not None and \
self.episode_lengths[vehicle_id] >= self.config["horizon"] and not self.is_multi_agent:
done = True
done_info[TerminationState.MAX_STEP] = True
logging.info(msg("max step"))
self.logger.info(msg("max step"))

elif self.config["allowed_more_steps"] is not None and \
self.episode_lengths[vehicle_id] >= self.engine.data_manager.current_scenario_length + self.config[
"allowed_more_steps"] and not self.is_multi_agent:
done = True
done_info[TerminationState.MAX_STEP] = True
logging.info(msg("more step than original episode"))
self.logger.info(msg("more step than original episode"))

# for compatibility
# crash almost equals to crashing with vehicles
Expand Down
4 changes: 2 additions & 2 deletions metadrive/pull_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __call__(self, block_num, block_size, total_size):


def pull_asset(update):
logger = get_logger("Asset", propagate=False)
logger = get_logger(propagate=False)
logger.handlers.pop()
TARGET_DIR = os.path.join(os.path.dirname(__file__))
if os.path.exists(os.path.join(TARGET_DIR, "assets")):
Expand All @@ -57,7 +57,7 @@ def pull_asset(update):
zip_path = os.path.join(TARGET_DIR, 'assets.zip')

# Fetch the zip file
logger.info("Pull the assets from {}".format(ASSET_URL))
logger.info("Pull assets from {}".format(ASSET_URL))
urllib.request.urlretrieve(ASSET_URL, zip_path, MyProgressBar())

# Extract the zip file to the desired location
Expand Down
4 changes: 2 additions & 2 deletions metadrive/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
envs.append(env_name)
gym.register(id=env_name, entry_point=entry, kwargs=dict(config={}))

if len(envs) > 0:
get_logger("Gym").info("Successfully registered the following environments: {}.".format(envs))
# if len(envs) > 0:
# get_logger("Gym").info("Successfully registered the following environments: {}.".format(envs))

if __name__ == '__main__':
# Test purpose only
Expand Down
2 changes: 1 addition & 1 deletion metadrive/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

VERSION = "0.4.1.1"
VERSION = "0.4.1.2"


def asset_version():
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def is_win():
"panda3d-gltf==0.13", # 0.14 will bring some problems
"panda3d-simplepbr",
"pillow",
"protobuf==3.20.3",
"pytest",
"opencv-python",
"lxml",
Expand Down Expand Up @@ -122,7 +121,7 @@ def is_win():
1. Rename VERSION in metadrive/version.py to x.y.z
2. Revise the version in metadrive/assets/version.txt, and compress the folder into assets.zip
2. Revise the version in metadrive/assets/version.txt, and compress the folder: zip -r assets.zip assets
3. commit changes and push this branch to remote
Expand Down

0 comments on commit bf59ebc

Please sign in to comment.