Skip to content

Commit

Permalink
Post clean assets (#482)
Browse files Browse the repository at this point in the history
* publish process/fix asset missing

* format

* log system and depth cam fix

* add a version file

* check asset version automatically

* reload logger if it is None

* fix logger bug

* fix logger

* create folder legacy env
  • Loading branch information
QuanyiLi committed Aug 22, 2023
1 parent b58863f commit c47cd02
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<br>

![](metadrive/assets/logo-horizon.png)
![](documentation/source/figs/logo-horizon.png)

<br>

Expand Down
Binary file added documentation/source/figs/logo-horizon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion documentation/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. image:: ../../metadrive/assets/logo-horizon.png
.. image:: figs/logo-horizon.png
:width: 1800
:align: center

Expand Down
2 changes: 1 addition & 1 deletion documentation/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Installation:

#. After cloning the repo, use ``pip install -e .[cuda]`` to install, or ``pip install -e metadrive-simulator[cuda]`` if you are using pip.
#. Install Torch: ``conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge``
#. Install CuPy: ``conda install -c conda-forge cupy``
#. Install CuPy: ``pip install cupy-cuda11x``
#. Install Cuda-Python: ``conda install -c nvidia cuda-python``
#. For verifying your installation, cd ``metadrive/examples`` and run ``python verify_image_on_cuda.py``

Expand Down
4 changes: 2 additions & 2 deletions metadrive/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from panda3d.bullet import BulletWorld
from panda3d.core import Vec3
from panda3d.core import Vec4, BitMask32

from metadrive.version import VERSION
from metadrive.type import MetaDriveType

EDITION = "MetaDrive v0.3.0.1"
EDITION = "MetaDrive v{}".format(VERSION)
DATA_VERSION = EDITION # Use MetaDrive version to mark the data version
DEFAULT_AGENT = "default_agent"
RENDER_MODE_NONE = "none" # Do not render
Expand Down
24 changes: 19 additions & 5 deletions metadrive/engine/asset_loader.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import logging
import os
from metadrive.version import VERSION
import pathlib
import sys

from metadrive.engine.logger import get_logger
from metadrive.utils.utils import is_win


class AssetLoader:
"""
Load model for each element when render is needed.
"""
logger = get_logger("Asset")
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 All @@ -19,10 +20,23 @@ def init_loader(engine):
"""
Due to the feature of Panda3d, keep reference of loader in static variable
"""
asset_version = os.path.join(AssetLoader.asset_path, "version.txt")
if not os.path.exists(asset_version):
AssetLoader.logger.fatal("Missing assets/version.txt file! Abort")
raise FileExistsError("Missing assets/version.txt file! Abort")
else:
with open(asset_version, "r") as file:
lines = file.readlines()
if lines[0] != VERSION:
AssetLoader.logger.warning(
"Assets version mismatch! Current: {}, Expected: {}".format(lines[0], VERSION)
)
else:
AssetLoader.logger.info("Assets version: {}".format(VERSION))
if engine.win is None:
logging.debug("Physics world mode")
AssetLoader.logger.debug("Physics world mode")
return
logging.debug("Onscreen/Offscreen mode, Render/Load Elements")
AssetLoader.logger.debug("Onscreen/Offscreen mode, Render/Load Elements")
AssetLoader.loader = engine.loader

@classmethod
Expand Down Expand Up @@ -68,7 +82,7 @@ def initialize_asset_loader(engine):
# load model file in utf-8
os.environ["PYTHONUTF8"] = "on"
if AssetLoader.initialized():
logging.warning(
AssetLoader.logger.warning(
"AssetLoader is initialize to root path: {}! But you are initializing again!".format(
AssetLoader.asset_path
)
Expand Down
20 changes: 16 additions & 4 deletions metadrive/envs/base_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from metadrive.version import VERSION
import time
from collections import defaultdict
from typing import Union, Dict, AnyStr, Optional, Tuple, Callable
Expand Down Expand Up @@ -205,7 +206,7 @@
multi_thread_render=True,
multi_thread_render_mode="Cull", # or "Cull/Draw"
preload_models=True, # preload pedestrian Object for avoiding lagging when creating it for the first time
log_level=None,
log_level=logging.INFO,

# record/replay metadata
record_episode=False, # when replay_episode is not None ,this option will be useless
Expand Down Expand Up @@ -260,6 +261,7 @@ def __init__(self, config: dict = None):
def _post_process_config(self, config):
"""Add more special process to merged config"""
# Cancel interface panel
self.logger.info("MetaDrive version: {}".format(VERSION))
if not config["show_interface"]:
config["interface_panel"] = []

Expand Down Expand Up @@ -302,10 +304,11 @@ def _post_process_config(self, config):
config["vehicle_config"]["image_source"], config["sensors"])

# show sensor lists
_str = "Sensors:"
_str = "Sensors: [{}]"
sensors_str = ""
for _id, cfg in config["sensors"].items():
_str += "{}: {}, {}, ".format(_id, cfg[0] if isinstance(cfg[0], str) else cfg[0].__name__, cfg[1:])
self.logger.info(_str[:-2])
sensors_str += "{}: {}, {}, ".format(_id, cfg[0] if isinstance(cfg[0], str) else cfg[0].__name__, cfg[1:])
self.logger.info(_str.format(sensors_str[:-2]))

# determine render mode automatically
if config["use_render"]:
Expand Down Expand Up @@ -456,6 +459,11 @@ def reset(self, seed: Union[None, int] = None):
:param seed: The seed to set the env.
:return: 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
self._reset_global_seed(seed)
if self.engine is None:
Expand Down Expand Up @@ -548,6 +556,10 @@ def _get_step_return(self, actions, engine_info):
def close(self):
if self.engine is not None:
close_engine()
if self.logger is not None:
self.logger.handlers.clear()
del self.logger
self.logger = None

def force_close(self):
print("Closing environment ... Please wait")
Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion metadrive/tests/scripts/capture_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"vehicle_config": dict(
mini_map=(168 * w_f * 6, 84 * h_f * 6, 270), # buffer length, width
rgb_camera=(168 * w_f, 84 * h_f), # buffer length, width
depth_camera=(168 * w_f, 84 * h_f, True), # buffer length, width, view_ground
depth_camera=(168 * w_f, 84 * h_f), # buffer length, width, view_ground
show_navi_mark=False,
increment_steering=False,
wheel_friction=0.6,
Expand Down
2 changes: 1 addition & 1 deletion metadrive/tests/test_env/_test_remote_metadrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def _test_remote_metadrive_env():
from metadrive.envs.remote_env import RemoteMetaDrive
from metadrive.envs.legacy_envs.remote_env import RemoteMetaDrive
# Test
envs = [RemoteMetaDrive(dict(map=7)) for _ in range(3)]
ret = [env.reset() for env in envs]
Expand Down
2 changes: 1 addition & 1 deletion metadrive/tests/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def capture_headless_image(cuda, image_source="main_camera"):
image_observation=True,
sensors={
"rgb_camera": (RGBCamera, 84, 84),
"depth_camera": (DepthCamera, 512, 512, False)
"depth_camera": (DepthCamera, 512, 512)
},
interface_panel=[],
vehicle_config={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _test_depth_camera_as_obs(render=False):
image_observation=True,
image_on_cuda=True,
use_render=False,
vehicle_config=dict(image_source="depth_camera", depth_camera=(800, 600, False)),
vehicle_config=dict(image_source="depth_camera", depth_camera=(800, 600)),
show_interface=True,
show_logo=False,
show_fps=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"use_render": True,
"image_observation": True,
"rgb_clip": True,
"vehicle_config": dict(depth_camera=(200, 88, False), image_source="depth_camera"),
"vehicle_config": dict(depth_camera=(200, 88), image_source="depth_camera"),
"map_config": {
BaseMap.GENERATE_TYPE: MapGenerateMethod.BIG_BLOCK_NUM,
BaseMap.GENERATE_CONFIG: 12,
Expand Down
1 change: 1 addition & 0 deletions metadrive/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.3.0.1"
55 changes: 33 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# Please don't change the order of following packages!
import os
import sys
import urllib.request
import zipfile
from os import path

import os
import zipfile
import urllib.request
from setuptools import setup, find_namespace_packages # This should be place at top!

ROOT_DIR = os.path.dirname(__file__)


def get_version():
context = {}
with open('./metadrive/version.py', 'r') as file:
exec(file.read(), context)
return context['VERSION']


VERSION = get_version()
ASSET_URL = "https://github.com/metadriverse/metadrive/releases/download/MetaDrive-{}/assets.zip".format(VERSION)


def is_mac():
return sys.platform == "darwin"

Expand All @@ -29,9 +39,6 @@ def is_win():
exclude=("docs", "docs.*", "documentation", "documentation.*", "build.*"))
print("We will install the following packages: ", packages)

""" ===== Remember to modify the PG_EDITION at first ====="""
version = "0.3.0.1"
ASSET_URL = "https://github.com/metadriverse/metadrive/releases/download/MetaDrive-0.3.0.1/assets.zip"

def post_install():
TARGET_DIR = os.path.join(os.path.dirname(__file__), 'metadrive')
Expand Down Expand Up @@ -109,7 +116,7 @@ def post_install():
setup(
name="metadrive-simulator",
python_requires='>=3.6, <3.12', # do version check with assert
version=version,
version=VERSION,
description="An open-ended driving simulator with infinite scenes",
url="https://github.com/metadriverse/metadrive",
author="MetaDrive Team",
Expand All @@ -132,35 +139,39 @@ def post_install():
post_install()

"""
How to publish to pypi? Noted by Zhenghao in Dec 27, 2020.
How to publish to pypi and Draft github Release? Noted by Zhenghao and Quanyi in Dec 27, 2020.
Note: make sure you have the assets dir locally. we will include the assets with the .wheel file
Note: make sure you have the right assets dir locally. we will include the assets with the .wheel file
0. Rename version in metadrive/constants.py and setup.py
0. Rename VERSION in metadrive/version.py
1. Remove old files and ext_modules from setup() to get a clean wheel for all platforms in py3-none-any.wheel
1. Revise the version in metadrive/assets/version.txt
2. Remove old files and ext_modules from setup() to get a clean wheel for all platforms in py3-none-any.wheel
rm -rf dist/ build/ documentation/build/ metadrive_simulator.egg-info/ docs/build/
2. Rename current version to X.Y.Z.rcA, where A is arbitrary value represent "release candidate A".
3. Rename current version to X.Y.Z.rcA, where A is arbitrary value represent "release candidate A".
This is really important since pypi do not support renaming and re-uploading.
Rename version in metadrive/constants.py and setup.py
Rename version in metadrive/versions.py
3. Get wheel
4. Get wheel
python setup.py sdist bdist_wheel
WARNING: when create wheels on windows, modifying MANIFEST.in to include assets by using
recursive-include metadrive\\assets\\ *
recursive-include metadrive\\examples\\ *
4. Upload to test channel
5. Upload to test channel
twine upload --repository testpypi dist/*
5. Test as next line. If failed, change the version name and repeat 1, 2, 3, 4, 5.
6. Test as next line. If failed, change the version name and repeat 1, 2, 3, 4, 5.
pip install --index-url https://test.pypi.org/simple/ metadrive
6. Rename current version to X.Y.Z in setup.py, rerun 1, 3 steps.
7. Rename current version to X.Y.Z in setup.py, rerun 1, 3 steps.
7. Upload to production channel
8. Upload to production channel
twine upload dist/*
9. Draft a release on github with new version number
10. upload the generated .whl file and new assets folder compressed and named to assets.zip
!!!!!!!!!!!!! NOTE: please make sure that unzip assets.zip will generate a folder called assets instead of files
"""

0 comments on commit c47cd02

Please sign in to comment.