Skip to content

Commit 24f4c35

Browse files
committed
Ruff fixes + version bump
1 parent 957a786 commit 24f4c35

7 files changed

+15
-27
lines changed

Diff for: dsp/cone_transforms.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def sum_of_K_reprs(cls, reprs: list[KRepresentation]) -> KRepresentation:
4444
offset = np.sum([K.offset for K in reprs])
4545

4646
def f_concave(x: np.ndarray) -> cp.Expression:
47-
nones = any([K.concave_expr(x) is None for K in reprs])
47+
nones = any(K.concave_expr(x) is None for K in reprs)
4848
return cp.sum([K.concave_expr(x) for K in reprs]) if not nones else None
4949

5050
concave_expr = f_concave
@@ -214,7 +214,6 @@ def K_repr_ax(a: cp.Expression) -> KRepresentation:
214214

215215
class LocalToGlob:
216216
def __init__(self, x_variables: list[cp.Variable], y_variables: list[cp.Variable]) -> None:
217-
218217
self.outer_x_vars = x_variables
219218
self.var_to_glob: dict[int, tuple[int, int]] = {}
220219

@@ -296,7 +295,6 @@ def K_repr_FxGy(
296295
local_to_glob: LocalToGlob,
297296
switched: bool = False,
298297
) -> KRepresentation:
299-
300298
z = cp.Variable(Fx.shape)
301299
constraints = [z >= Fx]
302300

@@ -335,7 +333,6 @@ def K_repr_bilin(
335333
def get_cone_repr(
336334
const: list[Constraint], variables: list[cp.Variable]
337335
) -> tuple[dict[int, np.ndarray], np.ndarray, ConeDims]:
338-
339336
assert all(isinstance(v, cp.Variable) for v in variables)
340337

341338
# TODO: CVXPY does not have a stable API for getting the cone representation that is
@@ -504,7 +501,6 @@ def create_sparse_matrix_from_columns(
504501
local_to_glob: LocalToGlob,
505502
var_to_mat_mapping: dict[int, sp.csc_matrix],
506503
) -> sp.csc_matrix:
507-
508504
cols = []
509505
for v in variables:
510506
start, end = local_to_glob.var_to_glob[v.id]

Diff for: dsp/parser.py

-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def affine_error_message(affine_vars: list[cp.Variable]) -> str:
4040

4141
class Parser:
4242
def __init__(self, convex_vars: set[cp.Variable], concave_vars: set[cp.Variable]) -> None:
43-
4443
self.convex_vars: set[cp.Variable] = convex_vars
4544
self.concave_vars: set[cp.Variable] = concave_vars
4645
if self.convex_vars & self.concave_vars:
@@ -170,7 +169,6 @@ def parse_expr_variables(self, expr: cp.Expression, switched: bool, **kwargs: di
170169
def parse_expr_repr(
171170
self, expr: cp.Expression, switched: bool, local_to_glob: LocalToGlob
172171
) -> KRepresentation:
173-
174172
K_repr = self._parse_expr(expr, switched, repr_parse=True, local_to_glob=local_to_glob)
175173
assert isinstance(K_repr, KRepresentation)
176174
return K_repr
@@ -192,7 +190,6 @@ def contains_curvature_lumping(expr: cp.Expression) -> bool:
192190
def _parse_expr(
193191
self, expr: cp.Expression, switched: bool, repr_parse: bool, **kwargs: dict
194192
) -> KRepresentation | None:
195-
196193
# constant
197194
if not expr.variables():
198195
assert expr.size == 1

Diff for: dsp/problem.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def dualized_problem(
8888
minimization_vars: Iterable[cp.Variable],
8989
maximization_vars: Iterable[cp.Variable],
9090
) -> tuple[list[Constraint], Objective]:
91-
9291
parser = initialize_parser(obj_expr, minimization_vars, maximization_vars, constraints)
9392

9493
local_to_glob_y = LocalToGlob(parser.convex_vars, parser.concave_vars)
@@ -147,7 +146,7 @@ def value(self) -> float | None:
147146
def is_dsp(self) -> bool:
148147
# try to form x_prob and catch the exception
149148
try:
150-
self.x_prob
149+
self.x_prob # noqa
151150
return True
152151
except DSPError:
153152
return False
@@ -269,7 +268,7 @@ def is_dsp(obj: cp.Problem | SaddlePointProblem | cp.Expression) -> bool:
269268
return obj.is_dsp()
270269
elif isinstance(obj, cp.Problem):
271270
all_SE_atoms = get_problem_SE_atoms(obj)
272-
return obj.is_dcp() and all([atom.is_dsp() for atom in all_SE_atoms])
271+
return obj.is_dcp() and all(atom.is_dsp() for atom in all_SE_atoms)
273272
elif isinstance(obj, cp.Expression):
274273
return is_dsp_expr(obj)
275274
else:

Diff for: dsp/saddle_atoms.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def is_dsp(self) -> bool:
5959
raise NotImplementedError
6060

6161
def numeric(self, values: list[np.ndarray | None]) -> np.ndarray | None:
62-
if any([v is None for v in values]):
62+
if any(v is None for v in values):
6363
return None
6464
return self._numeric(values)
6565

@@ -101,7 +101,8 @@ def __init__(self, Fx: cp.Expression, Gy: cp.Expression) -> None:
101101
if (not self.bilinear) and (not Gy.is_nonneg()):
102102
warnings.warn(
103103
"Gy is non-positive. The y domain of saddle_inner is Gy >="
104-
" 0. The implicit constraint Gy >= 0 will be added to the problem."
104+
" 0. The implicit constraint Gy >= 0 will be added to the problem.",
105+
stacklevel=1,
105106
)
106107

107108
self.Fx = Fx
@@ -226,7 +227,8 @@ def __init__(self, exponents: cp.Expression, weights: cp.Expression) -> None:
226227
warnings.warn(
227228
"Weights are non-positive. The domain of weighted log-sum-exp is y >="
228229
" 0. The implicit constraint y >= 0 will be added to"
229-
" the problem."
230+
" the problem.",
231+
stacklevel=1,
230232
)
231233

232234
self.concave_composition = not weights.is_affine()
@@ -560,7 +562,8 @@ def __init__(self, x: cp.Expression, y: cp.Expression) -> None:
560562
warnings.warn(
561563
"Weights are non-positive. The domain of weighted_norm2 is y >="
562564
" 0. The implicit constraint y >= 0 will be added to"
563-
" the problem."
565+
" the problem.",
566+
stacklevel=1,
564567
)
565568

566569
self.concave_composition = not y.is_affine()

Diff for: dsp/saddle_extremum.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def __init__(
2020
f: cp.Expression,
2121
constraints: Iterable[cp.Constraint],
2222
) -> None:
23-
2423
self.f = f
2524
self._parser = None
2625

@@ -44,7 +43,7 @@ def _validate_arguments(self, constraints: list[cp.Constraint]) -> None:
4443
def is_dsp(self) -> bool:
4544
try:
4645
self.parser # noqa
47-
return all([c.is_dcp() for c in self.constraints])
46+
return all(c.is_dcp() for c in self.constraints)
4847
except DSPError:
4948
return False
5049

@@ -81,7 +80,6 @@ def __init__(
8180
f: cp.Expression,
8281
constraints: Iterable[cp.Constraint],
8382
) -> None:
84-
8583
super().__init__(f, constraints)
8684

8785
self._concave_vars = set(filter(lambda v: isinstance(v, dsp.LocalVariable), f.variables()))
@@ -99,7 +97,6 @@ def concave_variables(self) -> list[cp.Variable]:
9997
@property
10098
def parser(self) -> Parser:
10199
if self._parser is None:
102-
103100
parser = initialize_parser(
104101
self.f,
105102
minimization_vars=self.other_variables,
@@ -155,7 +152,6 @@ def __init__(
155152
f: cp.Expression,
156153
constraints: Iterable[cp.Constraint],
157154
) -> None:
158-
159155
super().__init__(f, constraints)
160156

161157
self._convex_vars = set(filter(lambda v: isinstance(v, dsp.LocalVariable), f.variables()))

Diff for: pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ requires = ["setuptools"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.ruff]
6-
select = ["E", "F", "I", "UP", "B", "ANN", "N", "C4"]
6+
lint.select = ["E", "F", "I", "UP", "B", "ANN", "N", "C4"]
77
line-length = 100
8-
target-version = "py37"
9-
ignore = ["N806", "ANN101", "ANN102", "N801", "N802", "N803", "ANN401"]
8+
target-version = "py38"
9+
lint.ignore = ["N806", "ANN101", "ANN102", "N801", "N802", "N803", "ANN401"]
1010
exclude = ["tests"]

Diff for: setup.cfg

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = dsp-cvxpy
3-
version = 0.1.0
3+
version = 0.1.1
44
author = Philipp Schiele, Eric Luxenberg, Stephen Boyd
55
66
url = https://github.com/cvxgrp/dsp
@@ -23,6 +23,3 @@ dev = tox
2323

2424
[options.package_data]
2525
* = README.md
26-
27-
[flake8]
28-
max-line-length = 100

0 commit comments

Comments
 (0)