Skip to content

Commit 869649b

Browse files
authored
black -> ruff (#376)
* pre-commit-sort * pre-commit: black -> ruff * pre-commit run -a * hide unused variables * noqa * remove unused import * fix import order * ruff details * add changelog entry
1 parent 249660b commit 869649b

27 files changed

+53
-68
lines changed

.pre-commit-config.yaml

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
ci:
2-
autoupdate_branch: 'devel'
3-
autofix_prs: false
4-
autoupdate_schedule: quarterly
5-
submodules: true
2+
autofix_prs: false
3+
autoupdate_branch: devel
4+
autoupdate_schedule: quarterly
5+
submodules: true
66
repos:
7-
- repo: https://github.com/pre-commit/mirrors-clang-format
8-
rev: v19.1.7
9-
hooks:
10-
- id: clang-format
11-
args: ['--style={BasedOnStyle: Mozilla, SortIncludes: false}']
12-
- repo: https://github.com/pre-commit/pre-commit-hooks
13-
rev: v5.0.0
14-
hooks:
15-
- id: trailing-whitespace
16-
- repo: https://github.com/psf/black
17-
rev: 24.10.0
18-
hooks:
19-
- id: black
20-
- repo: https://github.com/BlankSpruce/gersemi
21-
rev: 0.19.0
22-
hooks:
23-
- id: gersemi
7+
- repo: https://github.com/BlankSpruce/gersemi
8+
rev: 0.19.0
9+
hooks:
10+
- id: gersemi
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.8.6
13+
hooks:
14+
- id: ruff
15+
args:
16+
- --fix
17+
- --exit-non-zero-on-fix
18+
- id: ruff-format
19+
- repo: https://github.com/pre-commit/mirrors-clang-format
20+
rev: v19.1.7
21+
hooks:
22+
- id: clang-format
23+
args:
24+
- '--style={BasedOnStyle: Mozilla, SortIncludes: false}'
25+
- repo: https://github.com/pre-commit/pre-commit-hooks
26+
rev: v5.0.0
27+
hooks:
28+
- id: trailing-whitespace

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
### Changed
1414
* Upgrade nanobind submodule to v2.5.0 ([#378](https://github.com/Simple-Robotics/proxsuite/pull/378))
1515
* Switch to gersemi for formatting ([#380](https://github.com/Simple-Robotics/proxsuite/pull/380))
16+
* Switch to ruff for formatting / linting ([#376](https://github.com/Simple-Robotics/proxsuite/pull/376))
1617

1718
## [0.7.1] - 2025-01-28
1819

benchmark/timings-parallel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def generate_mixed_qp(n, n_eq, n_in, seed=1):
3030
q = np.random.randn(n)
3131
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc").toarray()
3232
v = np.random.randn(n) # Fictitious solution
33-
delta = np.random.rand(m) # To get inequality
33+
_delta = np.random.rand(m) # To get inequality
3434
u = A @ v
3535
l = -1.0e20 * np.ones(m)
3636

@@ -49,7 +49,6 @@ def generate_mixed_qp(n, n_eq, n_in, seed=1):
4949
num_qps = 128
5050

5151
for n, n_eq, n_in in problem_specs:
52-
5352
print(f"\nProblem specs: {n=} {n_eq=} {n_in=}. Generating {num_qps} such problems.")
5453
problems = [generate_mixed_qp(n, n_eq, n_in, seed=j) for j in range(num_qps)]
5554
print(
@@ -86,7 +85,7 @@ def generate_mixed_qp(n, n_eq, n_in, seed=1):
8685
print("Solving batch of qps using solve_in_parallel with default thread config")
8786
tic = perf_counter_ns()
8887
proxsuite.proxqp.dense.solve_in_parallel(qps=qps_batch)
89-
timings[f"solve_in_parallel_heuristics_threads"] = (perf_counter_ns() - tic) * 1e-6
88+
timings["solve_in_parallel_heuristics_threads"] = (perf_counter_ns() - tic) * 1e-6
9089

9190
print("Solving vector of qps serially")
9291
tic = perf_counter_ns()

bindings/python/proxsuite/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import platform
2-
import numpy # for OpenMP proper linkage
2+
import numpy # noqa F401 for OpenMP proper linkage
33

44
machine = platform.machine()
55
has_vectorization_instructions = not machine.startswith(
@@ -21,7 +21,7 @@ def load_module(main_module_name):
2121
except ModuleNotFoundError:
2222
return False
2323

24-
if has_vectorization_instructions:
24+
if has_vectorization_instructions: # noqa
2525
all_modules = [
2626
("proxsuite_pywrap_avx512", instructionset.has_AVX512F),
2727
("proxsuite_pywrap_avx2", instructionset.has_AVX2),
@@ -31,7 +31,7 @@ def load_module(main_module_name):
3131
if checker() and load_module(module_name):
3232
return
3333

34-
assert load_module("proxsuite_pywrap") == True
34+
assert load_module("proxsuite_pywrap")
3535

3636

3737
load_main_module(globals=globals())

bindings/python/proxsuite/torch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
try:
2-
import torch
2+
import torch # noqa F401
33
except ImportError:
44
import warnings
55

bindings/python/proxsuite/torch/qplayer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ def backward(ctx, dl_dzhat, dl_dlams, dl_dnus, dl_ds_e, dl_ds_i):
436436
if neq > 0:
437437
kkt[:dim, dim : dim + n_eq] = A_i.transpose()
438438
kkt[dim : dim + n_eq, :dim] = A_i
439-
kkt[dim + n_eq + n_in : dim + 2 * n_eq + n_in, dim : dim + n_eq] = (
440-
-np.eye(n_eq)
441-
)
439+
kkt[
440+
dim + n_eq + n_in : dim + 2 * n_eq + n_in, dim : dim + n_eq
441+
] = -np.eye(n_eq)
442442
kkt[
443443
dim + n_eq + n_in : dim + 2 * n_eq + n_in,
444444
dim + n_eq + 2 * n_in : 2 * dim + n_eq + 2 * n_in,
@@ -485,9 +485,9 @@ def backward(ctx, dl_dzhat, dl_dlams, dl_dnus, dl_ds_e, dl_ds_i):
485485
rhs[dim + n_eq : dim + n_eq + n_in_sol][~active_set] = dl_dnus[
486486
i
487487
][~active_set]
488-
rhs[dim + n_eq + n_in_sol : dim + n_eq + n_in][active_set] = (
489-
-dl_dnus[i][active_set]
490-
)
488+
rhs[dim + n_eq + n_in_sol : dim + n_eq + n_in][
489+
active_set
490+
] = -dl_dnus[i][active_set]
491491
if dl_ds_e is not None:
492492
if dl_ds_e.shape[0] != 0:
493493
rhs[dim + n_eq + n_in : dim + 2 * n_eq + n_in] = -dl_ds_e[i]

examples/python/init_dense_qp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import proxsuite
2-
import numpy as np
3-
import scipy.sparse as spa
42
from util import generate_mixed_qp
53

64

examples/python/init_dense_qp_with_box.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import proxsuite
22
import numpy as np
3-
import scipy.sparse as spa
43
from util import generate_mixed_qp
54

65

examples/python/init_dense_qp_with_other_options.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import proxsuite
2-
import numpy as np
3-
import scipy.sparse as spa
42
from util import generate_mixed_qp
53

64

examples/python/init_dense_qp_with_timings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import proxsuite
2-
import numpy as np
3-
import scipy.sparse as spa
42
from util import generate_mixed_qp
53

64

0 commit comments

Comments
 (0)