Skip to content

Commit 8252ad3

Browse files
committed
Split github workflows for lower latency, add ruff
1 parent f076ae1 commit 8252ad3

7 files changed

Lines changed: 82 additions & 8 deletions

File tree

.github/workflows/tests.yml

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
build-and-test:
1313
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }} jax=${{ matrix.jax-version }}"
1414
runs-on: "${{ matrix.os }}"
15-
1615
strategy:
1716
matrix:
1817
python-version: ["3.9", "3.10", "3.11"]
@@ -22,7 +21,6 @@ jobs:
2221
- python-version: "3.9"
2322
os: "ubuntu-latest"
2423
jax-version: "0.4.27" # Keep version in sync with pyproject.toml and copy.bara.sky!
25-
2624
steps:
2725
- uses: "actions/checkout@v2"
2826
- uses: "actions/setup-python@v4"
@@ -33,13 +31,72 @@ jobs:
3331
- name: Run CI tests
3432
run: JAX_VERSION="${{ matrix.jax-version }}" bash test.sh
3533
shell: bash
34+
doctests:
35+
name: "Doctests on ${{ matrix.os }} with Python ${{ matrix.python-version }}"
36+
runs-on: "${{ matrix.os }}"
37+
strategy:
38+
matrix:
39+
python-version: ["3.11"] # only build docs with a somewhat latest python
40+
os: [ubuntu-latest]
41+
steps:
42+
- uses: "actions/checkout@v2"
43+
- uses: "actions/setup-python@v4"
44+
with:
45+
python-version: "${{ matrix.python-version }}"
46+
cache: "pip"
47+
cache-dependency-path: 'pyproject.toml'
48+
- name: Build docs and run doctests
49+
run: |
50+
python3 -m pip install --quiet --editable ".[docs]"
51+
cd docs
52+
make html
53+
make doctest # run doctests
54+
shell: bash
55+
linting:
56+
name: "Lint check with flake8 and pylint"
57+
runs-on: "ubuntu-latest"
58+
steps:
59+
- uses: "actions/checkout@v2"
60+
- uses: "actions/setup-python@v4"
61+
with:
62+
python-version: "3.11"
63+
cache: "pip"
64+
cache-dependency-path: "pyproject.toml"
65+
- name: Install linting dependencies
66+
run: |
67+
pip install -U pip setuptools wheel
68+
pip install -U flake8 pytest-xdist pylint pylint-exit
69+
- name: Lint with flake8
70+
run: |
71+
python3 -m flake8 --select=E9,F63,F7,F82,E225,E251 --show-source --statistics
72+
- name: Lint module files with pylint
73+
run: |
74+
PYLINT_ARGS="-efail -wfail -cfail -rfail"
75+
python3 -m pylint --rcfile=.pylintrc $(find optax -name '*.py' | grep -v 'test.py' | xargs) -d E1102 || pylint-exit $PYLINT_ARGS $?
76+
- name: Lint test files with pylint
77+
run: |
78+
PYLINT_ARGS="-efail -wfail -cfail -rfail"
79+
python3 -m pylint --rcfile=.pylintrc $(find optax -name '*_test.py' | xargs) -d W0212,E1102 || pylint-exit $PYLINT_ARGS $?
80+
ruff-lint:
81+
name: "Lint check with ruff"
82+
runs-on: "ubuntu-latest"
83+
steps:
84+
- uses: "actions/checkout@v2"
85+
- uses: "actions/setup-python@v4"
86+
with:
87+
python-version: "3.11"
88+
cache: "pip"
89+
cache-dependency-path: "pyproject.toml"
90+
- name: Install ruff and lint check
91+
run: |
92+
pip install -U ruff
93+
ruff check .
3694
markdown-link-check:
3795
name: "Check links in markdown files"
3896
runs-on: "ubuntu-latest"
3997
steps:
4098
- name: Checkout repository
4199
uses: actions/checkout@v4
42-
43100
- name: Check links
44101
uses: gaurav-nelson/github-action-markdown-link-check@v1
45102
with:

examples/contrib/reduce_on_plateau.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
"source": [
373373
"opt = optax.chain(\n",
374374
" optax.adam(LEARNING_RATE),\n",
375-
" reduce_on_plateau(\n",
375+
" contrib.reduce_on_plateau(\n",
376376
" patience=PATIENCE,\n",
377377
" cooldown=COOLDOWN,\n",
378378
" factor=FACTOR,\n",
@@ -759,7 +759,7 @@
759759
}
760760
],
761761
"source": [
762-
"transform = reduce_on_plateau(\n",
762+
"transform = contrib.reduce_on_plateau(\n",
763763
" patience=PATIENCE,\n",
764764
" cooldown=COOLDOWN,\n",
765765
" factor=FACTOR,\n",

examples/linear_assignment_problem.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"outputs": [],
5656
"source": [
5757
"import networkx as nx\n",
58-
"from jax import numpy as jnp, random\n",
58+
"from jax import random\n",
5959
"import optax\n",
6060
"from matplotlib import pyplot as plt"
6161
]

examples/nanolm.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@
629629
}
630630
],
631631
"source": [
632-
"plt.title(f\"Convergence of adamw (train loss)\")\n",
632+
"plt.title(\"Convergence of adamw (train loss)\")\n",
633633
"plt.plot(all_train_losses, label=\"train\", lw=3)\n",
634634
"plt.plot(\n",
635635
" jnp.arange(0, len(all_eval_losses) * N_FREQ_EVAL, N_FREQ_EVAL),\n",

optax/schedules/_inject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def _convert_floats(x, dtype):
3232
"""Convert float-like inputs to dtype, rest pass through."""
33-
if jax.dtypes.scalar_type_of(x) == float:
33+
if jax.dtypes.scalar_type_of(x) is float:
3434
return jnp.asarray(x, dtype=dtype)
3535
return x
3636

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,17 @@ dp-accounting = [
8787
[tool.setuptools.packages.find]
8888
include = ["README.md", "LICENSE"]
8989
exclude = ["*_test.py"]
90+
91+
[tool.ruff.lint]
92+
select = [
93+
"F",
94+
"E",
95+
]
96+
ignore = [
97+
"E731", # lambdas are allowed
98+
"E501", # don't check line lengths
99+
"F401", # allow unused imports
100+
"E402", # allow modules not at top of file
101+
"E741", # allow "l" as a variable name
102+
"E703", # allow semicolons (for jupyter notebooks)
103+
]

test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ make html
101101
make doctest # run doctests
102102
cd ..
103103

104+
pip install -U ruff
105+
ruff check .
106+
104107
echo "All tests passed. Congrats!"

0 commit comments

Comments
 (0)