Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

black -> ruff #376

Draft
wants to merge 7 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
ci:
autoupdate_branch: 'devel'
autofix_prs: false
autoupdate_schedule: quarterly
autofix_prs: false
autoupdate_branch: devel
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
args: ['--style={BasedOnStyle: Mozilla, SortIncludes: false}']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
args:
- '--style={BasedOnStyle: Mozilla, SortIncludes: false}'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
5 changes: 2 additions & 3 deletions benchmark/timings-parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generate_mixed_qp(n, n_eq, n_in, seed=1):
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc").toarray()
v = np.random.randn(n) # Fictitious solution
delta = np.random.rand(m) # To get inequality
_delta = np.random.rand(m) # To get inequality
u = A @ v
l = -1.0e20 * np.ones(m)

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

for n, n_eq, n_in in problem_specs:

print(f"\nProblem specs: {n=} {n_eq=} {n_in=}. Generating {num_qps} such problems.")
problems = [generate_mixed_qp(n, n_eq, n_in, seed=j) for j in range(num_qps)]
print(
Expand Down Expand Up @@ -86,7 +85,7 @@ def generate_mixed_qp(n, n_eq, n_in, seed=1):
print("Solving batch of qps using solve_in_parallel with default thread config")
tic = perf_counter_ns()
proxsuite.proxqp.dense.solve_in_parallel(qps=qps_batch)
timings[f"solve_in_parallel_heuristics_threads"] = (perf_counter_ns() - tic) * 1e-6
timings["solve_in_parallel_heuristics_threads"] = (perf_counter_ns() - tic) * 1e-6

print("Solving vector of qps serially")
tic = perf_counter_ns()
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/proxsuite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import platform
import numpy # for OpenMP proper linkage
import numpy # noqa F401 for OpenMP proper linkage

machine = platform.machine()
has_vectorization_instructions = not machine.startswith(
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/proxsuite/torch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try:
import torch
import torch # noqa F401
except ImportError:
import warnings

Expand Down
12 changes: 6 additions & 6 deletions bindings/python/proxsuite/torch/qplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ def backward(ctx, dl_dzhat, dl_dlams, dl_dnus, dl_ds_e, dl_ds_i):
if neq > 0:
kkt[:dim, dim : dim + n_eq] = A_i.transpose()
kkt[dim : dim + n_eq, :dim] = A_i
kkt[dim + n_eq + n_in : dim + 2 * n_eq + n_in, dim : dim + n_eq] = (
-np.eye(n_eq)
)
kkt[
dim + n_eq + n_in : dim + 2 * n_eq + n_in, dim : dim + n_eq
] = -np.eye(n_eq)
kkt[
dim + n_eq + n_in : dim + 2 * n_eq + n_in,
dim + n_eq + 2 * n_in : 2 * dim + n_eq + 2 * n_in,
Expand Down Expand Up @@ -486,9 +486,9 @@ def backward(ctx, dl_dzhat, dl_dlams, dl_dnus, dl_ds_e, dl_ds_i):
rhs[dim + n_eq : dim + n_eq + n_in_sol][~active_set] = dl_dnus[
i
][~active_set]
rhs[dim + n_eq + n_in_sol : dim + n_eq + n_in][active_set] = (
-dl_dnus[i][active_set]
)
rhs[dim + n_eq + n_in_sol : dim + n_eq + n_in][
active_set
] = -dl_dnus[i][active_set]
if dl_ds_e != None:
if dl_ds_e.shape[0] != 0:
rhs[dim + n_eq + n_in : dim + 2 * n_eq + n_in] = -dl_ds_e[i]
Expand Down
2 changes: 0 additions & 2 deletions examples/python/init_dense_qp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
1 change: 0 additions & 1 deletion examples/python/init_dense_qp_with_box.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
2 changes: 0 additions & 2 deletions examples/python/init_dense_qp_with_other_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
2 changes: 0 additions & 2 deletions examples/python/init_dense_qp_with_timings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
2 changes: 0 additions & 2 deletions examples/python/init_with_default_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
4 changes: 1 addition & 3 deletions examples/python/loading_sparse_qp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import proxsuite
from util import generate_mixed_qp

# load a qp object using qp problem dimensions
n = 10
n_eq = 2
n_in = 2
qp = proxsuite.proxqp.sparse.QP(n, n_eq, n_in)

import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


# load a qp2 object using matrix masks
Expand Down
2 changes: 0 additions & 2 deletions examples/python/overview-simple.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
2 changes: 0 additions & 2 deletions examples/python/qplayer_sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import time
import argparse
import numpy as np
import scipy.sparse as spa

try:
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
from torch.nn.parameter import Parameter

import cvxpy as cp
Expand Down
1 change: 0 additions & 1 deletion examples/python/solve_dense_qp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
2 changes: 0 additions & 2 deletions examples/python/solve_dense_qp_with_setting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
1 change: 0 additions & 1 deletion examples/python/solve_without_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
2 changes: 0 additions & 2 deletions examples/python/solve_without_api_and_option.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import proxsuite
import numpy as np
import scipy.sparse as spa
from util import generate_mixed_qp


Expand Down
1 change: 0 additions & 1 deletion examples/python/update_dense_qp_ws_previous_result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import proxsuite
import numpy as np
from util import generate_mixed_qp


Expand Down
1 change: 0 additions & 1 deletion examples/python/update_sparse_qp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import proxsuite
import numpy as np
from util import generate_mixed_qp


Expand Down
2 changes: 1 addition & 1 deletion examples/python/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def generate_mixed_qp(n, sparse=False, seed=1, reg=1e-2, dens1=0.075):
A = A.toarray()
P = P.toarray()
v = np.random.randn(n) # Fictitious solution
delta = np.random.rand(m) # To get inequality
_delta = np.random.rand(m) # To get inequality
u = A @ v
l = -1.0e20 * np.ones(m)

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ requires = [
]
build-backend = "cmeel.build"
configure-args = ["-DBUILD_TESTING:BOOL=OFF","-DBUILD_PYTHON_INTERFACE:BOOL=ON","-DBUILD_WITH_VECTORIZATION_SUPPORT:BOOL=ON","-DINSTALL_DOCUMENTATION:BOOL=OFF","-DBUILD_WITH_OPENMP_SUPPORT=OFF"]

[tool.ruff.lint]
ignore = [ "E741" ]
exclude = [ "cmake-module/*", "bindings/python/external/nanobind/*" ]
4 changes: 2 additions & 2 deletions test/src/dense_qp_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ def test_initializing_with_None(self):
A = None
b = None
C = None
u = None
l = None
_u = None
_l = None

results = proxsuite.proxqp.dense.solve(
H,
Expand Down
2 changes: 1 addition & 1 deletion test/src/dense_qp_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def generate_mixed_qp(n, seed=1, reg=0.01):
order="C"
)
v = np.random.randn(n) # Fictitious solution
delta = np.random.rand(m) # To get inequality
_delta = np.random.rand(m) # To get inequality
u = A @ v
l = -1.0e20 * np.ones(m)

Expand Down
6 changes: 3 additions & 3 deletions test/src/parallel_qp_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def generate_mixed_qp(n, seed=1):
order="C"
)
v = np.random.randn(n) # Fictitious solution
delta = np.random.rand(m) # To get inequality
_delta = np.random.rand(m) # To get inequality
u = A @ v
l = -1.0e20 * np.ones(m)

Expand Down Expand Up @@ -162,8 +162,8 @@ def test_sparse_parallel_custom_BatchQP(self):

for i in range(batch_size):
H, g, A, b, C, u, l = generate_mixed_qp(n, seed=i)
n_eq = A.shape[0]
n_in = C.shape[0]
_n_eq = A.shape[0]
_n_in = C.shape[0]

H_ = H != 0.0
A_ = A != 0.0
Expand Down
2 changes: 1 addition & 1 deletion test/src/sparse_qp_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def generate_mixed_qp(n, seed=1):
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc")
v = np.random.randn(n) # Fictitious solution
delta = np.random.rand(m) # To get inequality
_delta = np.random.rand(m) # To get inequality
u = A @ v
l = -1.0e20 * np.ones(m)

Expand Down
2 changes: 1 addition & 1 deletion test/src/sparse_qp_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def generate_mixed_qp(n, seed=1, reg=0.01):
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc")
v = np.random.randn(n) # Fictitious solution
delta = np.random.rand(m) # To get inequality
_delta = np.random.rand(m) # To get inequality
u = A @ v
l = -1.0e20 * np.ones(m)

Expand Down
Loading