Skip to content

Commit d89ecfb

Browse files
authored
Support Python 3.13 / Torch 2.12 and rework the tested install path (#345)
* Normalize tested install dependencies * Clarify deprecated torch-scatter helper * Clarify standalone and library install paths * Align GPU workflow and cu130 wheel index
1 parent 47f77d3 commit d89ecfb

18 files changed

Lines changed: 963 additions & 1849 deletions

.github/workflows/gpu_compat.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
timeout-minutes: 180
2929
steps:
3030
- name: Checkout
31-
uses: actions/checkout@v6
31+
uses: actions/checkout@v7
3232
with:
3333
fetch-depth: 0
3434

@@ -41,7 +41,7 @@ jobs:
4141
4242
- name: Install DeePTB GPU stack
4343
run: |
44-
bash install.sh "${{ inputs.backend }}" --extra pythtb --test
44+
bash install.sh "${{ inputs.backend }}" --extra pythtb
4545
4646
- name: CUDA and torch-scatter smoke
4747
run: |

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ celerybeat.pid
153153
# Environments
154154
.env
155155
.venv
156+
.compat-envs/
156157
env/
157158
venv/
158159
ENV/
@@ -184,6 +185,9 @@ dptb/_version.py
184185
poetry.lock
185186
poetry.toml
186187

188+
# Compatibility test outputs
189+
tools/compat/results*/
190+
187191
# JetBrains
188192
.idea/
189193
CLAUDE.md

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:24.04
22
SHELL ["/bin/bash", "-c"]
33

44
ARG MINIFORGE_NAME=Miniforge3

Dockerfile.main

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:24.04
22

33
SHELL ["/bin/bash", "-c"]
44

README.md

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Installing **DeePTB** is straightforward with UV, a fast Python package manager.
5858
- **Requirements**
5959
- Git
6060
- Python 3.10 to 3.13
61-
- UV, the recommended installer frontend
61+
- UV, used by `install.sh` as the fast installer frontend
6262
- For GPU installs: an NVIDIA driver compatible with the selected CUDA runtime
6363

6464
- **From Source** (Recommended)
@@ -107,9 +107,34 @@ Installing **DeePTB** is straightforward with UV, a fast Python package manager.
107107
- Automatically create a virtual environment (`.venv`)
108108
- Install a tested PyTorch / PyG / `torch-scatter` binary-wheel combination
109109
- Refuse unsupported Python or CUDA/backend combinations instead of falling back to source builds
110-
- Install all other dependencies
110+
- Install all runtime and test dependencies
111111

112-
4. **Install optional dependencies** (if needed):
112+
4. **Activate the standalone environment**:
113+
114+
`install.sh` installs DeePTB into `.venv` under the current DeePTB
115+
repository. Activate it before running `dptb`:
116+
117+
```bash
118+
source .venv/bin/activate # On Unix/macOS
119+
.venv\Scripts\activate # On Windows
120+
dptb --help
121+
```
122+
123+
5. **Validate the installation**:
124+
DeePTB is under active development, so new installations should run the
125+
test suite once before production use.
126+
127+
```bash
128+
python -m pytest ./dptb/tests/
129+
```
130+
131+
For a faster local check while iterating:
132+
133+
```bash
134+
python -m pytest ./dptb/tests/ -m "not slow"
135+
```
136+
137+
6. **Install optional dependencies** (if needed):
113138
```bash
114139
# For 3D Fermi surface plotting
115140
./install.sh auto --extra 3Dfermi
@@ -121,13 +146,6 @@ Installing **DeePTB** is straightforward with UV, a fast Python package manager.
121146
./install.sh auto --extra pybinding
122147
```
123148

124-
5. **Run DeePTB**:
125-
```bash
126-
source .venv/bin/activate # On Unix/macOS
127-
.venv\Scripts\activate # On Windows
128-
dptb --help
129-
```
130-
131149
- **Developer Install**
132150

133151
`pyproject.toml` declares the broader source-compatible range
@@ -138,39 +156,61 @@ Installing **DeePTB** is straightforward with UV, a fast Python package manager.
138156
uv sync
139157
```
140158

141-
For new machines, prefer `install.sh` because it selects a tested
142-
`torch-scatter` binary wheel for the requested CPU/GPU backend.
159+
This path is for developers who intentionally manage their own environment.
160+
For a tested standalone DeePTB environment, prefer `install.sh`.
143161

144-
- **Easy Installation** (PyPI)
162+
- **Library Installation** (Existing Environment)
145163

146164
> [!WARNING]
147-
> PyPI installation requires a compatible PyTorch and `torch-scatter` binary
148-
> wheel to be installed first. The source install path above is easier for new
149-
> machines.
165+
> This path is for downstream projects or existing environments that import
166+
> DeePTB as a library. The environment must provide a compatible PyTorch and
167+
> `torch-scatter` binary wheel.
150168

151-
**For CPU**:
152-
```bash
153-
# 1. Install torch_scatter matching the tested CPU Torch version
154-
pip install torch-scatter -f https://data.pyg.org/whl/torch-2.12.1+cpu.html
169+
DeePTB keeps a broad Torch compatibility range so downstream projects can
170+
choose their own CPU/GPU backend. In that case, install PyTorch first, then
171+
install a `torch-scatter` binary wheel matching the current Torch version and
172+
backend. If you are working from a DeePTB source checkout, the helper can
173+
inspect the current environment and print the matching PyG wheel command:
155174

156-
# 2. Install DeePTB
157-
pip install dptb
175+
```bash
176+
python - <<'PY'
177+
import torch
178+
print("torch:", torch.__version__)
179+
print("cuda runtime:", torch.version.cuda)
180+
print("cuda available:", torch.cuda.is_available())
181+
PY
182+
183+
python docs/auto_install_torch_scatter.py --dry-run
184+
python docs/auto_install_torch_scatter.py
158185
```
159186
160-
**For GPU** (example with CUDA 12.8 / RTX 50):
187+
Then install DeePTB from the current source checkout:
188+
161189
```bash
162-
# 1. Install torch with CUDA support.
163-
pip install torch==2.10.0 --index-url https://download.pytorch.org/whl/cu128
190+
pip install .
191+
```
164192
165-
# 2. Install torch_scatter matching the Torch/CUDA pair.
166-
pip install torch-scatter -f https://data.pyg.org/whl/torch-2.10.0+cu128.html
193+
Use `pip install -e .` instead if you want an editable developer install.
194+
Published package installs, such as `pip install dptb`, were not part of this
195+
compatibility test pass; prefer a source checkout until that path is tested.
167196
168-
# 3. Install DeePTB
169-
pip install dptb
170-
```
197+
For standalone DeePTB use on a new machine, use the **From Source** installer
198+
above instead; it creates `.venv` and selects a tested Torch / PyG /
199+
`torch-scatter` combination.
171200
172-
> [!TIP]
173-
> For easier installation with automatic GPU/CPU detection, use the **From Source** method above instead.
201+
Example manual `torch-scatter` commands:
202+
203+
```bash
204+
# CPU, torch 2.12.1
205+
pip install --only-binary torch-scatter \
206+
torch-scatter==2.1.2 \
207+
-f https://data.pyg.org/whl/torch-2.12.1+cpu.html
208+
209+
# CUDA 12.8 / torch 2.10.0
210+
pip install --only-binary torch-scatter \
211+
torch-scatter==2.1.2+pt210cu128 \
212+
-f https://data.pyg.org/whl/torch-2.10.0+cu128.html
213+
```
174214
175215
- **Julia Backend** (Optional - for High-Performance Pardiso Solver)
176216
@@ -215,7 +255,7 @@ Installing **DeePTB** is straightforward with UV, a fast Python package manager.
215255
216256
To ensure the code is correctly installed, please run the unit tests first:
217257
```bash
218-
uv run pytest ./dptb/tests/
258+
python -m pytest ./dptb/tests/
219259
```
220260
Be careful if not all tests pass!
221261

docs/auto_install_torch_scatter.py

Lines changed: 111 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,118 @@
1-
# NOTE: This script is no longer needed when using UV package manager.
2-
# UV will automatically install torch_scatter from the configured index in pyproject.toml.
3-
# This script is kept for reference and for users not using UV.
1+
"""Install torch-scatter for the currently installed PyTorch.
42
3+
This helper is for library/downstream installs where the environment already
4+
owns its PyTorch stack. For standalone DeePTB installs, prefer ``install.sh``.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
import argparse
10+
import re
511
import subprocess
12+
import sys
13+
from importlib import metadata
14+
15+
16+
SCATTER_VERSION = "2.1.2"
17+
18+
19+
def normalize_torch_version(version: str) -> tuple[str, str]:
20+
match = re.match(r"^(\d+\.\d+\.\d+)(?:\+([A-Za-z0-9_]+))?", version)
21+
if not match:
22+
raise SystemExit(f"ERROR: cannot parse torch version: {version}")
23+
24+
base_version = match.group(1)
25+
backend = match.group(2) or "cpu"
26+
if backend.startswith("cu"):
27+
return base_version, backend
28+
return base_version, "cpu"
29+
30+
31+
def scatter_requirement(torch_base: str, backend: str) -> str:
32+
if backend == "cpu":
33+
return f"torch-scatter=={SCATTER_VERSION}"
34+
35+
major, minor, _patch = torch_base.split(".")
36+
return f"torch-scatter=={SCATTER_VERSION}+pt{major}{minor}{backend}"
637

7-
try:
8-
import torch
9-
print("The torch module has been successfully imported!")
1038

11-
torch_version = torch.__version__
12-
print(f"Current torch version: {torch_version}")
39+
def installed_scatter_version() -> str | None:
40+
try:
41+
return metadata.version("torch-scatter")
42+
except metadata.PackageNotFoundError:
43+
return None
44+
1345

14-
if torch.cuda.is_available():
15-
cuda_version = torch.version.cuda
16-
else:
17-
cuda_version = "cpu"
18-
print(f"Versions of CUDA used by PyTorch: {cuda_version}")
46+
def main() -> None:
47+
parser = argparse.ArgumentParser(
48+
description=(
49+
"Install a torch-scatter binary wheel matching the current torch "
50+
"version and CPU/CUDA backend."
51+
)
52+
)
53+
parser.add_argument(
54+
"--dry-run",
55+
action="store_true",
56+
help="Print the pip command without installing anything.",
57+
)
58+
parser.add_argument(
59+
"--force",
60+
action="store_true",
61+
help="Reinstall torch-scatter even if it is already importable.",
62+
)
63+
args = parser.parse_args()
1964

2065
try:
21-
import torch_scatter
22-
print("You have already installed torch-scatter!")
23-
24-
except ImportError:
25-
url = f"https://data.pyg.org/whl/torch-{torch_version}.html"
26-
print(f"torch-scatter will be installed from {url}...")
27-
subprocess.run(["pip", "install", "torch-scatter==2.1.2", "-f", url], check=True)
28-
print("Installation complete, please re-run the program.")
29-
30-
except ImportError:
31-
print("The torch module is not found, please install PyTorch first.")
32-
print("You can install PyTorch with the following command (version range: 2.0.0-2.5.1) :")
33-
print("pip install \"torch>=2.0.0,<=2.5.1\"")
66+
import torch
67+
except ImportError as exc:
68+
raise SystemExit(
69+
"ERROR: torch is not installed in this environment. Install the "
70+
"PyTorch build required by your project first, then rerun this "
71+
"helper."
72+
) from exc
73+
74+
torch_base, backend = normalize_torch_version(torch.__version__)
75+
find_links = f"https://data.pyg.org/whl/torch-{torch_base}+{backend}.html"
76+
requirement = scatter_requirement(torch_base, backend)
77+
78+
current_scatter = installed_scatter_version()
79+
print("Detected environment:")
80+
print(f" Python: {sys.version.split()[0]}")
81+
print(f" torch: {torch.__version__}")
82+
print(f" CUDA runtime: {torch.version.cuda}")
83+
print(f" CUDA available: {torch.cuda.is_available()}")
84+
print(f" PyG wheel index: {find_links}")
85+
print(f" torch-scatter: {requirement}")
86+
87+
if current_scatter and not args.force:
88+
required_version = requirement.split("==", 1)[1].lower()
89+
if current_scatter.lower() == required_version:
90+
print(f"torch-scatter is already installed: {current_scatter}")
91+
return
92+
print(f"torch-scatter is already installed: {current_scatter}")
93+
print(f"The detected torch backend expects: {required_version}")
94+
print("Use --force to reinstall it for the detected torch backend.")
95+
raise SystemExit(1)
96+
97+
command = [
98+
sys.executable,
99+
"-m",
100+
"pip",
101+
"install",
102+
"--only-binary",
103+
"torch-scatter",
104+
requirement,
105+
"-f",
106+
find_links,
107+
]
108+
109+
print("Command:")
110+
print(" " + " ".join(command))
111+
if args.dry_run:
112+
return
113+
114+
subprocess.run(command, check=True)
115+
116+
117+
if __name__ == "__main__":
118+
main()

0 commit comments

Comments
 (0)