Skip to content

Commit

Permalink
Merge pull request #19 from opendilab/gl-dev
Browse files Browse the repository at this point in the history
update v0.3.4
  • Loading branch information
RobinC94 authored Jul 28, 2022
2 parents 4b7816b + d89e8d5 commit 660343c
Show file tree
Hide file tree
Showing 32 changed files with 2,622 additions and 51 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main, 'doc/*']
pull_request:
branches: [main, 'doc/*']
branches: [main]

jobs:
doc:
Expand All @@ -22,8 +22,7 @@ jobs:
- name: Generate
run: |
python -m pip install .[doc]
wget http://opendilab.org/download/DI-drive/carla-0.9.9-py3.7-linux-x86_64.egg
easy_install carla-0.9.9-py3.7-linux-x86_64.egg
python -m pip install carla
make -C ./docs html
mv docs/build/html public
rm -rf docs/build
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7]
python-version: [3.7]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: code style
- name: Install
run: |
python -m pip install .
python -c 'import core'
- name: Code style
run: |
python -m pip install .[style]
bash format.sh ./core --test
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v0.3.4 (2022.7.25)
- Add Traj SAC and PPO policy
- Add MetaDrive evaluator
- Add MetaDrive TREX demo and doc
- Update Carla support to 0.9.10
- Fix bug of MetaDrive reset conflice with EnvManager
- Fix bug in DingEnvManager

## v0.3.3 (2022.6.5)
- Update readme, reorganize info
- Add MetaDriveTrajEnv and doc
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pip install -e .

DI-engine and Pytorch will be installed automatically.

In addition, at least one simulator in Carla and MetaDrive need to be able to run in DI-drive. [MetaDrive](https://decisionforce.github.io/metadrive/) can be easily installed via `pip`.
In addition, at least one simulator in **Carla** and **MetaDrive** need to be installed to run in DI-drive. [MetaDrive](https://decisionforce.github.io/metadrive/) can be easily installed via `pip`.
If [Carla](http://carla.org) server is used for simulation, users need to install 'Carla Python API' in addition. You can use either one of them or both. Make sure to modify the activated simulators in `core.__init__.py` to avoid import error.

Please refer to the [installation guide](https://opendilab.github.io/DI-drive/installation/index.html) for details about the installation of **DI-drive**.
Expand Down Expand Up @@ -101,6 +101,10 @@ We provide detail guidance for IL and RL experiments in all simulators and quick
- [Latent DRL](https://arxiv.org/abs/2001.08726)
- MetaDrive Macro RL

### Other Method

- [DREX](http://proceedings.mlr.press/v100/brown20a.html)

## DI-drive Casezoo

**DI-drive Casezoo** is a scenario set for training and testing the Autonomous Driving policy in simulator.
Expand Down Expand Up @@ -155,6 +159,7 @@ DI-drive
| | |-- vae_model.py
| | |-- vehicle_controller.py
| |-- policy
| | |-- traj_policy
| | |-- auto_policy.py
| | |-- base_carla_policy.py
| | |-- cilrs_policy.py
Expand Down
2 changes: 1 addition & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__TITLE__ = "DI-drive"
__VERSION__ = "0.3.3"
__VERSION__ = "0.3.4"
__DESCRIPTION__ = "Decision AI Auto-Driving Platform"
__AUTHOR__ = "OpenDILab Contributors"
__AUTHOR_EMAIL__ = "[email protected]"
Expand Down
10 changes: 6 additions & 4 deletions core/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
if 'metadrive' in SIMULATORS:
from .md_macro_env import MetaDriveMacroEnv
from .md_traj_env import MetaDriveTrajEnv
env_map.update({
"Macro-v1": 'core.envs.md_macro_env:MetaDriveMacroEnv',
"Traj-v1": 'core.envs.md_traj_env:MetaDriveTrajEnv'
})
env_map.update(
{
"Macro-v1": 'core.envs.md_macro_env:MetaDriveMacroEnv',
"Traj-v1": 'core.envs.md_traj_env:MetaDriveTrajEnv'
}
)

for k, v in env_map.items():
if k not in registry.env_specs:
Expand Down
6 changes: 6 additions & 0 deletions core/envs/drive_env_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def reset(self, *args, **kwargs) -> Any:
obs = to_ndarray(obs, dtype=np.float32)
if isinstance(obs, np.ndarray) and len(obs.shape) == 3:
obs = obs.transpose((2, 0, 1))
elif isinstance(obs, dict):
birdview = obs['birdview'].transpose((2, 0, 1))
obs = {'birdview': birdview, 'vehicle_state': obs['vehicle_state']}
self._final_eval_reward = 0.0
return obs

Expand All @@ -75,6 +78,9 @@ def step(self, action: Any = None) -> BaseEnvTimestep:
obs = to_ndarray(obs, dtype=np.float32)
if isinstance(obs, np.ndarray) and len(obs.shape) == 3:
obs = obs.transpose((2, 0, 1))
elif isinstance(obs, dict):
birdview = obs['birdview'].transpose((2, 0, 1))
obs = {'birdview': birdview, 'vehicle_state': obs['vehicle_state']}
rew = to_ndarray([rew], dtype=np.float32)
if done:
info['final_eval_reward'] = self._final_eval_reward
Expand Down
23 changes: 14 additions & 9 deletions core/envs/md_traj_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from ding.utils import ENV_REGISTRY
from core.utils.simulator_utils.md_utils.discrete_policy import DiscreteMetaAction
from core.utils.simulator_utils.md_utils.agent_manager_utils import TrajAgentManager
from core.utils.simulator_utils.md_utils.engine_utils import TrajEngine
from core.utils.simulator_utils.md_utils.engine_utils import TrajEngine, initialize_engine, close_engine, \
engine_initialized, set_global_random_seed
from core.utils.simulator_utils.md_utils.traffic_manager_utils import TrafficMode
from metadrive.constants import RENDER_MODE_NONE, DEFAULT_AGENT, REPLAY_DONE, TerminationState
from metadrive.envs.base_env import BaseEnv
Expand All @@ -23,7 +24,6 @@
from metadrive.envs.base_env import BASE_DEFAULT_CONFIG
from metadrive.obs.top_down_obs_multi_channel import TopDownMultiChannel
from metadrive.engine.base_engine import BaseEngine
from metadrive.utils.utils import auto_termination

DIDRIVE_DEFAULT_CONFIG = dict(
# ===== Generalization =====
Expand Down Expand Up @@ -77,8 +77,8 @@
# ===== Reward Scheme =====
# See: https://github.com/decisionforce/metadrive/issues/283
success_reward=10.0, # 10.0,
out_of_road_penalty=1.0, # 5.0,
crash_vehicle_penalty=1.0, # 1.0,
out_of_road_penalty=5.0, # 5.0,
crash_vehicle_penalty=5.0, # 1.0,
crash_object_penalty=5.0, # 5.0,
run_out_of_time_penalty=5.0, # 5.0,

Expand Down Expand Up @@ -668,14 +668,14 @@ def _get_step_return(self, actions, engine_info):

should_done = engine_info.get(REPLAY_DONE, False
) or (self.config["horizon"] and self.episode_steps >= self.config["horizon"])
termination_infos = self.for_each_vehicle(auto_termination, should_done)
#termination_infos = self.for_each_vehicle(self.auto_termination, should_done)

step_infos = concat_step_infos([
engine_info,
done_infos,
reward_infos,
cost_infos,
termination_infos,
#termination_infos,
])

if should_done:
Expand Down Expand Up @@ -847,10 +847,9 @@ def lazy_init(self):
:return: None
"""
# It is the true init() func to create the main vehicle and its module, to avoid incompatible with ray
if TrajEngine.singleton is not None:
if engine_initialized():
return
TrajEngine.singleton = TrajEngine(self.config)
self.engine = TrajEngine.singleton
self.engine = initialize_engine(self.config)
# engine setup
self.setup_engine()
# other optional initialization
Expand Down Expand Up @@ -883,3 +882,9 @@ def get_episode_max_step(self, distance, average_speed=6.5):
) * average_speed * self.config['physics_world_step_size']
max_step = int(distance / average_dist_per_step) + 1
return max_step

def close(self):
if self.engine is not None:
close_engine()
if self._top_down_renderer is not None:
self._top_down_renderer.close()
Loading

0 comments on commit 660343c

Please sign in to comment.