Skip to content

Commit 3457621

Browse files
author
Lui
committed
Merge branch 'main' into notebooks
merge main
2 parents 3359bc4 + d87ed6c commit 3457621

14 files changed

+541
-76
lines changed

.devcontainer/Dockerfile

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
FROM nvidia/cuda:12.6.3-devel-ubuntu22.04
2+
3+
# Prevent interactive prompts during package installation
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Install system dependencies
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
python3.11 \
9+
python3-pip \
10+
python3.11-venv \
11+
build-essential \
12+
git \
13+
curl \
14+
ssh \
15+
mesa-utils \
16+
&& rm -rf /var/lib/apt/lists/* && apt-get clean
17+
18+
# Create symbolic links for python
19+
RUN ln -sf /usr/bin/python3.11 /usr/bin/python \
20+
&& ln -sf /usr/bin/python3.11 /usr/bin/python3
21+
22+
# Create non-root user
23+
ARG USERNAME=vscode
24+
ARG USER_UID=1000
25+
ARG USER_GID=$USER_UID
26+
27+
RUN groupadd --gid $USER_GID $USERNAME \
28+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
29+
&& apt-get update \
30+
&& apt-get install -y sudo \
31+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
32+
&& chmod 0440 /etc/sudoers.d/$USERNAME
33+
34+
# Set environment variables for CUDA
35+
ENV PATH="/usr/local/cuda-12.0/bin:${PATH}"
36+
ENV LD_LIBRARY_PATH="/usr/local/cuda-12.0/lib64:${LD_LIBRARY_PATH}"
37+
38+
ENV NVIDIA_VISIBLE_DEVICES ${NVIDIA_VISIBLE_DEVICES:-all}
39+
ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics
40+
41+
# Create and set proper permissions for workspace directory
42+
RUN mkdir -p /workspace && chown -R $USERNAME:$USERNAME /workspace && sudo chmod -R 777 /workspace
43+
44+
# Create virtual environment with proper permissions
45+
ENV VIRTUAL_ENV=/home/vscode/venv
46+
RUN python -m venv $VIRTUAL_ENV && \
47+
chown -R $USERNAME:$USERNAME $VIRTUAL_ENV
48+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
49+
50+
# Switch to non-root user
51+
USER $USERNAME
52+
53+
# Install development tools
54+
RUN pip install --no-cache-dir ruff
55+
56+
# Create a temporary directory for installation with proper permissions
57+
WORKDIR /tmp/install
58+
59+
# Copy pyproject.toml with correct ownership
60+
COPY --chown=$USERNAME:$USERNAME pyproject.toml .
61+
62+
# Install dependencies as non-root user
63+
RUN pip install --no-cache-dir -e ".[test,gpu]"
64+
65+
# Set final working directory and ensure proper permissions
66+
WORKDIR /workspace

.devcontainer/devcontainer.linux.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "Crazyflow Development",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"context": ".."
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"ms-python.python",
11+
"ms-python.pylance",
12+
"charliermarsh.ruff",
13+
"ms-vscode.test-adapter-converter",
14+
"ms-python.pytest-adapter",
15+
"nvidia.nsight-vscode-edition",
16+
"ms-azuretools.vscode-docker",
17+
"ms-toolsai.jupyter-renderers",
18+
"ms-toolsai.jupyter",
19+
"ms-toolsai.jupyter-keymap"
20+
],
21+
"settings": {
22+
"python.defaultInterpreterPath": "/home/vscode/venv/bin/python",
23+
"python.testing.pytestEnabled": true, // test framework
24+
"python.testing.pytestArgs": [
25+
"-m",
26+
"not render"
27+
],
28+
"python.testing.unittestEnabled": false, // test framework
29+
"python.testing.nosetestsEnabled": false, // test framework
30+
"editor.formatOnSave": true,
31+
"editor.codeActionsOnSave": {
32+
"source.fixAll.ruff": true,
33+
"source.organizeImports.ruff": true
34+
},
35+
"[python]": {
36+
"editor.defaultFormatter": "charliermarsh.ruff",
37+
"editor.formatOnSave": true,
38+
"editor.rulers": [
39+
100
40+
]
41+
}
42+
}
43+
}
44+
},
45+
"containerEnv": {
46+
"DISPLAY": "${localEnv:DISPLAY}",
47+
"XAUTHORITY": "${localEnv:XAUTHORITY}"
48+
},
49+
"runArgs": [
50+
"--interactive",
51+
"--net=host",
52+
"--ipc=host",
53+
// "--gpus=all", //use only with GPU
54+
// "--runtime=nvidia" //use only with GPU
55+
],
56+
"postCreateCommand": "python -m pip install -e '.[test,gpu]'",
57+
"remoteUser": "vscode"
58+
}

.devcontainer/devcontainer.wsl2.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "Crazyflow Development",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"context": ".."
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"ms-python.python",
11+
"ms-python.pylance",
12+
"charliermarsh.ruff",
13+
"ms-vscode.test-adapter-converter",
14+
"ms-python.pytest-adapter",
15+
"nvidia.nsight-vscode-edition",
16+
"ms-azuretools.vscode-docker",
17+
"ms-toolsai.jupyter-renderers",
18+
"ms-toolsai.jupyter",
19+
"ms-toolsai.jupyter-keymap"
20+
],
21+
"settings": {
22+
"python.defaultInterpreterPath": "/home/vscode/venv/bin/python",
23+
"python.testing.pytestEnabled": true, // test framework
24+
"python.testing.pytestArgs": [
25+
"-m",
26+
"not render"
27+
],
28+
"python.testing.unittestEnabled": false, // test framework
29+
"python.testing.nosetestsEnabled": false, // test framework
30+
"editor.formatOnSave": true,
31+
"editor.codeActionsOnSave": {
32+
"source.fixAll.ruff": true,
33+
"source.organizeImports.ruff": true
34+
},
35+
"[python]": {
36+
"editor.defaultFormatter": "charliermarsh.ruff",
37+
"editor.formatOnSave": true,
38+
"editor.rulers": [
39+
100
40+
]
41+
}
42+
}
43+
}
44+
},
45+
// mounts required for WSL2 X11
46+
"mounts": [
47+
"source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind",
48+
"source=/mnt/wslg,target=/mnt/wslg,type=bind",
49+
"source=/usr/lib/wsl,target=/usr/lib/wsl,type=bind"
50+
],"containerEnv": {
51+
"DISPLAY": "${localEnv:DISPLAY}",
52+
"XAUTHORITY": "${localEnv:XAUTHORITY}",
53+
"WAYLAND_DISPLAY": "${localEnv:WAYLAND_DISPLAY}", // WSL2
54+
"XDG_RUNTIME_DIR": "${localEnv:XDG_RUNTIME_DIR}", // WSL2
55+
"PULSE_SERVER": "${localEnv:PULSE_SERVER}" // WSL2
56+
},
57+
"runArgs": [
58+
"--interactive",
59+
"--net=host",
60+
"--ipc=host"
61+
// "--gpus=all", //use only with GPU
62+
// "--runtime=nvidia" //use only with GPU
63+
],
64+
"postCreateCommand": "python -m pip install -e '.[test,gpu]'",
65+
"remoteUser": "vscode"
66+
}

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
.vscode/
21
**.egg-info/
32
**/__pycache__/
43
logs
54
secrets
65
**/*.secret
76
saves
87
.pytest_cache
9-
**/*.json
8+
*.json
109
**/*.csv
1110
build
12-
.venv
11+
.venv
12+
!/.devcontainer/devcontainer.json
13+
!/.devcontainer/devcontainer.linux.json
14+
!/.devcontainer/devcontainer.wsl2.json
15+
!/.vscode/launch.json

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python Debugger: Current File",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal",
13+
"justMyCode": false
14+
}
15+
]
16+
}

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
### Using the project with VSCode devcontainers
2+
3+
**Running on CPU**: by default the containers run on CPU. You don't need to take any action.
4+
5+
**Running on GPU**: The devcontsainers can easily run using your computer's NVIDIA GPU on Linux and Windows. This makes sense if you want to accelerate simulation by running thousands of simulation in parallel. In order to work you need to install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0&target_type=deb_local), [NVIDIA Container runtime](https://developer.nvidia.com/container-runtime) for your computer. Finally, enable GPU access to the devcontainers by setting the commented out `"--gpus=all"` and `"--runtime=nvidia"` flags in `devcontainer.json`.
6+
7+
8+
**Linux**
9+
10+
1. Install [Docker](https://docs.docker.com/engine/install/) (, and make sure Docker Daemon is running)
11+
2. Install [VSCode](https://code.visualstudio.com/), with [devcontainer extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), and [remote dev pack](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker).
12+
3. Clone this project's code. Rename `/.devcontainer/devcontainer.linux.json` to `/.devcontainer/devcontainer.json`.
13+
4. Open this project in VSCode. VSCode should automatically detect the devcontainer and prompt you to `Reopen in container`. If not, see [here](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-an-existing-folder-in-a-container) to open manually. Note: Opening the container for the first time might take a while (up to 15 min), as the container is pulled from the web and build.
14+
15+
**Windows** (requires Windows 10 or later)
16+
17+
For windows, we require WSL2 to run the devcontainer. (So its actually Linux with extra steps.) Full instructions can be found [in the official docs](https://code.visualstudio.com/blogs/2020/07/01/containers-wsl#_getting-started). Here are the important steps:
18+
1. Install [Docker](https://docs.docker.com/desktop/setup/install/windows-install/), and WSL2, and Ubuntu 22.04 LTS (, and make sure Docker Daemon is running)
19+
2. Docker will recognize that you have WSL installed and prompt you via Windows Notifications to enable WSL integration -> confirm this with `Enable WSL integration`. If not, open `Docker Desktop`, navigate to the settings, and manually enable WSL integration. (There are TWO setting options for this. Make sure to enable BOTH!)
20+
3. Install [VSCode](https://code.visualstudio.com/), with the [WSL extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl), [devcontainer extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), and [remote dev pack](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker).
21+
4. Clone the source code for the exercises in the WSL2 file system to `/home` (`~`), or wherever you like. (Performance when working on the WSL file system is much better compared to Windows file system). You can access the WSL filesystem either by starting a WSL/Ubuntu console, or via the Windows File Explorer at `\\wsl.localhost\Ubuntu\home` (replace `Ubuntu` with your distro, if necessary).
22+
7. Rename `/.devcontainer/devcontainer.windows.json` to `/.devcontainer/devcontainer.json`.
23+
8. Open this project in VSCode. The easiest way to do so is by starting a WSL/Ubuntu shell, navigating via `cd` to the source code, then type `code .` to open VSCode. VSCode should automatically detect the devcontainer and prompt you to `Reopen in container`. If not, see [here](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-an-existing-folder-in-a-container) to open manually. Note: Opening the container for the first time might take a while (up to 15 min), as the container is pulled from the web and build.
24+
25+
26+
**MacOS**
27+
28+
Should work like Linux. Untested.
29+
30+
____________
31+
32+
Known Issues:
33+
- if building docker container fails at `RUN apt-get update`, make sure your host systems time is set correct: https://askubuntu.com/questions/1511514/docker-build-fails-at-run-apt-update-error-failed-to-solve-process-bin-sh
34+
135
# crazyflow
236
Fast, parallelizable simulations of Crazyflies with JAX and MuJoCo.
337

crazyflow/sim/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from crazyflow.sim.physics import Physics
22
from crazyflow.sim.sim import Sim
3-
from crazyflow.sim.symbolic import symbolic
3+
from crazyflow.sim.symbolic import symbolic_attitude, symbolic_from_sim, symbolic_thrust
44

5-
__all__ = ["Sim", "Physics", "symbolic"]
5+
__all__ = ["Sim", "Physics", "symbolic_attitude", "symbolic_from_sim", "symbolic_thrust"]

crazyflow/sim/physics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from crazyflow.control.control import KF, KM
1111

1212
SYS_ID_PARAMS = {
13-
"acc": jnp.array([20.91, 3.65]),
13+
"acc": jnp.array([20.907574256269616, 3.653687545690674]),
1414
"roll_acc": jnp.array([-130.3, -16.33, 119.3]),
1515
"pitch_acc": jnp.array([-99.94, -13.3, 84.73]),
1616
"yaw_acc": jnp.array([0.0, 0.0, 0.0]),

0 commit comments

Comments
 (0)