Skip to content

Commit 1033f47

Browse files
committed
Update config, fix lints for ruff 0.15.2
1 parent a1bf1e2 commit 1033f47

23 files changed

+96
-163
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ extend-ignore = [
102102
"E226", # missing whitespace around arithmetic operator
103103
"E402", # module-level import not at top of file
104104
"RUF067", # non-empty-init-module
105+
"TRY004",
106+
"TRY300",
105107
]
106108

107109
[tool.ruff.lint.flake8-quotes]
@@ -127,6 +129,8 @@ required-imports = ["from __future__ import annotations"]
127129
[tool.ruff.lint.per-file-ignores]
128130
"doc/**/*.py" = ["I002"]
129131
"examples/**/*.py" = ["I002"]
132+
"sumpy/test/test_*.py" = ["S102"]
133+
"doc/conf.py" = ["S102"]
130134

131135
[tool.typos.default]
132136
extend-ignore-re = [

sumpy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def __init__(self, new_flag, new_no_cache_kernels=()):
114114
self.new_no_cache_kernels = new_no_cache_kernels
115115

116116
def __enter__(self):
117-
global CACHING_ENABLED, NO_CACHE_KERNELS
118117
self.previous_flag = CACHING_ENABLED
119118
self.previous_kernels = NO_CACHE_KERNELS
120119
set_caching_enabled(self.new_flag, self.new_no_cache_kernels)

sumpy/codegen.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@
4444

4545

4646
if TYPE_CHECKING:
47-
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence, Set
47+
from collections.abc import (
48+
Callable,
49+
Iterable,
50+
Iterator,
51+
Mapping,
52+
Sequence,
53+
Set as AbstractSet,
54+
)
4855

4956
from numpy.typing import DTypeLike
5057

@@ -730,10 +737,10 @@ def map_common_subexpression_uncached(
730737

731738
def to_loopy_insns(
732739
assignments: Iterable[tuple[str, sym.Expr]],
733-
vector_names: Set[str] | None = None,
740+
vector_names: AbstractSet[str] | None = None,
734741
pymbolic_expr_maps: Sequence[Callable[[Expression], Expression]] = (),
735742
complex_dtype: DTypeLike | None = None,
736-
retain_names: Set[str] | None = None,
743+
retain_names: AbstractSet[str] | None = None,
737744
) -> Sequence[Assignment | CallInstruction]:
738745
if vector_names is None:
739746
vector_names = frozenset()
@@ -771,8 +778,7 @@ def cmb_mapper(expr: Expression, /) -> Expression:
771778
expr = ssg(expr)
772779
expr = bik(expr)
773780
expr = cmr(expr)
774-
expr = btog(expr)
775-
return expr
781+
return btog(expr)
776782

777783
def convert_expr(name: str, expr: Expression) -> Expression:
778784
logger.debug("generate expression for: %s", name)

sumpy/distributed.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from boxtree.distributed.calculation import DistributedExpansionWranglerMixin
2929

30-
import pytools.obj_array as obj_array
30+
from pytools import obj_array
3131

3232
from sumpy.fmm import SumpyExpansionWrangler
3333

@@ -61,23 +61,20 @@ def distribute_source_weights(self,
6161
local_src_weight_vecs_host = super().distribute_source_weights(
6262
actx, src_weight_vecs_host, src_idx_all_ranks)
6363

64-
local_src_weight_vecs_device = [
64+
return [
6565
actx.from_numpy(local_src_weight)
6666
for local_src_weight in local_src_weight_vecs_host]
6767

68-
return local_src_weight_vecs_device
69-
7068
def gather_potential_results(self,
7169
actx: ArrayContext, potentials, tgt_idx_all_ranks):
7270
potentials_host_vec = [
7371
actx.to_numpy(potentials_dev) for potentials_dev in potentials
7472
]
7573

76-
gathered_potentials_host_vec = []
77-
for potentials_host in potentials_host_vec:
78-
gathered_potentials_host_vec.append(
79-
super().gather_potential_results(
80-
actx, potentials_host, tgt_idx_all_ranks))
74+
gathered_potentials_host_vec = [
75+
super().gather_potential_results(
76+
actx, potentials_host, tgt_idx_all_ranks)
77+
for potentials_host in potentials_host_vec]
8178

8279
if self.is_mpi_root:
8380
return obj_array.new_1d([

sumpy/e2e.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ def get_cache_key(self):
135135
return (type(self).__name__, self.src_expansion, self.tgt_expansion)
136136

137137
@abstractmethod
138-
def get_kernel(self):
138+
@override
139+
def get_kernel(self) -> lp.TranslationUnit:
139140
pass
140141

141142
def get_optimized_kernel(self):
142143
# FIXME
143144
knl = self.get_kernel()
144-
knl = lp.split_iname(knl, "itgt_box", 64, outer_tag="g.0", inner_tag="l.0")
145+
return lp.split_iname(knl, "itgt_box", 64, outer_tag="g.0", inner_tag="l.0")
145146

146-
return knl
147147

148148
# }}}
149149

@@ -259,18 +259,14 @@ def get_kernel(self):
259259
loopy_knl = knl.prepare_loopy_kernel(loopy_knl)
260260

261261
loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr")
262-
loopy_knl = lp.set_options(loopy_knl,
262+
return lp.set_options(loopy_knl,
263263
enforce_variable_access_ordered="no_check")
264264

265-
return loopy_knl
266-
267265
@override
268266
def get_optimized_kernel(self):
269267
# FIXME
270268
knl = self.get_kernel()
271-
knl = lp.split_iname(knl, "itgt_box", 64, outer_tag="g.0", inner_tag="l.0")
272-
273-
return knl
269+
return lp.split_iname(knl, "itgt_box", 64, outer_tag="g.0", inner_tag="l.0")
274270

275271
def __call__(self, actx: ArrayContext, **kwargs):
276272
"""
@@ -511,11 +507,9 @@ def get_kernel(self, result_dtype):
511507

512508
def get_optimized_kernel(self, result_dtype):
513509
knl = self.get_kernel(result_dtype)
514-
knl = self.tgt_expansion.m2l_translation.optimize_loopy_kernel(
510+
return self.tgt_expansion.m2l_translation.optimize_loopy_kernel(
515511
knl, self.tgt_expansion, self.src_expansion)
516512

517-
return knl
518-
519513
def __call__(self, actx: ArrayContext, **kwargs):
520514
"""
521515
:arg src_expansions:
@@ -612,22 +606,18 @@ def get_kernel(self, result_dtype):
612606

613607
loopy_knl = lp.merge([loopy_knl, translation_classes_data_knl])
614608
loopy_knl = lp.inline_callable_kernel(loopy_knl, "m2l_data")
615-
loopy_knl = lp.set_options(loopy_knl,
609+
return lp.set_options(loopy_knl,
616610
enforce_variable_access_ordered="no_check",
617611
# FIXME: Without this, Loopy spends an eternity checking
618612
# scattered writes to global variables to see whether barriers
619613
# need to be inserted.
620614
disable_global_barriers=True)
621615

622-
return loopy_knl
623-
624616
def get_optimized_kernel(self, result_dtype):
625617
# FIXME
626618
knl = self.get_kernel(result_dtype)
627619
knl = lp.tag_inames(knl, "idim*:unr")
628-
knl = lp.tag_inames(knl, {"itr_class": "g.0"})
629-
630-
return knl
620+
return lp.tag_inames(knl, {"itr_class": "g.0"})
631621

632622
def __call__(self, actx: ArrayContext, **kwargs):
633623
"""
@@ -722,9 +712,7 @@ def get_kernel(self, result_dtype):
722712
loopy_knl = expn.prepare_loopy_kernel(loopy_knl)
723713

724714
loopy_knl = lp.merge([loopy_knl, single_box_preprocess_knl])
725-
loopy_knl = lp.inline_callable_kernel(loopy_knl, "m2l_preprocess_inner")
726-
727-
return loopy_knl
715+
return lp.inline_callable_kernel(loopy_knl, "m2l_preprocess_inner")
728716

729717
def get_optimized_kernel(self, result_dtype):
730718
knl = self.get_kernel(result_dtype)
@@ -822,18 +810,16 @@ def get_kernel(self, result_dtype):
822810
loopy_knl = lp.merge([loopy_knl, single_box_postprocess_knl])
823811
loopy_knl = lp.inline_callable_kernel(loopy_knl, "m2l_postprocess_inner")
824812

825-
loopy_knl = lp.set_options(loopy_knl,
813+
return lp.set_options(loopy_knl,
826814
enforce_variable_access_ordered="no_check")
827-
return loopy_knl
828815

829816
def get_optimized_kernel(self, result_dtype):
830817
knl = self.get_kernel(result_dtype)
831818
knl = lp.tag_inames(knl, "itgt_box:g.0")
832819
_, optimizations = self.get_inner_knl_and_optimizations(result_dtype)
833820
for optimization in optimizations:
834821
knl = optimization(knl)
835-
knl = lp.add_inames_for_unused_hw_axes(knl)
836-
return knl
822+
return lp.add_inames_for_unused_hw_axes(knl)
837823

838824
def __call__(self, actx: ArrayContext, **kwargs):
839825
"""
@@ -943,11 +929,9 @@ def get_kernel(self):
943929
loopy_knl = knl.prepare_loopy_kernel(loopy_knl)
944930

945931
loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr")
946-
loopy_knl = lp.set_options(loopy_knl,
932+
return lp.set_options(loopy_knl,
947933
enforce_variable_access_ordered="no_check")
948934

949-
return loopy_knl
950-
951935
def __call__(self, actx: ArrayContext, **kwargs):
952936
"""
953937
:arg src_expansions:
@@ -1050,11 +1034,9 @@ def get_kernel(self):
10501034
loopy_knl = knl.prepare_loopy_kernel(loopy_knl)
10511035

10521036
loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr")
1053-
loopy_knl = lp.set_options(loopy_knl,
1037+
return lp.set_options(loopy_knl,
10541038
enforce_variable_access_ordered="no_check")
10551039

1056-
return loopy_knl
1057-
10581040
def __call__(self, actx: ArrayContext, **kwargs):
10591041
"""
10601042
:arg src_expansions:

sumpy/e2p.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import numpy as np
3030

3131
import loopy as lp
32-
import pytools.obj_array as obj_array
3332
from loopy.version import MOST_RECENT_LANGUAGE_VERSION # noqa: F401
33+
from pytools import obj_array
3434

3535
from sumpy.array_context import make_loopy_program
3636
from sumpy.tools import KernelCacheMixin, gather_loopy_arguments
@@ -101,8 +101,7 @@ def add_loopy_eval_callable(
101101
loopy_knl = lp.remove_unused_inames(loopy_knl)
102102
for kernel in self.kernels:
103103
loopy_knl = kernel.prepare_loopy_kernel(loopy_knl)
104-
loopy_knl = lp.tag_array_axes(loopy_knl, "targets", "sep,C")
105-
return loopy_knl
104+
return lp.tag_array_axes(loopy_knl, "targets", "sep,C")
106105

107106
def get_loopy_args(self):
108107
return gather_loopy_arguments((self.expansion, *tuple(self.kernels)))
@@ -194,20 +193,16 @@ def get_kernel(self):
194193

195194
loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr")
196195
loopy_knl = lp.tag_inames(loopy_knl, "iknl*:unr")
197-
loopy_knl = self.add_loopy_eval_callable(loopy_knl)
198-
199-
return loopy_knl
196+
return self.add_loopy_eval_callable(loopy_knl)
200197

201198
def get_optimized_kernel(self):
202199
# FIXME
203200
knl = self.get_kernel()
204201
knl = lp.tag_inames(knl, {"itgt_box": "g.0"})
205202
knl = lp.add_inames_to_insn(knl, "itgt_box", "id:kernel_scaling")
206-
knl = lp.set_options(knl,
203+
return lp.set_options(knl,
207204
enforce_variable_access_ordered="no_check")
208205

209-
return knl
210-
211206
def __call__(self, actx: ArrayContext, **kwargs):
212207
"""
213208
:arg expansions:
@@ -322,20 +317,16 @@ def get_kernel(self):
322317
loopy_knl = lp.tag_inames(loopy_knl, "iknl*:unr")
323318
loopy_knl = lp.prioritize_loops(loopy_knl, "itgt_box,itgt,isrc_box")
324319
loopy_knl = self.add_loopy_eval_callable(loopy_knl)
325-
loopy_knl = lp.tag_array_axes(loopy_knl, "targets", "sep,C")
326-
327-
return loopy_knl
320+
return lp.tag_array_axes(loopy_knl, "targets", "sep,C")
328321

329322
def get_optimized_kernel(self):
330323
# FIXME
331324
knl = self.get_kernel()
332325
knl = lp.tag_inames(knl, {"itgt_box": "g.0"})
333326
knl = lp.add_inames_to_insn(knl, "itgt_box", "id:kernel_scaling")
334-
knl = lp.set_options(knl,
327+
return lp.set_options(knl,
335328
enforce_variable_access_ordered="no_check")
336329

337-
return knl
338-
339330
def __call__(self, actx: ArrayContext, **kwargs):
340331
centers = kwargs.pop("centers")
341332
# "1" may be passed for rscale, which won't have its type

sumpy/expansion/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ def _get_mi_hyperplanes(self) -> list[tuple[int, int]]:
333333
axis `d`.
334334
"""
335335
d = self.dim - 1
336-
hyperplanes = [(d, const) for const in range(self.order + 1)]
337-
return hyperplanes
336+
return [(d, const) for const in range(self.order + 1)]
338337

339338
@memoize_method
340339
def _split_coeffs_into_hyperplanes(
@@ -648,8 +647,7 @@ def mi_key(ident: MultiIndex | DerivativeIdentifier) -> tuple[int, ...]:
648647
mi = ident
649648
key = [sum(mi)]
650649

651-
for i in range(dim):
652-
key.append(mi[axis_permutation[i]])
650+
key.extend(mi[axis_permutation[i]] for i in range(dim))
653651

654652
return tuple(key)
655653

0 commit comments

Comments
 (0)