Skip to content

Commit

Permalink
MAINT: autoupdate pre-commit hooks (#8)
Browse files Browse the repository at this point in the history
* DX: enforce Ruff
* DX: pin CI workflow
* MAINT: address linting issues

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: GitHub <[email protected]>
Co-authored-by: Remco de Boer <[email protected]>
  • Loading branch information
3 people authored Apr 6, 2024
1 parent 59b3568 commit e51351f
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 85 deletions.
71 changes: 26 additions & 45 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/ComPWA/policy
rev: 0.2.2
rev: 0.3.4
hooks:
- id: colab-toc-visible
- id: check-dev-files
Expand All @@ -22,9 +22,17 @@ repos:
- --no-gitpod
- --no-prettierrc
- --no-pypi
- --no-ruff
- --repo-name=jax-mini-benchmark

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
hooks:
- id: ruff
args: [--fix]
types_or: [python, pyi, jupyter]
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -39,54 +47,11 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
hooks:
- id: black
- id: black-jupyter
args: [--line-length=85]
types_or: [jupyter]

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
hooks:
- id: editorconfig-checker
name: editorconfig
alias: ec
exclude: >-
(?x)^(
.*\.py
)$
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/ComPWA/mirrors-pyright
rev: v1.1.345
hooks:
- id: pyright

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args:
- --py37-plus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: ruff
args:
- --fix

- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.1
hooks:
Expand All @@ -98,3 +63,19 @@ repos:
- id: toml-sort
args:
- --in-place

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
hooks:
- id: editorconfig-checker
name: editorconfig
alias: ec
exclude: >-
(?x)^(
.*\.py
)$
- repo: https://github.com/ComPWA/mirrors-pyright
rev: v1.1.357
hooks:
- id: pyright
9 changes: 5 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"recommendations": [
"charliermarsh.ruff",
"eamodio.gitlens",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"github.vscode-pull-request-github",
"ms-python.black-formatter",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"Soulcode.vscode-unwanted-extensions",
"soulcode.vscode-unwanted-extensions",
"stkb.rewrap",
"tamasfe.even-better-toml",
"tyriar.sort-lines",
"yzhang.markdown-all-in-one"
],
"unwantedRecommendations": [
"bungcip.better-toml",
"davidanson.vscode-markdownlint",
"garaioag.garaio-vscode-unwanted-recommendations",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"ms-python.mypy-type-checker",
"ms-python.pylint",
"streetsidesoftware.code-spell-checker",
"travisillig.vscode-json-stable-stringify"
"travisillig.vscode-json-stable-stringify",
"tyriar.sort-lines"
]
}
17 changes: 14 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@
"editor.rulers": [72],
"rewrap.wrappingColumn": 72
},
"[json]": {
"editor.wordWrap": "on"
},
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.rulers": [88]
},
"black-formatter.importStrategy": "fromEnvironment",
"diffEditor.experimental.showMoves": true,
"editor.formatOnSave": true,
"github-actions.workflows.pinned.workflows": [".github/workflows/ci.yml"],
"gitlens.telemetry.enabled": false,
"multiDiffEditor.experimental.enabled": true,
"notebook.codeActionsOnSave": {
"notebook.source.organizeImports": "explicit"
},
"notebook.formatOnSave.enabled": true,
"python.analysis.typeCheckingMode": "strict",
"redhat.telemetry.enabled": false,
"rewrap.wrappingColumn": 88,
"ruff.enable": true,
"ruff.importStrategy": "fromEnvironment"
"ruff.importStrategy": "fromEnvironment",
"ruff.organizeImports": true,
"telemetry.telemetryLevel": "off"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Mini benchmark for JAX

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

This package provides a set of benchmark scripts that can be used to profile JAX performance on a varying number of CPU cores. JAX does not provide control over the number of cores it uses, so a common trick is to work do this with [`taskset`](https://man7.org/linux/man-pages/man1/taskset.1.html).
Expand Down
88 changes: 60 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dev = [
"jax-mini-benchmark[sty]",
]
jupyter = [
"black",
"isort",
"jupyterlab",
"jupyterlab-code-formatter",
Expand All @@ -68,7 +69,6 @@ jupyter = [
"python-lsp-server[rope]",
]
sty = [
"black",
"pre-commit",
"ruff",
]
Expand All @@ -95,30 +95,6 @@ where = ["src"]
[tool.setuptools_scm]
write_to = "src/jax_benchmark/_version.py"

[tool.black]
exclude = '''
/(
.*\.egg-info
| .*build
| \.eggs
| \.git
| \.pytest_cache
| \.tox
| \.venv
| \.vscode
| dist
)/
'''
include = '\.pyi?$'
preview = true
target-version = [
"py310",
"py311",
"py37",
"py38",
"py39",
]

[tool.pyright]
exclude = [
"**/*.egg-info",
Expand All @@ -141,12 +117,24 @@ reportUnknownVariableType = false
typeCheckingMode = "strict"

[tool.ruff]
extend-include = ["*.ipynb"]
preview = true
show-fixes = true
src = ["src"]
target-version = "py37"

[tool.ruff.format]
docstring-code-format = true
line-ending = "lf"

[tool.ruff.lint]
extend-select = [
"A",
"B",
"BLE",
"C4",
"C90",
"D",
"EM",
"ERA",
"FA",
Expand All @@ -163,18 +151,62 @@ extend-select = [
"RET",
"RSE",
"RUF",
"S",
"SIM",
"T20",
"TCH",
"TID",
"TRY",
"UP",
"YTT",
]
show-fixes = true
src = ["src"]
target-version = "py37"
ignore = [
"D100",
"D101",
"D102",
"D103",
"D104",
"D105",
"D107",
"D203",
"D213",
"D407",
"D416",
"E501",
"ISC001",
"PLC0415",
"PLW1514",
"S404",
"S602",
"SIM108",
"T201",
]
task-tags = ["cspell"]

[tool.ruff.lint.isort]
split-on-trailing-comma = false

[tool.ruff.lint.per-file-ignores]
"*.ipynb" = [
"B018",
"C90",
"D",
"E703",
"N806",
"N816",
"PLR09",
"PLR2004",
"PLW0602",
"PLW0603",
"S101",
"T20",
"TCH00",
]
"visualize-benchmark.ipynb" = ["S301", "S403"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.tomlsort]
all = false
ignore_case = true
Expand Down
2 changes: 1 addition & 1 deletion src/jax_benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def run_single_benchmark(
shape_str = "x".join(map(str, shape))
filename.parent.mkdir(exist_ok=True, parents=True)
subprocess.call(
f"taskset -c 0-{n_cpus-1}"
f"taskset -c 0-{n_cpus - 1}"
" benchmark-jax-dot-product"
f" --output={filename}"
f" --number={number}"
Expand Down
4 changes: 3 additions & 1 deletion src/jax_benchmark/dot_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def main() -> int:
args = parser.parse_args()
mute_warnings()
benchmarks = run_benchmark(
shape=tuple(int(i) for i in args.shape.split("x")),
shape=tuple( # pyright:ignore[reportArgumentType]
int(i) for i in args.shape.split("x")
),
repeat=args.repeat,
number=args.number,
)
Expand Down
4 changes: 2 additions & 2 deletions src/jax_benchmark/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@


def enable_x64() -> None:
from jax.config import config # pyright: ignore[reportPrivateImportUsage]
import jax

config.update("jax_enable_x64", True)
jax.config.update("jax_enable_x64", True)


def get_machine_info() -> dict:
Expand Down
2 changes: 1 addition & 1 deletion visualize-benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"\n",
"\n",
"benchmarks: dict[int | str, TimeitResult] = {}\n",
"benchmarks[\"all\"] = load_benchmark(f\"timing_all.pickle\")\n",
"benchmarks[\"all\"] = load_benchmark(\"timing_all.pickle\")\n",
"for i in range(12):\n",
" benchmarks[i] = load_benchmark(f\"timing_c0-{i}.pickle\")"
]
Expand Down

0 comments on commit e51351f

Please sign in to comment.