-
Notifications
You must be signed in to change notification settings - Fork 17
chore: Use devcontainers #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
74677dd
0cdff0b
71d2c27
ed62fd9
fc13bf3
be74427
204c61a
5506c6d
c328d23
29efbd1
69b15d4
45eba36
87d8352
2e811c7
0b8f18c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| FROM python:3.14-slim | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| build-essential git ca-certificates curl \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \ | ||
| && apt-get install -y nodejs \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/ | ||
|
|
||
| ENV UV_NO_SYNC=1 | ||
| ENV UV_PROJECT_ENVIRONMENT=/opt/venv | ||
| ENV CC=gcc | ||
| ENV PYTHONPATH=/workspaces/TorchJD/tests | ||
| ENV VIRTUAL_ENV=/opt/venv | ||
| ENV PATH=/opt/venv/bin:$PATH | ||
|
|
||
| WORKDIR /tmp/torchjd-install | ||
|
|
||
| COPY pyproject.toml README.md ./ | ||
| RUN mkdir -p src/torchjd && touch src/torchjd/__init__.py | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv venv /opt/venv \ | ||
| && uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot | ||
|
|
||
| COPY src/ src/ | ||
|
|
||
| WORKDIR /workspaces/TorchJD |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "name": "TorchJD", | ||
| "build": { | ||
| "dockerfile": "Dockerfile", | ||
| "context": ".." | ||
| }, | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "ms-python.python", | ||
| "astral-sh.ruff", | ||
| "astral-sh.ty" | ||
| ], | ||
| "settings": { | ||
| "python.defaultInterpreterPath": "/opt/venv/bin/python", | ||
| "python.languageServer": "None", | ||
| "[python]": { | ||
| "editor.defaultFormatter": "astral-sh.ruff" | ||
| }, | ||
| "ruff.importStrategy": "fromEnvironment", | ||
| "ty.importStrategy": "fromEnvironment" | ||
| } | ||
| } | ||
| }, | ||
| "postCreateCommand": "uv pip install -e '.[full]' --group check --group doc --group test --group plot && uv run pre-commit install" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| .git | ||
| .venv | ||
| venv | ||
| __pycache__ | ||
| *.pyc | ||
| docs/_build | ||
| .pytest_cache | ||
| .mypy_cache | ||
| .ruff_cache | ||
| build/ | ||
| dist/ | ||
| *.egg-info/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,63 +19,72 @@ with the affected code. | |
|
|
||
| ## Installation | ||
|
|
||
| To work with TorchJD, we suggest you to use [uv](https://docs.astral.sh/uv/). While this is not | ||
| mandatory, we only provide installation steps with this tool. You can install it by following their | ||
| [installation documentation](https://docs.astral.sh/uv/getting-started/installation/). We also | ||
| suggest to use VSCode with the `Python`, `ty` and `ruff` extensions (without `Pylance`). | ||
| TorchJD provides a **[devcontainer](https://containers.dev/)** configuration that gives you a | ||
| ready-to-use development environment with all dependencies pre-installed. This is the recommended way | ||
| to set up your environment. | ||
|
|
||
| 1) Pre-requisites: Use `uv` to install a Python version compatible with TorchJD and to pin it to the | ||
| `TorchJD` folder. From the root of the `TorchJD` repo, run: | ||
| ```bash | ||
| uv python install 3.14.0 | ||
| uv python pin 3.14.0 | ||
| ``` | ||
| ### Using the devcontainer | ||
|
|
||
| 2) Create a virtual environment and install the project in it. From the root of `TorchJD`, run: | ||
| 1. Install [Docker](https://docs.docker.com/get-docker/) and | ||
| [VS Code](https://code.visualstudio.com/) with the | ||
| [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). | ||
| 2. Clone the repository and open it in VS Code: | ||
| ```bash | ||
| uv venv | ||
| CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot | ||
| ``` | ||
| If you want to install PyTorch with a different CUDA version (this could be required depending on | ||
| your GPU), you'll need to specify an extra index. For instance, for CUDA 12.6, run: | ||
| ```bash | ||
| uv venv | ||
| CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot --index-strategy unsafe-best-match --extra-index-url https://download.pytorch.org/whl/cu126 | ||
| git clone https://github.com/SimplexLab/TorchJD.git | ||
| code TorchJD | ||
| ``` | ||
| 3. When prompted, click **"Reopen in Container"** (or press `Ctrl+Shift+P` and run | ||
| *"Dev Containers: Reopen in Container"*). The container will build on first launch and install all | ||
| dependencies automatically. | ||
|
|
||
| 3) Set environment variables: | ||
| Alternatively, you can use **[GitHub Codespaces](https://github.com/features/codespaces)** directly | ||
| from the repository page — no local setup required. | ||
|
|
||
| We need to use `UV_NO_SYNC=1` to prevent `uv` from syncing all the time. This is because by | ||
| default, it tries to resolve libraries compatible with the whole range of Python versions | ||
| supported by TorchJD, but in reality, we just need an installation compatible with the currently | ||
| used Python version. That's also why we specify `--python-version=3.14` when running | ||
| `uv pip install`. To follow that recommendation, add the following line to your `.bashrc`: | ||
| ```bash | ||
| export UV_NO_SYNC=1 | ||
| ``` | ||
| and start a new terminal. The alternative is to use the `--no-sync` flag whenever you run a pip | ||
| command that would normally sync (like `uv run`). | ||
| The devcontainer includes: | ||
| - Python 3.14 with all TorchJD dependencies (including optional ones) | ||
| - All development tools: `uv`, `ruff`, `ty`, `pre-commit`, `pytest` | ||
| - Pre-configured VS Code extensions and settings | ||
| - `PYTHONPATH` set up for the `tests/` folder | ||
|
|
||
| Lastly, to run some scripts from the `tests` folder, you'll have to add the `TorchJD/tests` | ||
| folder to your `PYTHONPATH`. For that, you should add the following line to your `.bashrc`: | ||
| ```bash | ||
| export PYTHONPATH="$PYTHONPATH:<path_to_TorchJD>/tests" | ||
| ``` | ||
| where `<path_to_TorchJD>` is the absolute path to your `TorchJD` repo. | ||
| ### GPU support | ||
|
|
||
| 4) Install pre-commit: | ||
| ```bash | ||
| uv run pre-commit install | ||
| ``` | ||
| If you have an NVIDIA GPU and want to run tests on CUDA, add the following to | ||
| `.devcontainer/devcontainer.json` inside the top-level object: | ||
| ```json | ||
| "runArgs": ["--gpus", "all"] | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > If you're running into issues when `uv` tries to compile `ecos`, make sure that `gcc` is | ||
| > installed. Alternatively, you can try to install `clang` or try to use some older Python version | ||
| > (3.12) for which `ecos` has provided compiled packages (the list is accessible | ||
| > [here](https://pypi.org/project/ecos/#files)). | ||
| ### CUDA-specific PyTorch installation | ||
|
|
||
| > [!TIP] | ||
| > The Python version that you should specify in your IDE is `<path-to-TorchJD>/.venv/bin/python`. | ||
| By default, the devcontainer installs the CPU-only version of PyTorch. If you need a CUDA version, | ||
| run the following inside the container: | ||
| ```bash | ||
| uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot --index-strategy unsafe-best-match --extra-index-url https://download.pytorch.org/whl/cu126 | ||
| ``` | ||
| (replace `cu126` with your CUDA version). | ||
|
|
||
| ### Adding LaTeX (for trajectory plotting) | ||
|
|
||
| The trajectory plotting scripts require LaTeX. Install it inside the container with: | ||
| ```bash | ||
| sudo apt-get update && sudo apt-get install -y texlive-latex-extra texlive-fonts-recommended dvipng cm-super | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could these come with the container?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the downside is that the container will weight 2-4GB more and this becomes "mandatory" for all contributors. Concerning caching dockers with Github, no problems. |
||
| ``` | ||
|
|
||
| ### Manual setup (without devcontainer) | ||
|
|
||
| If you prefer a local setup, you'll need: | ||
| - [uv](https://docs.astral.sh/uv/getting-started/installation/) | ||
| - Python 3.14 (install via `uv python install 3.14.0`) | ||
| - `gcc` (for compiling `ecos`) | ||
|
|
||
| Then, from the repo root: | ||
| ```bash | ||
| uv venv | ||
| CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot | ||
| export UV_NO_SYNC=1 | ||
| export PYTHONPATH="$PYTHONPATH:$PWD/tests" | ||
| uv run pre-commit install | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > In the following commands, you can get rid of the `uv run` prefix if you activate the `venv` | ||
|
|
@@ -85,13 +94,12 @@ suggest to use VSCode with the `Python`, `ty` and `ruff` extensions (without `Py | |
|
|
||
| ### Clean reinstallation | ||
|
|
||
| If you want to update all dependencies or just reinstall from scratch, run the following command | ||
| from the root of `TorchJD`: | ||
| If you want to update all dependencies or just reinstall from scratch, run the following inside the | ||
| container: | ||
| ```bash | ||
| rm -rf .venv | ||
| rm -f uv.lock | ||
| uv venv | ||
| CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot | ||
| rm -rf /opt/venv | ||
| uv venv /opt/venv | ||
| uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot | ||
| uv run pre-commit install | ||
| ``` | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not really how it works. Cuda comes with torch so you don't necessarily even have a cuda version. The correct wording would be: with the latest cuda version you GPU is compatible with.