Skip to content

Commit

Permalink
Merge pull request #35 from yhs0602/feat/mmap
Browse files Browse the repository at this point in the history
Feat/mmap
  • Loading branch information
yhs0602 authored Feb 4, 2025
2 parents b3f2231 + 4858004 commit 583851e
Show file tree
Hide file tree
Showing 64 changed files with 4,554 additions and 1,307 deletions.
6 changes: 5 additions & 1 deletion .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ venv/*
.pytest_cache/*
.vscode/*
build/*
./build/*
craftground.egg-info/*
docs/*
figures/*
paper/*
poster/*
pybind11/*
src/craftground.egg-info/*
src/proto/*
src/proto/*
build/_deps/*
./build/_deps/*
src/craftground/MinecraftEnv/_deps/*
8 changes: 4 additions & 4 deletions .clangd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
If:
PathMatch: /src/cpp/.*
PathMatch: src/cpp/.*

CompileFlags:
CompilationDatabase: /build
CompilationDatabase: build

---

If:
PathMatch: /src/MinecraftEnv/src/main/cpp/.*
PathMatch: src/craftground/MinecraftEnv/src/main/cpp/.*

CompileFlags:
CompilationDatabase: /src/MinecraftEnv/build
CompilationDatabase: src/craftground/MinecraftEnv
9 changes: 9 additions & 0 deletions .github/workflows/cmake-build-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ jobs:
run: |
nvcc -V
- name: Set up cache for CMake FetchContent
uses: actions/cache@v3
with:
path: |
build/_deps
key: ${{ runner.os }}-fetchcontent-${{ hashFiles('CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-
- name: Configure CMake for python part
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/cmake-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches: [ "main" ]

jobs:
build:
cmake-build:
runs-on: ${{ matrix.os }}

strategy:
Expand Down Expand Up @@ -66,7 +66,6 @@ jobs:
sudo mv libtorch $LIBTORCH
- name: Install python < 3.13 if macos # https://groups.google.com/g/vim_dev/c/1I20UCzmtF4
if: matrix.os == 'macos-latest'
uses: actions/setup-python@v5
with:
python-version: '3.12'
Expand All @@ -78,6 +77,15 @@ jobs:
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Set up cache for CMake FetchContent
uses: actions/cache@v3
with:
path: |
build/_deps
key: ${{ runner.os }}-fetchcontent-${{ hashFiles('CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-
- name: Configure CMake for python part
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Expand All @@ -89,6 +97,11 @@ jobs:
-S ${{ github.workspace }}
-DBUILD_TESTS=ON # Enable testing
# - name: Install Windows Universal CRT
# run: |
# curl -LO https://download.visualstudio.microsoft.com/download/pr/b6b7b0c1-4475-4a21-9c59-63722e3fdf18/7e2b0a8fc72e4f0ba9ea8c7ed1b7c13d/windows10.0-kb3118401-x64.msu
# start /wait wusa.exe windows10.0-kb3118401-x64.msu /quiet /norestart

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
branches: [ "main" ]

jobs:
build:
gradle_build:
runs-on: ${{ matrix.os }}
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
Expand Down Expand Up @@ -94,6 +94,15 @@ jobs:
uses: gradle/actions/setup-gradle@v4
# with:
# gradle-version: "8.8" # Quotes required to prevent YAML converting to number

- name: Set up cache for CMake FetchContent
uses: actions/cache@v3
with:
path: |
src/craftground/MinecraftEnv/_deps
key: ${{ runner.os }}-fetchcontent-${{ hashFiles('src/craftground/MinecraftEnv/src/main/cpp/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-
- name: Build with Gradle Wrapper
run: ./gradlew build
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/publish-package-cuda-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ jobs:

- uses: astral-sh/setup-uv@v4

- name: Set up cache for CMake FetchContent python cache
uses: actions/cache@v3
with:
path: |
build/_deps
key: ${{ runner.os }}-fetchcontent-python-${{ hashFiles('CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-python-
- name: Set up cache for CMake FetchContent gradle cache
uses: actions/cache@v3
with:
path: |
src/craftground/MinecraftEnv/_deps
key: ${{ runner.os }}-fetchcontent-gradle-${{ hashFiles('src/craftground/MinecraftEnv/src/main/cpp/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-gradle-
- name: Build wheels
uses: pypa/[email protected]
env:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/publish-package-cuda-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true

- name: Set up cache for CMake FetchContent python cache
uses: actions/cache@v3
with:
path: |
build/_deps
key: ${{ runner.os }}-fetchcontent-python-${{ hashFiles('CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-python-
- name: Set up cache for CMake FetchContent gradle cache
uses: actions/cache@v3
with:
path: |
src/craftground/MinecraftEnv/_deps
key: ${{ runner.os }}-fetchcontent-gradle-${{ hashFiles('src/craftground/MinecraftEnv/src/main/cpp/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-gradle-
- name: Set up JDK 21
uses: actions/setup-java@v4
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/publish-package-nocuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Set up cache for CMake FetchContent python cache
uses: actions/cache@v3
with:
path: |
build/_deps
key: ${{ runner.os }}-fetchcontent-python-${{ hashFiles('CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-python-
- name: Set up cache for CMake FetchContent gradle cache
uses: actions/cache@v3
with:
path: |
src/craftground/MinecraftEnv/_deps
key: ${{ runner.os }}-fetchcontent-gradle-${{ hashFiles('src/craftground/MinecraftEnv/src/main/cpp/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-gradle-
- name: Build wheels
uses: pypa/[email protected]
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,29 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest flake8-pyproject coverage
python -m pip install .[test]
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Set up cache for CMake FetchContent python cache
uses: actions/cache@v3
with:
path: |
build/_deps
key: ${{ runner.os }}-fetchcontent-python-${{ hashFiles('CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-fetchcontent-python-
- name: Test with pytest
run: |
coverage run --source=src/craftground -m pytest tests/python/unit/
# build cpp extension first
mkdir build && cd build && cmake .. && cmake --build . && cd ..
PYTHONPATH=./build:src/craftground coverage run --source=src/craftground -m pytest tests/python/unit/
- name: coverage
run: |
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"C_Cpp.default.compileCommands": "${workspaceFolder}/src/MinecraftEnv/compile_commands.json",
"clangd.arguments": [
"--background-index",
"--compile-commands-dir=${workspaceFolder}/src/MinecraftEnv/"
],
"java.compile.nullAnalysis.mode": "automatic",
}
39 changes: 34 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.15...3.29)
cmake_minimum_required(VERSION 3.28)
project(craftground LANGUAGES CXX)
include(GNUInstallDirs)
include(FetchContent)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -67,7 +68,7 @@ else()
endif()

# Collect source files for the module
set(CRAFTGROUND_PY_SOURCES src/cpp/ipc.cpp)
set(CRAFTGROUND_PY_SOURCES src/cpp/ipc.cpp src/cpp/ipc_noboost.cpp src/cpp/print_hex.cpp)

if(APPLE)
# Add Apple-specific source files
Expand All @@ -86,9 +87,27 @@ elseif(CUDAToolkit_FOUND)
set(CRAFTGROUND_PY_COMPILE_OPTIONS -DHAS_CUDA)
endif()

# Find Boost
message(STATUS "Installing Boost")
set(BOOST_INCLUDE_LIBRARIES interprocess thread system)
set(BOOST_ENABLE_CMAKE ON)

set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
Boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_TAG boost-1.87.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
)
# FetchContent_MakeAvailable(Boost)

# message(STATUS "Boost is now available")
# Add the module
pybind11_add_module(craftground_native ${CRAFTGROUND_PY_SOURCES})

# target_link_libraries(craftground_native PRIVATE Boost::system Boost::thread Boost::interprocess)
# target_include_directories(craftground_native PRIVATE ${Boost_INCLUDE_DIRS})
if(APPLE)
if(Torch_FOUND)
target_include_directories(craftground_native PRIVATE "${TORCH_INCLUDE_DIRS}")
Expand All @@ -114,6 +133,10 @@ elseif(CUDAToolkit_FOUND)
target_link_libraries(craftground_native PRIVATE CUDA::cudart CUDA::cudart_static)
endif()
endif()
if(WIN32)
add_definitions(-D_WIN32)
target_link_libraries(craftground_native PRIVATE kernel32.lib user32.lib Synchronization.lib)
endif()


target_include_directories(craftground_native PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp)
Expand Down Expand Up @@ -155,16 +178,22 @@ if(BUILD_TESTS)
target_include_directories(craftground PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
if(WIN32)
target_link_libraries(
craftground_native PRIVATE
craftground PRIVATE
${CUDAToolkit_LIBRARY_DIR}/cudart.lib
# ${CUDAToolkit_LIBRARY_DIR}/cudart_static.lib
${CUDAToolkit_LIBRARY_DIR}/cuda.lib
)
else()
# On Linux, use the CUDA targets provided by CMake
target_link_libraries(craftground_native PRIVATE CUDA::cudart CUDA::cudart_static)
target_link_libraries(craftground PRIVATE CUDA::cudart CUDA::cudart_static)
endif()
endif()
# target_link_libraries(craftground PRIVATE Boost::system Boost::thread Boost::interprocess)
# target_include_directories(craftground PRIVATE ${Boost_INCLUDE_DIRS})
if(WIN32)
add_definitions(-D_WIN32)
target_link_libraries(craftground PRIVATE kernel32.lib user32.lib Synchronization.lib)
endif()
target_link_options(craftground PRIVATE "-Wl,--whole-archive" "-Wl,--no-whole-archive")
target_include_directories(craftground PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp)

Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
```bash
conda create -n my_experiment_env python=3.11
conda activate my_experiment_env
conda install conda-forge::openjdk=21 cmake
sudo apt install libglew-dev
conda install conda-forge::openjdk=21 conda-forge::cmake conda-forge::glew-dev conda-forge::libpng conda-forge::libzlib conda-forge::libopengl conda-forge::libflite
pip install craftground
```

Expand All @@ -56,7 +55,27 @@ pip3 install cmake # You need latest cmake, not the one provided by apt-get
pip3 install craftground
```

### Setup Headless Environment
### Windows Setup
#### Resolve Windows Path Length Limitation
Note: you may need to enable long file path due to windows limitation. You can enable it by editing registry as mentioned [here](https://docs.python.org/3/using/windows.html#removing-the-max-path-limitation)

> In the latest versions of Windows, this limitation can be expanded to approximately 32,000 characters. Your administrator will need to activate the “Enable Win32 long paths” group policy, or set LongPathsEnabled to 1 in the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
The following command does the same as the above instruction:
```cmd
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f
```

#### Resolve Conda Installation Issues
Using conda is recommended for Windows users. You can install conda from [here](https://docs.anaconda.com/miniconda/). Make sure to execute
```powershell
powershell -ExecutionPolicy Bypass
conda init powershell
```
if you are using PowerShell, in the anaconda powershell prompt.


### Setup Headless Environment (Linux)
Refer to [Headless Environment Setup](docs/headless.md) for setting up a headless environment.

### Install development version
Expand All @@ -66,7 +85,6 @@ pip install git+https://github.com/yhs0602/CraftGround.git@dev

## Run your first experiment
### Example repositories
- Check [the demo repository](https://github.com/yhs0602/CraftGround-Baselines3) for detailed examples.
- Check [the example repository](https://github.com/yhs0602/minecraft-simulator-benchmark) for benchmarking experiments.

### Example code
Expand Down
6 changes: 6 additions & 0 deletions dev_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
format_code() {
# Get a list of tracked files matching the desired extensions
git ls-files -- '*.h' '*.cpp' '*.mm' | xargs clang-format -i
git ls-files -- '*.java' -z | xargs -0 -P 4 google-java-format -i
ktlint '!**/com/kyhsgeekcode/minecraftenv/proto/**' --format
}
2 changes: 1 addition & 1 deletion docs/action_space.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The action space is a list of integers, and each indices represent the following

- `0`: 0: no-op, 1: Move forward, 2: Move backward
- `1`: 0: no-op, 1: Strafe right, 2: Strafe left
- `2`: 0: no-op, 1: Jump
- `2`: 0: no-op, 1: Jump, 2: Sneak, 3: Sprint
- `3`: Camera delta pitch (0: -180, 24:180)
- `4`: Camera delta yaw (-180: 180)
- `5`: 0: no-op, 1: Use 2: Drop 3: Attack 4: Craft 5: Equip 6: Place 7: Destroy
Expand Down
Loading

0 comments on commit 583851e

Please sign in to comment.