Skip to content

Commit

Permalink
fix new ruff UP031 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Aug 16, 2024
1 parent 7217a90 commit 166c40f
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions boxtree/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def make_bounding_box_dtype(device, dimensions, coord_dtype):
fields.append((f"max_{AXIS_NAMES[i]}", coord_dtype))

dtype = np.dtype(fields)

name = "boxtree_bbox_%dd_%s_t" % (dimensions, get_type_moniker(coord_dtype))
type_moniker = get_type_moniker(coord_dtype)
name = f"boxtree_bbox_{dimensions}d_{type_moniker}_t"

from pyopencl.tools import get_or_register_dtype, match_dtype_to_c_struct
dtype, c_decl = match_dtype_to_c_struct(device, name, dtype)
Expand Down
8 changes: 4 additions & 4 deletions boxtree/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def make_pde_aware_translation_cost_model(dim, nlevels):
For example, this factory is used for complex Taylor and Fourier-Bessel
expansions in 2D, and spherical harmonics (with point-and-shoot) in 3D.
"""
p_fmm = np.array([var("p_fmm_lev%d" % i) for i in range(nlevels)])
p_fmm = np.array([var(f"p_fmm_lev{i}") for i in range(nlevels)])
ncoeffs_fmm = (p_fmm + 1) ** (dim - 1)

uses_point_and_shoot = dim == 3
Expand All @@ -165,7 +165,7 @@ def make_taylor_translation_cost_model(dim, nlevels):
"""Create a cost model for FMM translation based on Taylor expansions
in Cartesian coordinates.
"""
p_fmm = np.array([var("p_fmm_lev%d" % i) for i in range(nlevels)])
p_fmm = np.array([var(f"p_fmm_lev{i}") for i in range(nlevels)])
ncoeffs_fmm = (p_fmm + 1) ** dim

return FMMTranslationCostModel(
Expand Down Expand Up @@ -507,7 +507,7 @@ def cost_per_box(self, queue, traversal, level_to_order,
result = self.zero_cost_per_box(queue, nboxes)

for ilevel in range(tree.nlevels):
calibration_params["p_fmm_lev%d" % ilevel] = level_to_order[ilevel]
calibration_params[f"p_fmm_lev{ilevel}"] = level_to_order[ilevel]

xlat_cost = self.translation_cost_model_factory(
tree.dimensions, tree.nlevels
Expand Down Expand Up @@ -586,7 +586,7 @@ def cost_per_stage(self, queue, traversal, level_to_order,
result = {}

for ilevel in range(tree.nlevels):
calibration_params["p_fmm_lev%d" % ilevel] = level_to_order[ilevel]
calibration_params[f"p_fmm_lev{ilevel}"] = level_to_order[ilevel]

xlat_cost = self.translation_cost_model_factory(
tree.dimensions, tree.nlevels
Expand Down
5 changes: 2 additions & 3 deletions boxtree/pyfmmlib_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,9 +1148,8 @@ def finalize_potentials(self, potential, template_ary):
scale_factor = 1/(4*np.pi)
else:
raise NotImplementedError(
"scale factor for pyfmmlib %s for %d dimensions" % (
self.tree_indep.eqn_letter,
self.dim))
f"scale factor for pyfmmlib {self.tree_indep.eqn_letter} "
f"for {self.dim} dimensions")

if self.tree_indep.eqn_letter == "l" and self.dim == 2:
potential = potential.real
Expand Down
2 changes: 1 addition & 1 deletion boxtree/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def _to_host_device_array(attr):
# {{{ type mangling

def get_type_moniker(dtype):
return "%s%d" % (dtype.kind, dtype.itemsize)
return f"{dtype.kind}{dtype.itemsize}"

# }}}

Expand Down
2 changes: 1 addition & 1 deletion boxtree/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ def extract_level_start_box_nrs(box_list, wait_for):
target_boxes_sep_smaller_by_source_level = []

for ilevel in range(tree.nlevels):
fin_debug("finding separated smaller ('list 3 level %d')" % ilevel)
fin_debug(f"finding separated smaller ('list 3 level {ilevel}')")

result, evt = knl_info.from_sep_smaller_builder(
*from_sep_smaller_base_args, ilevel,
Expand Down
2 changes: 1 addition & 1 deletion boxtree/tree_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ def my_realloc_zeros_nocopy(ary, shape=nboxes_guess):
has_mismatch = True

assert not has_mismatch
print("LEVEL %d OK" % level)
print(f"LEVEL {level} OK")

# Cannot delete in Py 2.7: referred to from nested scope.
h_box_srcntgt_counts_cumul = None
Expand Down
8 changes: 4 additions & 4 deletions boxtree/tree_build_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def make_morton_bin_count_type(device, dimensions, particle_id_dtype,
if srcntgts_have_extent:
name_suffix = "_ext"

name = "boxtree_morton_bin_count_%dd_p%s%s_t" % (
dimensions,
get_type_moniker(particle_id_dtype),
name_suffix)
type_moniker = get_type_moniker(particle_id_dtype)
name = (
f"boxtree_morton_bin_count_{dimensions}d_p{type_moniker}{name_suffix}_t"
)

from pyopencl.tools import get_or_register_dtype, match_dtype_to_c_struct
dtype, c_decl = match_dtype_to_c_struct(device, name, dtype)
Expand Down
24 changes: 13 additions & 11 deletions boxtree/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def int_to_roman(inp):
if inp == 0:
return "Z"
if not 0 < inp < 4000:
raise ValueError("Argument must be between 1 and 3999 (got %d)" % inp)
raise ValueError(f"Argument must be between 1 and 3999 (got {inp})")
ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
nums = ("M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I")
result = ""
Expand Down Expand Up @@ -130,26 +130,28 @@ def get_tikz_for_tree(self):

lines = []

lines.append(r"\def\nboxes{%d}" % self.tree.nboxes)
lines.append(r"\def\lastboxnr{%d}" % (self.tree.nboxes-1))
lines.append(r"\def\nboxes{%d}" % self.tree.nboxes) # noqa: UP031
lines.append(r"\def\lastboxnr{%d}" % (self.tree.nboxes-1)) # noqa: UP031
for ibox in range(self.tree.nboxes):
el, eh = self.tree.get_box_extent(ibox)
el_0, el_1 = float(el[0]), float(el[1])
eh_0, eh_1 = float(eh[0]), float(eh[1])

c = self.tree.box_centers[:, ibox]
c_0, c_1 = float(c[0]), float(c[1])

lines.append(
r"\coordinate (boxl%d) at (%r, %r);"
% (ibox, float(el[0]), float(el[1])))
fr"\coordinate (boxl{ibox}) at ({el_0!r}, {el_1!r});")
lines.append(
r"\coordinate (boxh%d) at (%r, %r);"
% (ibox, float(eh[0]), float(eh[1])))
fr"\coordinate (boxh{ibox}) at ({eh_0!r}, {eh_1!r});")
lines.append(
r"\coordinate (boxc%d) at (%r, %r);"
% (ibox, float(c[0]), float(c[1])))
fr"\coordinate (boxc{ibox}) at ({c_0!r}, {c_1!r});")
lines.append(
rf"\def\boxsize{int_to_roman(ibox)}{{{float(eh[0]-el[0])!r}}}")
r"\def\boxsize%s{%r}" % (int_to_roman(ibox), eh_0 - el_0) # noqa: UP031
)
lines.append(
rf"\def\boxlevel{int_to_roman(ibox)}{{{self.tree.box_levels[ibox]!r}}}")
r"\dev\boxlevel%s{%r}" % (int_to_roman(ibox), # noqa: UP031
self.tree.box_levels[ibox]))

lines.append(
r"\def\boxpath#1{(boxl#1) rectangle (boxh#1)}")
Expand Down
2 changes: 1 addition & 1 deletion test/test_cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_compare_cl_and_py_cost_model(actx_factory, nsources, ntargets, dims, dt

constant_one_params = cl_cost_model.get_unit_calibration_params().copy()
for ilevel in range(trav.tree.nlevels):
constant_one_params["p_fmm_lev%d" % ilevel] = 10
constant_one_params[f"p_fmm_lev{ilevel}"] = 10

xlat_cost = make_pde_aware_translation_cost_model(dims, trav.tree.nlevels)

Expand Down
9 changes: 4 additions & 5 deletions test/test_fmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def get_fmmlib_ref_pot(wrangler, weights, sources_host, targets_host,
use_dipoles = dipole_vec is not None

import pyfmmlib

name = "fld" if dims == 3 else "grad"
dp = "_dp" if use_dipoles else ""
fmmlib_routine = getattr(
pyfmmlib,
"%spot%s%ddall%s_vec" % (
eqn_letter,
"fld" if dims == 3 else "grad",
dims,
"_dp" if use_dipoles else ""))
f"{eqn_letter}pot{name}{dims}dall{dp}_vec")

kwargs = {}
if dims == 3:
Expand Down
5 changes: 2 additions & 3 deletions test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def test_source_target_tree(actx_factory, dims, visualize=False):
pt.show()

if not all_good_here:
print("BAD BOX %s %d" % (what, ibox))
print(f"BAD BOX {what} {ibox}")

all_good_so_far = all_good_so_far and all_good_here

Expand Down Expand Up @@ -624,8 +624,7 @@ def test_extent_tree(actx_factory, dims, extent_norm, visualize=False):
all_good_here = np.all(good)

if not all_good_here:
print("BAD BOX %s %d level %d"
% (what, ibox, tree.box_levels[ibox]))
print(f"BAD BOX {what} {ibox} level {tree.box_levels[ibox]}")

all_good_so_far = all_good_so_far and all_good_here
assert all_good_here
Expand Down

0 comments on commit 166c40f

Please sign in to comment.