From e51351f8f8cbb869a3520b9748f009064da62a1f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 6 Apr 2024 12:26:23 +0200 Subject: [PATCH] MAINT: autoupdate pre-commit hooks (#8) * 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 Co-authored-by: Remco de Boer <29308176+redeboer@users.noreply.github.com> --- .pre-commit-config.yaml | 71 ++++++++++---------------- .vscode/extensions.json | 9 ++-- .vscode/settings.json | 17 ++++-- README.md | 1 + pyproject.toml | 88 ++++++++++++++++++++++---------- src/jax_benchmark/__init__.py | 2 +- src/jax_benchmark/dot_product.py | 4 +- src/jax_benchmark/io.py | 4 +- visualize-benchmark.ipynb | 2 +- 9 files changed, 113 insertions(+), 85 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2947b25..d410345 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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: @@ -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: @@ -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 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index c2be5e4..a147e85 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -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" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index f7260e5..2f893da 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } diff --git a/README.md b/README.md index 36a520e..fff52a7 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/pyproject.toml b/pyproject.toml index 0856cc0..9ce8125 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,7 @@ dev = [ "jax-mini-benchmark[sty]", ] jupyter = [ + "black", "isort", "jupyterlab", "jupyterlab-code-formatter", @@ -68,7 +69,6 @@ jupyter = [ "python-lsp-server[rope]", ] sty = [ - "black", "pre-commit", "ruff", ] @@ -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", @@ -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", @@ -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 diff --git a/src/jax_benchmark/__init__.py b/src/jax_benchmark/__init__.py index 95dbb41..238632a 100644 --- a/src/jax_benchmark/__init__.py +++ b/src/jax_benchmark/__init__.py @@ -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}" diff --git a/src/jax_benchmark/dot_product.py b/src/jax_benchmark/dot_product.py index 226b8f9..d16f2fd 100644 --- a/src/jax_benchmark/dot_product.py +++ b/src/jax_benchmark/dot_product.py @@ -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, ) diff --git a/src/jax_benchmark/io.py b/src/jax_benchmark/io.py index 9d6802c..8d30dcc 100644 --- a/src/jax_benchmark/io.py +++ b/src/jax_benchmark/io.py @@ -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: diff --git a/visualize-benchmark.ipynb b/visualize-benchmark.ipynb index c6d70b5..a2daf69 100644 --- a/visualize-benchmark.ipynb +++ b/visualize-benchmark.ipynb @@ -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\")" ]