diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e2821b9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index b7faf40..4d3f601 100644 --- a/.gitignore +++ b/.gitignore @@ -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. @@ -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/ @@ -201,6 +201,14 @@ cython_debug/ .cursorignore .cursorindexingignore +# macOS +.DS_Store + +# PyTorch artifacts +*.pt +*.pth +*.safetensors + # Marimo marimo/_static/ marimo/_lsp/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..70ae16f --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 61711ad..94a0b06 100644 --- a/README.md +++ b/README.md @@ -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 +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. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..923300c --- /dev/null +++ b/pyproject.toml @@ -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", +] + +[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 diff --git a/src/qrg/__init__.py b/src/qrg/__init__.py new file mode 100644 index 0000000..00695fa --- /dev/null +++ b/src/qrg/__init__.py @@ -0,0 +1,5 @@ +"""qRG package.""" + +__all__ = ["__version__"] + +__version__ = "0.1.0" diff --git a/tests/test_smoke.py b/tests/test_smoke.py new file mode 100644 index 0000000..c674d14 --- /dev/null +++ b/tests/test_smoke.py @@ -0,0 +1,5 @@ +import qrg + + +def test_package_imports() -> None: + assert qrg.__version__ diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ff351d1 --- /dev/null +++ b/tox.ini @@ -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 + +[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