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

Fix RUF052 errors #252

Merged
merged 2 commits into from
Dec 15, 2024
Merged
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
8 changes: 4 additions & 4 deletions pytential/linalg/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ def __init__(
:param norm_type: type of the norm used to compute the centers of
each cluster. Supported values are ``"linf"`` and ``"l2"``.
"""
if _generate_ref_proxies is None:
generate_ref_proxies = _generate_ref_proxies
if generate_ref_proxies is None:
from functools import partial
_generate_ref_proxies = partial(
_generate_unit_sphere, places.ambient_dim)
generate_ref_proxies = partial(_generate_unit_sphere, places.ambient_dim)

from pytential import GeometryCollection
if not isinstance(places, GeometryCollection):
Expand All @@ -404,7 +404,7 @@ def __init__(
self.radius_factor = radius_factor
self.norm_type = norm_type

self.ref_points = _generate_ref_proxies(approx_nproxy)
self.ref_points = generate_ref_proxies(approx_nproxy)

@property
def ambient_dim(self) -> int:
Expand Down
24 changes: 14 additions & 10 deletions pytential/linalg/skeletonization.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,17 @@ def make_skeletonization_wrangler(
from pytential.symbolic.matrix import (
P2PClusterMatrixBuilder, QBXClusterMatrixBuilder)

if _neighbor_cluster_builder is None:
_neighbor_cluster_builder = QBXClusterMatrixBuilder
neighbor_cluster_builder = _neighbor_cluster_builder
if neighbor_cluster_builder is None:
neighbor_cluster_builder = QBXClusterMatrixBuilder

if _proxy_source_cluster_builder is None:
_proxy_source_cluster_builder = P2PClusterMatrixBuilder
proxy_source_cluster_builder = _proxy_source_cluster_builder
if proxy_source_cluster_builder is None:
proxy_source_cluster_builder = P2PClusterMatrixBuilder

if _proxy_target_cluster_builder is None:
_proxy_target_cluster_builder = QBXClusterMatrixBuilder
proxy_target_cluster_builder = _proxy_target_cluster_builder
if proxy_target_cluster_builder is None:
proxy_target_cluster_builder = QBXClusterMatrixBuilder

# }}}

Expand All @@ -455,15 +458,15 @@ def make_skeletonization_wrangler(
input_exprs=tuple(input_exprs),
domains=tuple(domains),
context=context,
neighbor_cluster_builder=_neighbor_cluster_builder,
neighbor_cluster_builder=neighbor_cluster_builder,
# source
weighted_sources=weighted_sources,
source_proxy_exprs=source_proxy_exprs,
proxy_source_cluster_builder=_proxy_source_cluster_builder,
proxy_source_cluster_builder=proxy_source_cluster_builder,
# target
weighted_targets=weighted_targets,
target_proxy_exprs=target_proxy_exprs,
proxy_target_cluster_builder=_proxy_target_cluster_builder,
proxy_target_cluster_builder=proxy_target_cluster_builder,
)

# }}}
Expand Down Expand Up @@ -793,7 +796,8 @@ def skeletonize_by_proxy(
skels: np.ndarray = np.empty((wrangler.nrows, wrangler.ncols), dtype=object)
for ibrow in range(wrangler.nrows):
for ibcol in range(wrangler.ncols):
skels[ibrow, ibcol] = _skeletonize_block_by_proxy_with_mats(
# NOTE: type annotations for object arrays are not there yet
skels[ibrow, ibcol] = _skeletonize_block_by_proxy_with_mats( # type: ignore[call-overload]
actx, ibrow, ibcol, places, proxy, wrangler, tgt_src_index,
id_eps=id_eps, id_rank=id_rank,
max_particles_in_box=max_particles_in_box)
Expand Down
46 changes: 24 additions & 22 deletions pytential/qbx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,17 @@ def __init__(
raise TypeError(
"must specify exactly one of 'fmm_order' or 'fmm_level_to_order'.")

if _box_extent_norm is None:
_box_extent_norm = "l2"
assert isinstance(_box_extent_norm, str)
box_extent_norm = _box_extent_norm
if box_extent_norm is None:
box_extent_norm = "l2"
assert isinstance(box_extent_norm, str)

if _from_sep_smaller_crit is None:
from_sep_smaller_crit = _from_sep_smaller_crit
if from_sep_smaller_crit is None:
# This seems to win no matter what the box extent norm is
# https://gitlab.tiker.net/papers/2017-qbx-fmm-3d/issues/10
_from_sep_smaller_crit = "precise_linf"
assert isinstance(_from_sep_smaller_crit, str)
from_sep_smaller_crit = "precise_linf"
assert isinstance(from_sep_smaller_crit, str)

if fmm_level_to_order is None:
if fmm_order is False:
Expand All @@ -206,31 +208,33 @@ def fmm_level_to_order(kernel, kernel_args, tree, level):
return fmm_order
assert isinstance(fmm_level_to_order, bool) or callable(fmm_level_to_order)

if _max_leaf_refine_weight is None:
max_leaf_refine_weight = _max_leaf_refine_weight
if max_leaf_refine_weight is None:
if density_discr.ambient_dim == 2:
# FIXME: This should be verified now that l^2 is the default.
_max_leaf_refine_weight = 64
max_leaf_refine_weight = 64
elif density_discr.ambient_dim == 3:
# FIXME: this is likely no longer up to date as the translation
# operators have changed (as of 07-07-2022)
# For static_linf/linf (private url):
# https://gitlab.tiker.net/papers/2017-qbx-fmm-3d/issues/8#note_25009
# For static_l2/l2 (private url):
# https://gitlab.tiker.net/papers/2017-qbx-fmm-3d/issues/12
_max_leaf_refine_weight = 512
max_leaf_refine_weight = 512
else:
# Just guessing...
_max_leaf_refine_weight = 64
assert isinstance(_max_leaf_refine_weight, int)
max_leaf_refine_weight = 64
assert isinstance(max_leaf_refine_weight, int)

if _from_sep_smaller_min_nsources_cumul is None:
from_sep_smaller_min_nsources_cumul = _from_sep_smaller_min_nsources_cumul
if from_sep_smaller_min_nsources_cumul is None:
# See here for the comment thread that led to these defaults:
# https://gitlab.tiker.net/inducer/boxtree/merge_requests/28#note_18661
if density_discr.dim == 1:
_from_sep_smaller_min_nsources_cumul = 15
from_sep_smaller_min_nsources_cumul = 15
else:
_from_sep_smaller_min_nsources_cumul = 30
assert isinstance(_from_sep_smaller_min_nsources_cumul, int)
from_sep_smaller_min_nsources_cumul = 30
assert isinstance(from_sep_smaller_min_nsources_cumul, int)

if expansion_factory is None:
expansion_factory = DefaultExpansionFactory()
Expand Down Expand Up @@ -258,15 +262,13 @@ def fmm_level_to_order(kernel, kernel_args, tree, level):

self.debug = debug
self._disable_refinement = _disable_refinement
self._expansions_in_tree_have_extent = \
_expansions_in_tree_have_extent
self._expansions_in_tree_have_extent = _expansions_in_tree_have_extent
self._expansion_stick_out_factor = _expansion_stick_out_factor
self._well_sep_is_n_away = _well_sep_is_n_away
self._max_leaf_refine_weight = _max_leaf_refine_weight
self._box_extent_norm = _box_extent_norm
self._from_sep_smaller_crit = _from_sep_smaller_crit
self._from_sep_smaller_min_nsources_cumul = \
_from_sep_smaller_min_nsources_cumul
self._max_leaf_refine_weight = max_leaf_refine_weight
self._box_extent_norm = box_extent_norm
self._from_sep_smaller_crit = from_sep_smaller_crit
self._from_sep_smaller_min_nsources_cumul = from_sep_smaller_min_nsources_cumul
self._tree_kind = _tree_kind
self._use_target_specific_qbx = _use_target_specific_qbx

Expand Down
4 changes: 2 additions & 2 deletions pytential/qbx/target_assoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

class target_status_enum(Enum): # noqa
c_name = "TargetStatus"
dtype = np.int32
dtype = np.dtype(np.int32)
c_value_prefix = ""

UNMARKED = 0
Expand All @@ -142,7 +142,7 @@ class target_status_enum(Enum): # noqa

class target_flag_enum(Enum): # noqa
c_name = "TargetFlag"
dtype = np.int32
dtype = np.dtype(np.int32)
c_value_prefix = ""

INTERIOR_OR_EXTERIOR_VOLUME_TARGET = 0
Expand Down
Loading