Skip to content
Merged
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
python-version: "3.11"

- name: Sync dependencies
run: uv sync --group dev

- name: Tox
run: uv run tox
14 changes: 11 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ipython_config.py
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
Expand Down Expand Up @@ -182,9 +182,9 @@ cython_debug/
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/

Expand All @@ -201,6 +201,14 @@ cython_debug/
.cursorignore
.cursorindexingignore

# macOS
.DS_Store

# PyTorch artifacts
*.pt
*.pth
*.safetensors

# Marimo
marimo/_static/
marimo/_lsp/
Expand Down
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- repo: local
hooks:
- id: ruff-check
name: ruff check
entry: uv run ruff check src tests
language: system
pass_filenames: false
- id: ruff-format-check
name: ruff format --check
entry: uv run ruff format --check src tests
language: system
pass_filenames: false
- id: mypy
name: mypy
entry: uv run mypy --no-incremental src tests
language: system
pass_filenames: false
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,94 @@
# qRG
A torch based toolkit for renormalization group computations.

## Developer Setup

This repository uses `uv` for environment management, `tox` for checks, and `pre-commit` for local hooks.

### Requirements

- Python 3.11
- `uv`

Install `uv` if needed:

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

### Quick Start

Clone the repo and choose one PyTorch backend extra:

- `cpu`
- `cu126`
- `cu128`
- `cu129`
- `cu130`

Standard development setup with CPU PyTorch:

```bash
git clone <your-repo-url>
cd qRG
uv sync --group dev --extra cpu
uv run pre-commit install
```

If you want a CUDA backend instead, replace `cpu` with one of the CUDA extras, for example:

```bash
uv sync --group dev --extra cu128
```

Only one backend extra can be installed at a time.

### Common Commands

Run all checks:

```bash
uv run tox
```

Run pre-commit on all files:

```bash
uv run pre-commit run --all-files
```

Build the package:

```bash
uv run python -m build
```

### Minimal Install

If you only want the base package without dev tools or PyTorch extras:

```bash
uv sync
```

This installs the package and its base dependency `qten`, but not `dev` or any torch backend.

### Reinstall

Clean reinstall:

```bash
rm -rf .venv uv.lock
uv sync --group dev --extra cpu
```

Force reinstall in the existing environment:

```bash
uv sync --reinstall --group dev --extra cpu
```

### Notes

- `uv.lock` is ignored in this repository.
- Common Torch checkpoint files are ignored in git.
137 changes: 137 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
[build-system]
requires = ["setuptools>=69", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "qRG"
version = "0.1.0"
description = "A torch based package for renormalization group computation."
readme = "README.md"
requires-python = ">=3.11"
license = { file = "LICENSE" }
authors = [
{ name = "alphaharrius" },
{ name = "eyjafjallac" },
]
dependencies = [
"qten",
]
[project.optional-dependencies]
cpu = [
"torch>=2.7.0",
"torchvision>=0.22.0",
]
cu126 = [
"torch>=2.7.0",
"torchvision>=0.22.0",
]
cu128 = [
"torch>=2.7.0",
"torchvision>=0.22.0",
]
cu129 = [
"torch>=2.7.0",
"torchvision>=0.22.0",
]
cu130 = [
"torch>=2.7.0",
"torchvision>=0.22.0",
]
Comment on lines +19 to +39

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All backend extras (cpu, cu126, cu128, etc.) declare identical dependencies (torch/torchvision), and the actual index selection is implemented only under [tool.uv.sources]. Installers other than uv (e.g., pip install .[cu128]) will ignore the tool.uv config and likely resolve the default (often CPU) wheels, making these extras misleading. Consider documenting that uv is required for CUDA extras, or encode CUDA-specific requirements in a way that works with standard installers.

Copilot uses AI. Check for mistakes.

[tool.setuptools]
package-dir = { "" = "src" }

[tool.setuptools.packages.find]
where = ["src"]

[tool.uv]
package = true
conflicts = [
[{ extra = "cpu" }, { extra = "cu126" }, { extra = "cu128" }, { extra = "cu129" }, { extra = "cu130" }],
]

[tool.uv.sources]
torch = [
{ index = "pytorch-cu126", extra = "cu126" },
{ index = "pytorch-cu128", extra = "cu128" },
{ index = "pytorch-cu129", extra = "cu129" },
{ index = "pytorch-cu130", extra = "cu130" },
{ index = "pytorch-cpu", extra = "cpu", marker = "sys_platform == 'linux'" },
{ index = "pypi", extra = "cpu", marker = "sys_platform != 'linux'" },
]
torchvision = [
{ index = "pytorch-cu126", extra = "cu126" },
{ index = "pytorch-cu128", extra = "cu128" },
{ index = "pytorch-cu129", extra = "cu129" },
{ index = "pytorch-cpu", extra = "cpu", marker = "sys_platform == 'linux'" },
{ index = "pypi", extra = "cpu", marker = "sys_platform != 'linux'" },
]

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

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

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

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

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

[[tool.uv.index]]
name = "pypi"
url = "https://pypi.org/simple"

[dependency-groups]
dev = [
"build>=1.2.2",
"mypy>=1.10",
"pre-commit>=3.7",
"pytest>=8.2",
"pytest-cov>=4.0.0",
"ruff>=0.5",
"tox>=4.0.0",
"tox-uv>=1.0.0",
"twine>=5.1.1",
]
nb = [
"ipykernel>=6.29.0",
"jupyterlab>=4.2.0",
"notebook>=7.2.0",
"qten-plots>=0.1.0",
]

[tool.pytest.ini_options]
testpaths = ["tests"]

[tool.ruff]
target-version = "py311"
line-length = 100

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"

[tool.mypy]
python_version = "3.11"
files = ["src", "tests"]
strict = true
warn_unused_ignores = true
disallow_any_generics = true
5 changes: 5 additions & 0 deletions src/qrg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""qRG package."""

__all__ = ["__version__"]

__version__ = "0.1.0"

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__version__ is hard-coded here and also duplicated in pyproject.toml. This will eventually drift and cause incorrect version reporting; consider deriving it from installed package metadata (e.g., via importlib.metadata) or using a single-source versioning approach so you only update the version in one place.

Suggested change
__version__ = "0.1.0"
try:
# Python 3.8+
from importlib.metadata import PackageNotFoundError, version
except ImportError: # pragma: no cover
# Python < 3.8
from importlib_metadata import PackageNotFoundError, version # type: ignore[import]
try:
# Use the top-level package name as the distribution name
_distribution_name = __name__.split(".")[0]
__version__ = version(_distribution_name)
except PackageNotFoundError: # pragma: no cover
# Fallback when the package is not installed with metadata available
__version__ = "0.0.0"

Copilot uses AI. Check for mistakes.
5 changes: 5 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import qrg


def test_package_imports() -> None:
assert qrg.__version__
35 changes: 35 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[tox]
requires =
tox>=4.0.0
tox-uv>=1.0.0
env_list =
py311
lint
type

[testenv]
description = Run the test suite with coverage.
package = wheel
extras =
cpu
dependency_groups =
dev
commands =
pytest --cov=qrg --cov-report=term-missing tests
Comment on lines +12 to +18

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default [testenv] installs the cpu extra, which will pull in torch/torchvision for every test run and in CI. Since the current tests are only a smoke import test, this adds significant install time and potential CI flakiness for no functional benefit; consider making torch installation a dedicated tox env/factor (or optional) so unit tests can run without heavyweight extras.

Copilot uses AI. Check for mistakes.

[testenv:lint]
description = Run Ruff checks.
package = skip
dependency_groups =
dev
commands =
ruff check src tests
ruff format --check src tests

[testenv:type]
description = Run mypy checks.
package = skip
dependency_groups =
dev
commands =
mypy --no-incremental src tests
Loading