Skip to content

Commit 9dad224

Browse files
PanadesteinCopilot
andauthored
feat: ❄️ add Nix flake and update dependencies (#23)
* feat: ❄️ add Nix flake dev shell Provides a `nix develop` shell with uv, git and gh plus the native libs binary wheels need, as an alternative to the DevContainer. Python and all project dependencies stay managed by uv. Also drops the duplicate arXiv link from the README abstract. * chore: ❄️ lock and fix up the Nix flake Validated with nix flake check --all-systems and a full dev shell run. - Commit flake.lock, pinning nixpkgs. - Drop x86_64-darwin: unsupported by nixpkgs-unstable since 26.11. - Use stdenv.hostPlatform.isLinux and pkgs.nixfmt (deprecation warnings). - Activate the venv via UV_PROJECT_ENVIRONMENT instead of sourcing .venv/bin/activate, which hardcodes paths and misses relocated venvs. * fix: 🐛 close the unterminated ignoreWords array in cspell.json The file was invalid JSON, so cSpell silently fell back to its defaults. * feat!: ⬆️ support Python 3.12-3.14, default to 3.14 numpy 2.5 requires >=3.12, so a 3.11 floor silently capped users at numpy 2.4.x; 3.11 is also security-only until Oct 2027. Raise the floor to 3.12 and add 3.14. - requires-python >=3.12,<3.15 and matching classifiers. - .python-version, docpages, copilot-setup-steps and the Sonar job use 3.14. - Test matrix covers the range ends: 3.12 and 3.14. - ruff target-version and pyright pythonVersion track the *oldest* supported version, so they stay one step behind the default at 3.12. BREAKING CHANGE: Python 3.11 is no longer supported. * fix: 🚨 single-source the ruff pin at 0.16.5 The pre-commit config still referenced the retired charliermarsh/ruff-pre-commit mirror, but update-ruff.yml only rewrites revs for astral-sh/ruff-pre-commit, so the hook silently stayed on v0.12.11 while pyproject moved to 0.16.5. Point the hook at astral-sh and pin both to 0.16.5, which lets the monthly workflow keep them in sync from now on. Fixes the B008 this uncovered: random_mpo built its default Generator in the signature, so every caller that omitted rng shared one generator and test data depended on execution order. * chore: improve wording Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Ramón L. Panadés-Barrueta <rpana92@gmail.com> * fix: 💚 keep the benchmark job on an interpreter both sides accept The job benchmarks the base commit and the PR commit in one run, so pinning it to 3.14 broke it: main still declares requires-python <3.14 and uv refused to sync the base checkout. Use 3.13, which satisfies both ranges. * fix: 💚 regenerate uv.lock after the merge from main Git text-merged the two lockfiles and produced an ipython entry without a source field, so every job died at 'uv sync' with: error: Failed to parse `uv.lock` Caused by: Dependency `ipython` has missing `source` field but has more than one matching package Lockfiles cannot be merged line by line; reset to main's copy and re-resolved against the merged pyproject. * ci: 💚 loosen the benchmark regression threshold to 25% The comparison runs on a shared ubuntu-latest runner, where PRs that touch no source file have drifted by 10.8%, 12.4% and 20.2%. At 10% the check reported noise as a regression often enough to be ignored, which defeats the point of having it. --------- Signed-off-by: Ramón L. Panadés-Barrueta <rpana92@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 4a18982 commit 9dad224

16 files changed

Lines changed: 604 additions & 396 deletions

‎.envrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

‎.github/copilot-instructions.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
### Python Instructions
1919

20-
- Write code to support Python 3.11, 3.12, 3.13.
20+
- Write code to support Python 3.12, 3.13, 3.14.
2121
- Write clear and concise comments for each function.
2222
- Ensure functions have descriptive names and include type hints.
2323
- Provide docstrings following PEP 257 conventions.
@@ -54,7 +54,8 @@ def calculate_area(radius: float) -> float:
5454
The area of the circle, calculated as π * radius^2.
5555
"""
5656
import math
57-
return math.pi * radius ** 2
57+
58+
return math.pi * radius**2
5859
```
5960

6061
## Development Commands

‎.github/workflows/copilot-setup-steps.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: astral-sh/setup-uv@v7
2828
with:
2929
enable-cache: true
30-
python-version: "3.11"
30+
python-version: "3.14"
3131

3232
- name: Install package
3333
run: |

‎.github/workflows/docpages.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
uses: astral-sh/setup-uv@v7
4848
with:
4949
enable-cache: true
50-
python-version: "3.11"
50+
python-version: "3.14"
5151

5252
- name: Install package
5353
run: |

‎.github/workflows/test.yml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
- ubuntu-latest
4343
- gpu-runner
4444
python-version:
45-
- "3.11"
46-
- "3.13"
45+
- "3.12"
46+
- "3.14"
4747
test-group:
4848
- "not slow and not perf"
4949

@@ -129,7 +129,9 @@ jobs:
129129
retention-days: 1
130130

131131
benchmark:
132-
# Will fail if an slowdown in the median of more than 10% is detected
132+
# Fails on a median slowdown of more than 25%. The threshold is wide
133+
# because this runs on a shared runner, where no-op PRs have drifted by
134+
# up to 20%; anything tighter reports noise as a regression.
133135
name: 'Run Benchmark Comparison'
134136
if: github.event_name == 'pull_request'
135137
runs-on: ubuntu-latest
@@ -148,6 +150,8 @@ jobs:
148150
uses: astral-sh/setup-uv@v7
149151
with:
150152
enable-cache: true
153+
# This job builds both the base and the PR checkout, so the version
154+
# must satisfy `requires-python` on both sides of the comparison.
151155
python-version: "3.13"
152156

153157
- name: 'Install dependencies'
@@ -185,7 +189,7 @@ jobs:
185189
-W ignore::pytest_benchmark.logger.PytestBenchmarkWarning \
186190
--log-cli-level=WARNING \
187191
--benchmark-storage=file://baseline-benchmarks \
188-
--benchmark-compare-fail=median:10% \
192+
--benchmark-compare-fail=median:25% \
189193
--benchmark-compare=0001
190194
191195
publish-test-results:

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,9 @@ Thumbs.db
238238
*~
239239
*.swp
240240

241+
### Nix ###
242+
result
243+
result-*
244+
.direnv/
245+
241246
sandbox/**

‎.pre-commit-config.yaml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ repos:
2222
- id: trailing-whitespace
2323
exclude: '\.out$'
2424

25-
- repo: https://github.com/charliermarsh/ruff-pre-commit
26-
rev: v0.12.11
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
# Keep in sync with the ruff pin in pyproject.toml; update-ruff.yml bumps both.
27+
rev: v0.16.5
2728
hooks:
2829
- id: ruff
2930
exclude: '\.out$|^benches/'

‎.python-version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.14

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ accuracy, not just the shapes.
5959

6060
## Code style
6161

62-
The project targets Python 3.11+ and is checked with `ruff` under a strict rule
62+
The project targets Python 3.12+ and is checked with `ruff` under a strict rule
6363
set. Public functions carry type hints and Google-style docstrings without type
6464
annotations in the argument list. Keep lines within the configured limit and
6565
prefer clear code over clever code.

‎README.md‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Test src_method](https://github.com/Algorithmiq/src-method/actions/workflows/test.yml/badge.svg)](https://github.com/Algorithmiq/src-method/actions/workflows/test.yml)
55
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
66

7-
An implementation of the SRC algorithm introduced in [Camaño, Epperly and Tropp, *Quantum* **10**, 2022 (2026)](https://doi.org/10.22331/q-2026-03-10-2022) ([arXiv:2504.06475](https://arxiv.org/abs/2504.06475)), extending the idea to other kinds of tensor networks.
7+
An implementation of the SRC algorithm introduced in [Camaño, Epperly and Tropp, *Quantum* **10**, 2022 (2026)](https://doi.org/10.22331/q-2026-03-10-2022), extending the idea to other kinds of tensor networks.
88

99
### Features
1010

@@ -116,6 +116,33 @@ process is done, you will have _all_ project dependencies installed, including
116116
> DevContainer is non-deterministic. You might have to execute the *Reload Window*
117117
> command to get everything to work as expected after a fresh build of the container.
118118
119+
### Alternative: Nix flake
120+
121+
If you prefer [Nix] over Docker, the repository ships a `flake.nix` that provides
122+
a development shell with [uv], [Git] and the [GitHub CLI], plus the native
123+
libraries the binary wheels need at runtime. Python itself and all project
124+
dependencies remain managed by `uv`.
125+
126+
With [flakes enabled](https://nixos.wiki/wiki/Flakes#Enable_flakes_temporarily), run:
127+
128+
```bash
129+
nix develop
130+
```
131+
132+
Entering the shell runs `uv sync --all-groups` and activates the uv project
133+
environment (`$UV_PROJECT_ENVIRONMENT` if set, otherwise `.venv`), so you land
134+
in a ready-to-use environment. GPU extras are not installed by the flake: add them
135+
explicitly with `uv sync --all-groups --extra gpu-nvidia` (or `--all-groups --extra gpu-rocm`) on a machine with the matching drivers.
136+
137+
If you use [direnv], the provided `.envrc` enters the shell automatically:
138+
139+
```bash
140+
direnv allow
141+
```
142+
143+
Unlike the DevContainer, the Nix shell does not install the `pre-commit` hooks for
144+
you. Run `pre-commit install --install-hooks` once after the first `nix develop`.
145+
119146
## Documentation
120147

121148
We use [MkDocs] to generate our documentation pages. You can find the latest version [at this link].
@@ -135,5 +162,9 @@ the editor will prompt you to open a new page in your browser, where you can see
135162
[Docker]: https://docs.docker.com/get-docker/
136163
[Visual Studio Code]: https://code.visualstudio.com/
137164
[GitHub CLI]: https://cli.github.com/
165+
[Git]: https://git-scm.com/
166+
[Nix]: https://nixos.org/download/
167+
[direnv]: https://direnv.net/
168+
[uv]: https://docs.astral.sh/uv/
138169
[MkDocs]: https://www.mkdocs.org/
139170
[at this link]: https://docs.algorithmiq.fi/src_method

0 commit comments

Comments
 (0)