nocturne_lab
is a maintained fork of Nocturne; a 2D, partially observed, driving simulator built in C++. Currently, nocturne_lab
is used internally at the Emerge lab. You can get started with the intro examples 🏎️💨 here.
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()
Algorithm | Reference | Code | Compatible with | Test report |
---|---|---|---|---|
PPO single-agent control | Schulman et al., 2017 | ppo_with_sb3.ipynb | SB3 | ✅ Link |
PPO multi-agent control | Schulman et al., 2017 | 05_ppo_with_sb3_ma_control.py | SB3 | ✅ Link |
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