Skip to content

Commit

Permalink
Releases/0.4.0.1 (#483)
Browse files Browse the repository at this point in the history
* fix bug

* update example

* format

* move render pipe to engine core

* bypass the check process

* post pull asset

* update doc

* pull asset

* fix pull bug

* releases/0.4.0.1

* format

* include examples

* update wrokflow

* 0.4.0.2
  • Loading branch information
QuanyiLi committed Aug 22, 2023
1 parent c47cd02 commit ec35a0c
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 58 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/docs/.idea/
/build/
/dist/
**/assets.zip
/documentation/build/
/metadrive.egg-info/
.DS_Store
Expand Down
3 changes: 0 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
recursive-include metadrive/assets/ *
recursive-include metadrive/examples/ *
recursive-include metadrive\\assets\\ *
recursive-include metadrive\\examples\\ *
recursive-include metadrive\assets\ *
recursive-include metadrive\examples\ *
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ Install MetaDrive via:
git clone https://github.com/metadriverse/metadrive.git
cd metadrive
pip install -e .

# pull asset
python -m metadrive.pull_asset
```

or

```bash
pip install metadrive-simulator

# pull asset
python -m metadrive.pull_asset
```
*Note that the program is tested on both Linux and Windows. Some control and display issues in MacOS wait to be solved*

Expand Down
2 changes: 2 additions & 0 deletions documentation/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ We recommend to use the command following to install::
cd metadrive
pip install -e .

# pull asset
python -m metadrive.pull_asset

To check whether MetaDrive is successfully installed, please run::

Expand Down
2 changes: 1 addition & 1 deletion metadrive/component/sensors/vehicle_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VehiclePanel(ImageBuffer):
TASK_NAME = "update panel"
display_region_size = [2 / 3, 1, 0.8, 1.0]

def __init__(self, engine):
def __init__(self, engine, *, cuda):
if engine.win is None:
return
self.aspect2d_np = NodePath(PGTop("aspect2d"))
Expand Down
27 changes: 18 additions & 9 deletions metadrive/engine/asset_loader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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
from metadrive.version import VERSION


class AssetLoader:
Expand All @@ -20,16 +21,15 @@ 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")
msg = "Assets folder doesn't exist. Download assets by `python -m metadrive.pull_asset`"
if not os.path.exists(AssetLoader.asset_path):
AssetLoader.logger.fatal(msg)
raise FileExistsError(msg)
else:
with open(asset_version, "r") as file:
lines = file.readlines()
if lines[0] != VERSION:
if asset_version() != VERSION:
AssetLoader.logger.warning(
"Assets version mismatch! Current: {}, Expected: {}".format(lines[0], VERSION)
"Assets version mismatch! Current: {}, Expected: {}. "
"Update the assets by `python -m metadrive.pull_asset --update'".format(asset_version(), VERSION)
)
else:
AssetLoader.logger.info("Assets version: {}".format(VERSION))
Expand All @@ -39,6 +39,10 @@ def init_loader(engine):
AssetLoader.logger.debug("Onscreen/Offscreen mode, Render/Load Elements")
AssetLoader.loader = engine.loader

@property
def asset_version(self):
return asset_version()

@classmethod
def get_loader(cls):
assert AssetLoader.loader, "Please initialize AssetLoader before getting it!"
Expand Down Expand Up @@ -110,3 +114,8 @@ def get_logo_file():
file = AssetLoader.file_path("logo-tiny.png")
# assert os.path.exists(file)
return file


def asset_version():
from metadrive.version import asset_version
return asset_version()
4 changes: 2 additions & 2 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from metadrive.engine.core.physics_world import PhysicsWorld
from metadrive.engine.core.sky_box import SkyBox
from metadrive.engine.core.terrain import Terrain
from metadrive.render_pipeline.rpcore import RenderPipeline
from metadrive.render_pipeline.rpcore.rpobject import RPObject
from metadrive.utils.utils import is_mac, setup_logger


Expand Down Expand Up @@ -131,6 +129,8 @@ def __init__(self, global_config):
loadPrcFileData("", "win-size {} {}".format(*self.global_config["window_size"]))

if self.use_render_pipeline:
from metadrive.render_pipeline.rpcore import RenderPipeline
from metadrive.render_pipeline.rpcore.rpobject import RPObject
if not self.global_config["debug"]:
RPObject.set_output_level("warning") # warning
self.render_pipeline = RenderPipeline()
Expand Down
2 changes: 1 addition & 1 deletion metadrive/envs/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _post_process_config(self, config):
_str = "Sensors: [{}]"
sensors_str = ""
for _id, cfg in config["sensors"].items():
sensors_str += "{}: {}, {}, ".format(_id, cfg[0] if isinstance(cfg[0], str) else cfg[0].__name__, cfg[1:])
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
Expand Down
1 change: 1 addition & 0 deletions metadrive/examples/drive_in_multi_agent_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"Quit": "ESC",
"Number of existing vehicles": len(env.vehicles),
"Tracked agent (Press Q)": env.engine.agent_manager.object_to_agent(env.current_track_vehicle.id),
"Keyboard Control": "W,A,S,D",
# "Auto-Drive (Switch mode: T)": "on" if env.current_track_vehicle.expert_takeover else "off",
} if not args.top_down else {}
)
Expand Down
3 changes: 2 additions & 1 deletion metadrive/examples/drive_in_safe_metadrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
env.render(
text={
"Auto-Drive (Switch mode: T)": "on" if env.current_track_vehicle.expert_takeover else "off",
"Total episode cost": env.episode_cost
"Total episode cost": env.episode_cost,
"Keyboard Control": "W,A,S,D",
}
)
if not previous_takeover and env.current_track_vehicle.expert_takeover:
Expand Down
12 changes: 10 additions & 2 deletions metadrive/examples/drive_in_single_agent_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
environment that allows popping up an window.
"""
import argparse
import logging
import random

import cv2
Expand Down Expand Up @@ -35,7 +36,13 @@
parser.add_argument("--observation", type=str, default="lidar", choices=["lidar", "rgb_camera"])
args = parser.parse_args()
if args.observation == "rgb_camera":
config.update(dict(image_observation=True, sensors=dict(rgb_camera=(RGBCamera, 512, 256))))
config.update(
dict(
image_observation=True,
sensors=dict(rgb_camera=(RGBCamera, 512, 256)),
interface_panel=["rgb_camera", "dashboard"]
)
)
else:
config["vehicle_config"]["show_lidar"] = True
env = MetaDriveEnv(config)
Expand All @@ -54,7 +61,8 @@
env.render(
text={
"Auto-Drive (Switch mode: T)": "on" if env.current_track_vehicle.expert_takeover else "off",
"Current Observation": args.observation
"Current Observation": args.observation,
"Keyboard Control": "W,A,S,D",
}
)

Expand Down
3 changes: 2 additions & 1 deletion metadrive/examples/drive_in_waymo_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def reset(self, seed=None):
text={
"Quit": "ESC",
"Switch perspective": "Q or B",
"Reset Episode": "R"
"Reset Episode": "R",
"Keyboard Control": "W,A,S,D",
},
**extra_args
)
Expand Down
74 changes: 74 additions & 0 deletions metadrive/pull_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
import shutil
import urllib.request
import zipfile
import argparse
from metadrive.engine.logger import get_logger
from metadrive.version import asset_version
from metadrive.constants import VERSION
import progressbar

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


class MyProgressBar():
def __init__(self):
self.pbar = None

def __call__(self, block_num, block_size, total_size):
if not self.pbar:
self.pbar = progressbar.ProgressBar(maxval=total_size)
self.pbar.start()

downloaded = block_num * block_size
if downloaded < total_size:
self.pbar.update(downloaded)
else:
self.pbar.finish()


def pull_asset():
logger = get_logger("Asset", propagate=False)
logger.handlers.pop()
parser = argparse.ArgumentParser()
parser.add_argument("--update", action="store_true", help="Force overwrite the current assets")
args = parser.parse_args()
TARGET_DIR = os.path.join(os.path.dirname(__file__))
if os.path.exists(os.path.join(TARGET_DIR, "assets")):
if not args.update:
logger.warning(
"Fail to pull. Assets already exists, version: {}. Expected version: {}. "
"To overwrite existing assets and update, add flag '--update' and rerun this script".format(
asset_version(), VERSION
)
)
return
else:
if asset_version() != VERSION:
logger.info("Remove existing assets, version: {}..".format(asset_version()))
shutil.rmtree(os.path.join(TARGET_DIR, "assets"))
else:
logger.warning(
"Fail to pull. Assets is already up-to-date, version: {}. MetaDrive version: {}".format(
asset_version(), VERSION
)
)
return

zip_path = os.path.join(TARGET_DIR, 'assets.zip')

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

# Extract the zip file to the desired location
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(TARGET_DIR)

# Remove the downloaded zip file (optional)
os.remove(zip_path)
logger.info("Successfully download assets, version: {}. MetaDrive version: {}".format(asset_version(), VERSION))


if __name__ == '__main__':
pull_asset()
22 changes: 11 additions & 11 deletions metadrive/render_pipeline/rpcore/native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@

# Store a global flag, indicating whether the C++ modules were loaded or the python
# implemetation of them
NATIVE_CXX_LOADED = False

# Read the configuration from the flag-file
current_path = dirname(realpath(__file__))
cxx_flag_path = join(current_path, "use_cxx.flag")
if not isfile(cxx_flag_path):
RPObject.global_error("CORE", "Could not find cxx flag, please run the setup.py!")
sys.exit(1)
else:
with open(join(current_path, "use_cxx.flag"), "r") as handle:
NATIVE_CXX_LOADED = handle.read().strip() == "1"
NATIVE_CXX_LOADED = True

# Read the configuration from the flag-file, LQY: Bypass this check process.
# current_path = dirname(realpath(__file__))
# cxx_flag_path = join(current_path, "use_cxx.flag")
# if not isfile(cxx_flag_path):
# RPObject.global_error("CORE", "Could not find cxx flag, please run the setup.py!")
# sys.exit(1)
# else:
# with open(join(current_path, "use_cxx.flag"), "r") as handle:
# NATIVE_CXX_LOADED = handle.read().strip() == "1"

# The native module should only be imported once, and that by the internal pipeline code
assert __package__ == "metadrive.render_pipeline.rpcore.native", "You have included the pipeline in the wrong way!"
Expand Down
12 changes: 11 additions & 1 deletion metadrive/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
VERSION = "0.3.0.1"
import os

VERSION = "0.4.0.2"


def asset_version():
asset_path = os.path.join(os.path.dirname(__file__), "assets")
asset_version = os.path.join(asset_path, "version.txt")
with open(asset_version, "r") as file:
lines = file.readlines()
return lines[0]

0 comments on commit ec35a0c

Please sign in to comment.