Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
python-version:
- "3.10"
env:
PYTHON_VERSION: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv and set the Python version
uses: astral-sh/setup-uv@v6
with:
version: "0.9.0"
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "pyproject.toml"

# Update full Python version
- name: Full Python version
run: |
echo "PYTHON_VERSION=$(python -c "import platform; print(platform.python_version())")"
echo "PYTHON_VERSION=$(python -c "import platform; print(platform.python_version())")" >> $GITHUB_ENV
enable-cache: "true"

- name: Get changed files
id: changed-files-specific
Expand All @@ -60,32 +55,30 @@ jobs:
~/.cache/torch-uncertainty/
key: torch-uncertainty-${{ runner.os }}

- name: Install the minimal dependencies
- name: Install the project
if: steps.changed-files-specific.outputs.only_changed != 'true'
run: |
python3 -m pip install torch torchvision
python3 -m pip install .

run: uv sync --locked --dev --extra cpu

- name: Check that torch-uncertainty can be imported
if: steps.changed-files-specific.outputs.only_changed != 'true'
run: |
python3 -c "import torch_uncertainty; from torch_uncertainty.datamodules import MNISTDataModule"

- name: Install the optional dependencies
if: steps.changed-files-specific.outputs.only_changed != 'true'
run: |
python3 -m pip install .[all]
uv run python -c "import torch_uncertainty; from torch_uncertainty.datamodules import MNISTDataModule"

- name: Check style & format
if: steps.changed-files-specific.outputs.only_changed != 'true'
run: |
python3 -m ruff check torch_uncertainty --no-fix --statistics
python3 -m ruff format torch_uncertainty --check
uv run ruff check src/torch_uncertainty --no-fix --statistics
uv run ruff format src/torch_uncertainty --check

- name: Test with pytest and compute coverage
if: steps.changed-files-specific.outputs.only_changed != 'true'
run: |
python3 -m pytest tests --cov --cov-report xml --cov-report term --durations 10 --junitxml=junit.xml
uv run --frozen pytest tests --cov --cov-report xml --cov-report term --durations 10 --junitxml=junit.xml

# Store Python version
- name: Full Python version
run: |
echo "PYTHON_VERSION=$(uv run python -c "import platform; print(platform.python_version())")" >> $GITHUB_ENV

- name: Upload coverage to Codecov
if: steps.changed-files-specific.outputs.only_changed != 'true' && (github.event_name != 'pull_request' || github.base_ref == 'dev')
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repos:
name: check-added-large-files
entry: check-added-large-files
language: system
exclude: uv.lock
- id: ruff-check
name: ruff-check
entry: ruff check
Expand Down
6 changes: 3 additions & 3 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@uv run $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

html-noplot:
@$(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
@uv run $(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

Expand All @@ -26,4 +26,4 @@ clean:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@uv run $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
19 changes: 6 additions & 13 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,16 @@ If you are interested in contributing to torch_uncertainty, we first advise you
to follow the following steps to reproduce a clean development environment
ensuring continuous integration does not break.

1. Check that you have PyTorch already installed on your system
1. Install ``uv`` following the steps `here <https://docs.astral.sh/uv/getting-started/installation/>`_
2. Clone the repository
3. Install torch-uncertainty in editable mode with the dev packages:
:cmd:`python3 -m pip install -e .[dev]`
4. Install pre-commit hooks with :cmd:`pre-commit install`
3. Install torch-uncertainty with the dev packages change ``gpu`` to ``cpu`` if needed:
:cmd:`uv sync --extra gpu`
4. Install pre-commit hooks with :cmd:`uv run pre-commit install`

Build the documentation locally
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To build the documentation, reinstall TorchUncertainty with the packages of the docs
group:

.. parsed-literal::

python3 -m pip install -e .[dev,docs]

Then navigate to ``./docs`` and build the documentation with:
To build the documentation on Linux, navigate to ``./docs`` and build the documentation with:

.. parsed-literal::

Expand All @@ -73,7 +66,7 @@ run, at the root of the folder:

.. parsed-literal::

python3 -m pytest tests
uv run pytest tests

Try to include an emoji at the start of each commit message following the suggestions
from `this page <https://gist.github.com/parmentf/035de27d6ed1dce0b36a>`_.
Expand Down
91 changes: 73 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
requires = ["uv_build>=0.8.22,<0.9.0"]
build-backend = "uv_build"

[project]
name = "torch_uncertainty"
Expand Down Expand Up @@ -34,23 +34,27 @@ classifiers = [
dependencies = [
"timm",
"lightning[pytorch-extra]>=2.0",
"torch>=2.1,<=2.8.0",
"torchvision>=0.16",
"einops",
"seaborn",
]

[project.optional-dependencies]
experiments = ["tensorboard", "huggingface-hub>=0.31", "safetensors"]
image = ["kornia", "h5py", "opencv-python", "torch-uncertainty-assets"]
tabular = ["pandas"]
distribution = ["scipy"]
timeseries = ["tslearn"]
[dependency-groups]
dev = [
"torch_uncertainty[experiments,image]",
"ruff==0.12.5",
"pytest-cov",
"pre-commit",
"pre-commit-hooks",
{include-group = "lint"},
{include-group = "test"},
{include-group = "docs"},
]

lint = [
"ruff==0.12.5",
"pre-commit",
"pre-commit-hooks",
]
test = [
"torch_uncertainty[all]",
"pytest-cov",
]
docs = [
"sphinx==7.4.7",
Expand All @@ -62,13 +66,59 @@ docs = [
"sphinx_design",
"sphinxcontrib-sass",
]


[project.optional-dependencies]
all = [
"torch_uncertainty[dev,docs,tabular,distribution,timeseries]",
"scikit-learn",
"laplace-torch",
"glest==0.0.1a1",
"torch_uncertainty[experiments,image,distribution,timeseries,others]",
]
experiments = ["tensorboard", "huggingface-hub>=0.31", "safetensors"]
image = ["kornia", "h5py", "opencv-python", "torch-uncertainty-assets"]
distribution = ["scipy"]
timeseries = ["tslearn"]
others = [
"scikit-learn",
"laplace-torch",
"glest==0.0.1a1",
]

cpu = [
"torch>=2.1.0,<=2.8.0",
"torchvision>=0.16.0",
]
gpu = [
"torch>=2.1.0,<=2.8.0",
"torchvision>=0.16.0",
]

[tool.uv]
conflicts = [
[
{ extra = "cpu" },
{ extra = "gpu" },
],
]

[tool.uv.sources]
torch = [
{ index = "pytorch-cpu", extra = "cpu" },
{ index = "pytorch-cu128", extra = "gpu" },
]
torchvision = [
{ index = "pytorch-cpu", extra = "cpu" },
{ index = "pytorch-cu128", extra = "gpu" },
]

[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu128"
url = "https://download.pytorch.org/whl/cu128"
explicit = true

[project.urls]
homepage = "https://torch-uncertainty.github.io/"
documentation = "https://torch-uncertainty.github.io/quickstart.html"
Expand Down Expand Up @@ -170,7 +220,12 @@ docstring-code-line-length = 80
[tool.coverage.run]
branch = true
include = ["*/torch-uncertainty/*"]
omit = ["*/tests/*", "*/datasets/*"]
omit = [
"*/tests/*",
"*/datasets/*",
".venv/*",
"*/venv/*",
]

[tool.coverage.report]
exclude_lines = [
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sys

from torch_uncertainty.models import resnet
from torch_uncertainty.routines import ClassificationRoutine
from torch_uncertainty.datamodules import CIFAR10DataModule
from torch_uncertainty.routines import ClassificationRoutine
from torch_uncertainty.utils.cli import TULightningCLI, TUSaveConfigCallback


Expand Down
Loading