Skip to content

Commit 56d78e1

Browse files
Patrick Kidger Botpatrick-kidger
authored andcommitted
Use dependency groups, uv, and local pre-commit hooks
1 parent 7ac1ea0 commit 56d78e1

14 files changed

Lines changed: 104 additions & 87 deletions

.github/workflows/build_docs.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ jobs:
1616
- name: Checkout code
1717
uses: actions/checkout@v2
1818

19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
19+
- name: Install the latest version of uv
20+
uses: astral-sh/setup-uv@v7
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323

2424
- name: Install dependencies
2525
run: |
26-
python -m pip install --upgrade pip
27-
python -m pip install '.[docs]'
26+
uv run echo done
2827
2928
- name: Build docs
3029
run: |
31-
mkdocs build
30+
uv run mkdocs build
3231
3332
- name: Upload docs
3433
uses: actions/upload-artifact@v4

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ jobs:
1313
uses: patrick-kidger/action_update_python_project@v8
1414
with:
1515
python-version: "3.11"
16+
# Uninstall and reinstall pytest to work around the fact that it doesn't get put into `bin` otherwise.
1617
test-script: |
1718
cp -r ${{ github.workspace }}/test ./test
1819
cp ${{ github.workspace }}/pyproject.toml ./pyproject.toml
19-
uv sync --extra tests --no-install-project --inexact
20+
uv pip uninstall pytest
21+
uv sync --no-install-project --inexact
2022
uv run --no-sync python -m test
2123
pypi-token: ${{ secrets.pypi_token }}
2224
github-user: patrick-kidger

.github/workflows/run_tests.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@ jobs:
1515
- name: Checkout code
1616
uses: actions/checkout@v2
1717

18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v2
18+
- name: Install the latest version of uv
19+
uses: astral-sh/setup-uv@v7
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222

2323
- name: Install dependencies
2424
run: |
25-
python -m pip install --upgrade pip
26-
python -m pip install '.[dev,docs,tests]'
25+
uv run echo done
2726
2827
- name: Checks with pre-commit
2928
run: |
30-
pre-commit run --all-files
29+
uv run prek run --all-files
3130
3231
- name: Test with pytest
3332
run: |
34-
python -m test
33+
uv run python -m test
3534
3635
- name: Check that documentation can be built.
3736
run: |
38-
mkdocs build
37+
uv run mkdocs build

.pre-commit-config.yaml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1+
fail_fast: true
12
repos:
2-
- repo: local
3+
- repo: meta
34
hooks:
4-
- id: sort_pyproject
5-
name: sort_pyproject
6-
entry: toml-sort -i --sort-table-keys --sort-inline-tables
7-
language: python
8-
files: ^pyproject\.toml$
9-
additional_dependencies: ["toml-sort==0.23.1"]
10-
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.13.0
5+
- id: check-hooks-apply
6+
- id: check-useless-excludes
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.4.0
129
hooks:
13-
- id: ruff-format # formatter
14-
types_or: [ python, pyi, jupyter, toml ]
15-
- id: ruff # linter
16-
types_or: [ python, pyi, jupyter, toml ]
17-
args: [ --fix ]
18-
- repo: https://github.com/RobertCraigie/pyright-python
19-
rev: v1.1.405
10+
- id: trailing-whitespace
11+
exclude: \.md$
12+
- id: check-toml
13+
- id: mixed-line-ending
14+
- repo: local
2015
hooks:
21-
- id: pyright
22-
additional_dependencies: [equinox, jax, jaxtyping, optax, optimistix, lineax, pytest, typeguard==2.13.3, typing_extensions, wadler_lindig]
16+
- id: sort-pyproject
17+
name: sort pyproject
18+
files: ^pyproject\.toml$
19+
language: system
20+
entry: uv run -- toml-sort -i --sort-table-keys --sort-inline-tables
21+
- id: ruff-format
22+
name: ruff format
23+
types_or: [python, pyi, jupyter, toml]
24+
language: system
25+
entry: uv run -- ruff format --
26+
require_serial: true
27+
- id: ruff-lint
28+
name: ruff lint
29+
types_or: [python, pyi, jupyter, toml]
30+
language: system
31+
entry: uv run -- ruff check --fix --
32+
require_serial: true
33+
- id: pyright
34+
name: pyright
35+
types_or: [python]
36+
language: system
37+
entry: uv run -- pyright
38+
require_serial: true

CONTRIBUTING.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@ Contributions (pull requests) are very welcome! Here's how to get started.
44

55
---
66

7-
**Getting started**
7+
### Getting started
88

9-
First fork the library on GitHub.
10-
11-
Then clone and install the library:
9+
[We assume that you have `uv` installed.](https://docs.astral.sh/uv/) Now fork the library on GitHub. Then clone and install the library:
1210

1311
```bash
1412
git clone https://github.com/your-username-here/diffrax.git
1513
cd diffrax
16-
pip install -e '.[dev]'
17-
pre-commit install # `pre-commit` is installed by `pip` on the previous line
14+
uv run prek install # Creates a local venv + installs dependencies + installs pre-commit hooks.
1815
```
1916

2017
---
2118

22-
**If you're making changes to the code:**
23-
24-
Now make your changes. Make sure to include additional tests if necessary.
19+
### If you're making changes to the code
2520

26-
Next verify the tests all pass:
21+
Now make your changes. Make sure to include additional tests if necessary. Next verify the tests all pass:
2722

2823
```bash
29-
pip install -e '.[tests]'
30-
pytest # `pytest` is installed by `pip` on the previous line.
24+
uv run pytest
3125
```
3226

3327
Then push your changes back to your fork of the repository:
@@ -40,13 +34,12 @@ Finally, open a pull request on GitHub!
4034

4135
---
4236

43-
**If you're making changes to the documentation:**
37+
### If you're making changes to the documentation
4438

4539
Make your changes. You can then build the documentation by doing
4640

4741
```bash
48-
pip install -e '.[docs]'
49-
mkdocs serve
42+
uv run mkdocs serve
5043
```
5144

5245
You can then see your local copy of the documentation by navigating to `localhost:8000` in a web browser.

diffrax/_autocitation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def _backsolve_adjoint(adjoint, terms=None):
222222
r"""
223223
% You are backpropagating through an SDE using optimise-then-discretise
224224
% (`adjoint=BacksolveAdjoint(...)`)
225-
% This technique was introduced in
225+
% This technique was introduced in
226226
"""
227227
+ vbt_ref
228228
+ r"""
@@ -273,10 +273,10 @@ def _discrete_adjoint(adjoint):
273273
% If using forward-mode autodifferentiation, then this was studied in:
274274
@inproceedings{ma2021comparison,
275275
title={A Comparison of Automatic Differentiation and Continuous Sensitivity Analysis
276-
for Derivatives of Differential Equation Solutions},
276+
for Derivatives of Differential Equation Solutions},
277277
author={Ma, Yingbo and Dixit, Vaibhav and Innes, Michael J and Guo, Xingjian and
278278
Rackauckas, Chris},
279-
booktitle={2021 IEEE High Performance Extreme Computing Conference (HPEC)},
279+
booktitle={2021 IEEE High Performance Extreme Computing Conference (HPEC)},
280280
year={2021},
281281
pages={1-9},
282282
doi={10.1109/HPEC49654.2021.9622796}

diffrax/_event.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(
6262
the exact time of the event. If the triggered condition function returns a real
6363
number, then the final time will be the time at which that real number equals zero.
6464
(If the triggered condition function returns a boolean, then the returned time will
65-
just be the end of the step on which it becomes `True`.)
65+
just be the end of the step on which it becomes `True`.)
6666
[`optimistix.Newton`](https://docs.kidger.site/optimistix/api/root_find/#optimistix.Newton)
6767
would be a typical choice here.
6868
@@ -74,12 +74,12 @@ def __init__(
7474
7575
!!! Example
7676
77-
Consider a bouncing ball dropped from some intial height $x_0$. We can model
77+
Consider a bouncing ball dropped from some intial height $x_0$. We can model
7878
the ball by a 2-dimensional ODE
7979
8080
$\\frac{dx_t}{dt} = v_t, \\quad \\frac{dv_t}{dt} = -g,$
8181
82-
where $x_t$ represents the height of the ball, $v_t$ its velocity,
82+
where $x_t$ represents the height of the ball, $v_t$ its velocity,
8383
and $g$ is the gravitational constant. With $g=8$, this corresponds to the
8484
vector field:
8585
@@ -89,8 +89,8 @@ def vector_field(t, y, args):
8989
return jnp.array([v, -8.0])
9090
```
9191
92-
Figuring out exactly when the ball hits the ground amounts to
93-
solving the ODE until the event $x_t=0$ is triggered. This can be done by using
92+
Figuring out exactly when the ball hits the ground amounts to
93+
solving the ODE until the event $x_t=0$ is triggered. This can be done by using
9494
the real-valued condition function:
9595
9696
```python

diffrax/_progress_meter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def __check_init__(self):
190190
)
191191

192192
@staticmethod
193-
def _init_bar() -> "tqdm.tqdm": # pyright: ignore # noqa: F821
194-
import tqdm # pyright: ignore
193+
def _init_bar() -> "tqdm.tqdm": # pyright: ignore[reportUndefinedVariable] # noqa: F821
194+
import tqdm
195195

196196
bar_format = (
197197
"{percentage:.2f}%|{bar}| [{elapsed}<{remaining}, {rate_fmt}{postfix}]"

diffrax/_root_finder/_verychord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def postprocess(
189189
190190
- `rtol`: Relative tolerance for terminating the solve.
191191
- `atol`: Absolute tolerance for terminating the solve.
192-
- `norm`: The norm used to determine the difference between two iterates in the
192+
- `norm`: The norm used to determine the difference between two iterates in the
193193
convergence criteria. Should be any function `PyTree -> Scalar`, for example
194194
`optimistix.max_norm`.
195195
- `kappa`: A tolerance for the early convergence check.

diffrax/_saveat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __check_init__(self):
5353
- `t0`: If `True`, save the initial input `y0`.
5454
- `t1`: If `True`, save the output at `t1`.
5555
- `ts`: Some array of times at which to save the output.
56-
- `steps`: If `n>0`, save the output at every `n`th step of the numerical solver.
56+
- `steps`: If `n>0`, save the output at every `n`th step of the numerical solver.
5757
`0` means no saving.
5858
- `fn`: A function `fn(t, y, args)` which specifies what to save into `sol.ys` when
5959
using `t0`, `t1`, `ts` or `steps`. Defaults to `fn(t, y, args) -> y`, so that the
@@ -110,7 +110,7 @@ def __init__(
110110
- `t0`: If `True`, save the initial input `y0`.
111111
- `t1`: If `True`, save the output at `t1`.
112112
- `ts`: Some array of times at which to save the output.
113-
- `steps`: If `n>0`, save the output at every `n`th step of the numerical solver.
113+
- `steps`: If `n>0`, save the output at every `n`th step of the numerical solver.
114114
`0` means no saving.
115115
- `dense`: If `True`, save dense output, that can later be evaluated at any part of
116116
the interval $[t_0, t_1]$ via `sol = diffeqsolve(...); sol.evaluate(...)`.

0 commit comments

Comments
 (0)