nocturne_lab
is a maintained fork of Nocturne; a 2D, partially observed, driving simulator built in C++. You can get started with the intro examples 🏎️💨 here.
🚨 Update: We released a fast, GPU-accelerated version of Nocturne that runs at 1 Million FPS: GPUDrive
Project page and 📝
wandb
report with videos and full training logs
You can download a part of the dataset (~2000 scenes) here. Once downloaded, add the data to the ./data
folder and make sure the data_path
in env_config
is set correctly.
Algorithm | Reference | Implementation | How to run |
---|---|---|---|
MAPPO | (Vinitsky et al., 2021) | ma_ppo.py | python experiments/hr_rl/run_hr_ppo_cli.py --reg-weight 0.0 |
Human-Regularized (MA) PPO | (Cornelisse et al., 2024) | reg_ppo.py | python experiments/hr_rl/run_hr_ppo_cli.py --reg-weight 0.06 |
We release the best PPO-trained models with human regularization in models_trained/hr_rl
. Additionally, we release the human reference policies, which can be found at models_trained/il
. For the results presented in the paper, we used the IL policy trained on AVs (human_policy_D651_S500_02_18_20_05_AV_ONLY.pt
).
After installing nocturne_lab
, here is how you can run your own Human-Regularized PPO in 3 steps:
- Step 1: Make sure you installed the dataset and set the
data_path
inconfigs/env_config.yaml
to your folder. - Step 2: You have access to our trained imitation learning policy in models_trained/il. Make sure that the
human_policy_path
in theconfigs/exp_config.yaml
file is set to the IL policy you want to use. - Step 3: That's it! Now run:
python experiments/hr_rl/run_hr_ppo_cli.py --reg-weight <your-regularization-weight>
where setting reg-weight 0.0
will just run standard MAPPO. We used a regularization weight between 0.02 - 0.08 for the paper.
For transparency and reproducibility, we provide a detailed report with a PPO and HR-PPO run on 15 scenarios.
from nocturne.envs.base_env import BaseEnv
# Initialize an environment
env = BaseEnv(config=env_config)
# Reset
obs_dict = env.reset()
# Get info
agent_ids = [agent_id for agent_id in obs_dict.keys()]
dead_agent_ids = []
for step in range(1000):
# Sample actions
action_dict = {
agent_id: env.action_space.sample()
for agent_id in agent_ids
if agent_id not in dead_agent_ids
}
# Step in env
obs_dict, rew_dict, done_dict, info_dict = env.step(action_dict)
# Update dead agents
for agent_id, is_done in done_dict.items():
if is_done and agent_id not in dead_agent_ids:
dead_agent_ids.append(agent_id)
# Reset if all agents are done
if done_dict["__all__"]:
obs_dict = env.reset()
dead_agent_ids = []
# Close environment
env.close()
The instructions for installing Nocturne locally are provided below. To use the package on a HPC (e.g. HPC Greene), follow the instructions in ./hpc/hpc_setup.md.
- Python (>=3.10)
Below different options for setting up a virtual environment are described. Either option works although pyenv
is recommended.
Note: The virtual environment needs to be activated each time before you start working.
Create a virtual environment by running:
pyenv virtualenv 3.10.12 nocturne_lab
The virtual environment should be activated every time you start a new shell session before running subsequent commands:
pyenv shell nocturne_lab
Fortunately, pyenv
provides a way to assign a virtual environment to a directory. To set it for this project, run:
pyenv local nocturne_lab
Create a conda environment by running:
conda env create -f ./environment.yml
This creates a conda environment using Python 3.10 called nocturne_lab
.
To activate the virtual environment, run:
conda activate nocturne_lab
Create a virtual environment by running:
python -m venv .venv
The virtual environment should be activated every time you start a new shell session before running the subsequent command:
source .venv/bin/activate
poetry
is used to manage the project and its dependencies. Start by installing poetry
in your virtual environment:
pip install poetry
Before installing the package, you first need to synchronise and update the git submodules by running:
# Synchronise and update git submodules
git submodule sync
git submodule update --init --recursive
Now install the package by running:
poetry install
Note: If it fails to build
nocturne
, try runningpoetry build
to get a more descriptive error message. One reason it fails may be because you don't have SFML installed, which can be done by runningbrew install sfml
on mac orsudo apt-get install libsfml-dev
on Linux.
Under the hood the
nocturne
package uses thenocturne_cpp
Python package that wraps the Nocturne C++ code base and provides bindings for Python to interact with the C++ code usingpybind11
.
KeyringLocked Failed to unlock the collection!
. Solution: first runexport PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
in your terminal, then rerunpoetry install
stackOverflow with more info
To configure the development setup, run:
# Install poetry dev dependencies
poetry install --only=dev
# Install pre-commit (for flake8, isort, black, etc.)
pre-commit install
# Optional: Install poetry docs dependencies
poetry install --only=docs