diff --git a/examples/sym-exp-complexity.py b/examples/sym-exp-complexity.py index 779bfc360cf1192ecfa87c0222556074824ddd2a..138c9c8713f62abffd2ba384329369027c75ae43 100644 --- a/examples/sym-exp-complexity.py +++ b/examples/sym-exp-complexity.py @@ -55,7 +55,7 @@ def find_flops(): flops = lp.get_op_map(loopy_knl).filter_by(dtype=[flop_type]).sum() flop_counts.append( flops.eval_with_dict( - dict(isrc_start=0, isrc_stop=1, ntgt_boxes=1))) + {"isrc_start": 0, "isrc_stop": 1, "ntgt_boxes": 1})) print(orders) print(flop_counts) diff --git a/sumpy/cse.py b/sumpy/cse.py index 49ba690f2d4aa278c2f91cb826bad9c177ca67ef..f7023aa1483bba6ad9f9eee89ecceb096d40e334 100644 --- a/sumpy/cse.py +++ b/sumpy/cse.py @@ -227,8 +227,7 @@ class FuncArgTracker: """ iarg = iter(argset) - indices = { - fi for fi in self.arg_to_funcset[next(iarg)]} + indices = set(self.arg_to_funcset[next(iarg)]) if restrict_to_funcset is not None: indices &= restrict_to_funcset @@ -366,7 +365,7 @@ def opt_cse(exprs): :arg exprs: A list of sympy expressions: the expressions to optimize. :return: A dictionary of expression substitutions """ - opt_subs = dict() + opt_subs = {} from sumpy.tools import OrderedSet adds = OrderedSet() @@ -446,7 +445,7 @@ def tree_cse(exprs, symbols, opt_subs=None): :return: A pair (replacements, reduced exprs) """ if opt_subs is None: - opt_subs = dict() + opt_subs = {} # {{{ find repeated sub-expressions and used symbols @@ -498,7 +497,7 @@ def tree_cse(exprs, symbols, opt_subs=None): replacements = [] - subs = dict() + subs = {} def rebuild(expr): if not isinstance(expr, (Basic, Unevaluated)): diff --git a/sumpy/e2e.py b/sumpy/e2e.py index 89df2789f47b2a7630a26281ebc84f56115ded9b..c357082b264a7388e58026f46126fda5479b9065 100644 --- a/sumpy/e2e.py +++ b/sumpy/e2e.py @@ -262,7 +262,7 @@ class E2EFromCSR(E2EBase): assumptions="ntgt_boxes>=1", silenced_warnings="write_race(write_expn*)", default_offset=lp.auto, - fixed_parameters=dict(dim=self.dim), + fixed_parameters={"dim": self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION ) @@ -492,11 +492,12 @@ class M2LUsingTranslationClassesDependentData(E2EFromCSR): name=self.name, assumptions="ntgt_boxes>=1", default_offset=lp.auto, - fixed_parameters=dict(dim=self.dim, - m2l_translation_classes_dependent_ndata=( + fixed_parameters={ + "dim": self.dim, + "m2l_translation_classes_dependent_ndata": ( m2l_translation_classes_dependent_ndata), - ncoeff_tgt=ncoeff_tgt, - ncoeff_src=ncoeff_src), + "ncoeff_tgt": ncoeff_tgt, + "ncoeff_src": ncoeff_src}, lang_version=MOST_RECENT_LANGUAGE_VERSION, silenced_warnings="write_race(write_e2e*)", ) @@ -600,10 +601,10 @@ class M2LGenerateTranslationClassesDependentData(E2EBase): name=self.name, assumptions="ntranslation_classes>=1", default_offset=lp.auto, - fixed_parameters=dict( - dim=self.dim, - m2l_translation_classes_dependent_ndata=( - m2l_translation_classes_dependent_ndata)), + fixed_parameters={ + "dim": self.dim, + "m2l_translation_classes_dependent_ndata": ( + m2l_translation_classes_dependent_ndata)}, lang_version=MOST_RECENT_LANGUAGE_VERSION ) @@ -704,9 +705,9 @@ class M2LPreprocessMultipole(E2EBase): ] + gather_loopy_arguments([self.src_expansion, self.tgt_expansion]), name=self.name, assumptions="nsrc_boxes>=1", - fixed_parameters=dict( - nsrc_coeffs=nsrc_coeffs, - npreprocessed_src_coeffs=npreprocessed_src_coeffs), + fixed_parameters={ + "nsrc_coeffs": nsrc_coeffs, + "npreprocessed_src_coeffs": npreprocessed_src_coeffs}, default_offset=lp.auto, lang_version=lp.MOST_RECENT_LANGUAGE_VERSION, ) @@ -793,11 +794,11 @@ class M2LPostprocessLocal(E2EBase): name=self.name, assumptions="ntgt_boxes>=1", default_offset=lp.auto, - fixed_parameters=dict( - dim=self.dim, - nsrc_coeffs=ntgt_coeffs_before_postprocessing, - ntgt_coeffs=ntgt_coeffs, - ), + fixed_parameters={ + "dim": self.dim, + "nsrc_coeffs": ntgt_coeffs_before_postprocessing, + "ntgt_coeffs": ntgt_coeffs, + }, lang_version=MOST_RECENT_LANGUAGE_VERSION ) @@ -913,7 +914,7 @@ class E2EFromChildren(E2EBase): name=self.name, assumptions="ntgt_boxes>=1", silenced_warnings="write_race(write_expn*)", - fixed_parameters=dict(dim=self.dim, nchildren=2**self.dim), + fixed_parameters={"dim": self.dim, "nchildren": 2**self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) for knl in [self.src_expansion.kernel, self.tgt_expansion.kernel]: @@ -1017,7 +1018,7 @@ class E2EFromParent(E2EBase): ] + gather_loopy_arguments([self.src_expansion, self.tgt_expansion]), name=self.name, assumptions="ntgt_boxes>=1", silenced_warnings="write_race(write_expn*)", - fixed_parameters=dict(dim=self.dim, nchildren=2**self.dim), + fixed_parameters={"dim": self.dim, "nchildren": 2**self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) for knl in [self.src_expansion.kernel, self.tgt_expansion.kernel]: diff --git a/sumpy/e2p.py b/sumpy/e2p.py index 611b2718d6e22f8b3741cc4c80f6d912f2be8d1e..a62236b0f15ca3b7327f508c456332522c10b17c 100644 --- a/sumpy/e2p.py +++ b/sumpy/e2p.py @@ -198,7 +198,7 @@ class E2PFromSingleBox(E2PBase): assumptions="ntgt_boxes>=1", silenced_warnings="write_race(write_result*)", default_offset=lp.auto, - fixed_parameters=dict(dim=self.dim, nresults=len(result_names)), + fixed_parameters={"dim": self.dim, "nresults": len(result_names)}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") @@ -210,7 +210,7 @@ class E2PFromSingleBox(E2PBase): def get_optimized_kernel(self): # FIXME knl = self.get_kernel() - knl = lp.tag_inames(knl, dict(itgt_box="g.0")) + knl = lp.tag_inames(knl, {"itgt_box": "g.0"}) knl = self._allow_redundant_execution_of_knl_scaling(knl) knl = lp.set_options(knl, enforce_variable_access_ordered="no_check") @@ -312,9 +312,9 @@ class E2PFromCSR(E2PBase): assumptions="ntgt_boxes>=1", silenced_warnings="write_race(write_result*)", default_offset=lp.auto, - fixed_parameters=dict( - dim=self.dim, - nresults=len(result_names)), + fixed_parameters={ + "dim": self.dim, + "nresults": len(result_names)}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") @@ -327,7 +327,7 @@ class E2PFromCSR(E2PBase): def get_optimized_kernel(self): # FIXME knl = self.get_kernel() - knl = lp.tag_inames(knl, dict(itgt_box="g.0")) + knl = lp.tag_inames(knl, {"itgt_box": "g.0"}) knl = self._allow_redundant_execution_of_knl_scaling(knl) knl = lp.set_options(knl, enforce_variable_access_ordered="no_check") diff --git a/sumpy/expansion/__init__.py b/sumpy/expansion/__init__.py index 8bc04ae5b41c2390ee106ba93516611a85698d31..d4ef6e6a7baa0650b0cbcf891d8a44939980029d 100644 --- a/sumpy/expansion/__init__.py +++ b/sumpy/expansion/__init__.py @@ -559,7 +559,7 @@ class LinearPDEBasedExpansionTermsWrangler(ExpansionTermsWrangler): def get_full_coefficient_identifiers(self): identifiers = super().get_full_coefficient_identifiers() key = self._get_mi_ordering_key() - return list(sorted(identifiers, key=key)) + return sorted(identifiers, key=key) @memoize_method def get_stored_ids_and_unscaled_projection_matrix(self): diff --git a/sumpy/expansion/m2l.py b/sumpy/expansion/m2l.py index 1845f1d338babceb5ddb31048fd12ac17a4b44a3..dbcc7d260072ae631ce59f225551c6d992ef52d3 100644 --- a/sumpy/expansion/m2l.py +++ b/sumpy/expansion/m2l.py @@ -170,7 +170,7 @@ class M2LTranslationBase(ABC): When FFT is turned on, the output expressions are assumed to be transformed into Fourier space at the end by the caller. """ - return tuple() + return () def translation_classes_dependent_ndata(self, tgt_expansion, src_expansion): """Return the number of expressions returned by @@ -247,7 +247,7 @@ class M2LTranslationBase(ABC): key_hash.update(type(self).__name__.encode("utf8")) def optimize_loopy_kernel(self, knl, tgt_expansion, src_expansion): - return lp.tag_inames(knl, dict(itgt_box="g.0")) + return lp.tag_inames(knl, {"itgt_box": "g.0"}) # }}} M2LTranslationBase @@ -443,8 +443,8 @@ class VolumeTaylorM2LTranslation(M2LTranslationBase): circulant_matrix_mis, _, _ = \ self._translation_classes_dependent_data_mis(tgt_expansion, src_expansion) - circulant_matrix_ident_to_index = dict((ident, i) for i, ident in - enumerate(circulant_matrix_mis)) + circulant_matrix_ident_to_index = { + ident: i for i, ident in enumerate(circulant_matrix_mis)} ncoeff_src = len(src_expansion.get_coefficient_identifiers()) ncoeff_preprocessed = self.preprocess_multipole_nexprs(tgt_expansion, @@ -495,7 +495,7 @@ class VolumeTaylorM2LTranslation(M2LTranslationBase): ...], name="m2l_preprocess_inner", lang_version=lp.MOST_RECENT_LANGUAGE_VERSION, - fixed_parameters=dict(noutput_coeffs=ncoeff_preprocessed), + fixed_parameters={"noutput_coeffs": ncoeff_preprocessed}, ) def postprocess_local_exprs(self, tgt_expansion, src_expansion, m2l_result, @@ -524,8 +524,8 @@ class VolumeTaylorM2LTranslation(M2LTranslationBase): circulant_matrix_mis, needed_vector_terms, _ = \ self._translation_classes_dependent_data_mis(tgt_expansion, src_expansion) - circulant_matrix_ident_to_index = dict((ident, i) for i, ident in - enumerate(circulant_matrix_mis)) + circulant_matrix_ident_to_index = {ident: i for i, ident in + enumerate(circulant_matrix_mis)} ncoeff_tgt = len(tgt_expansion.get_coefficient_identifiers()) ncoeff_before_postprocessed = self.postprocess_local_nexprs(tgt_expansion, @@ -758,7 +758,7 @@ class VolumeTaylorM2LWithFFT(VolumeTaylorM2LWithPreprocessedMultipoles): knl = lp.split_iname(knl, "icoeff_tgt", 32, inner_iname="inner", inner_tag="l.0") - knl = lp.tag_inames(knl, dict(itgt_box="g.0")) + knl = lp.tag_inames(knl, {"itgt_box": "g.0"}) return knl @@ -1012,7 +1012,7 @@ def translation_classes_dependent_data_loopy_knl(tgt_expansion, src_expansion, from sumpy.tools import to_complex_dtype insns = to_loopy_insns( sac.assignments.items(), - vector_names=set(["d"]), + vector_names=frozenset({"d"}), pymbolic_expr_maps=[tgt_expansion.get_code_transformer()], retain_names=tgt_coeff_names, complex_dtype=to_complex_dtype(result_dtype), diff --git a/sumpy/fmm.py b/sumpy/fmm.py index 00ac1f380516910d184db23043d8e8f41efbe088..86b4412ae4f3fe08d975972b2ac79d51847664fe 100644 --- a/sumpy/fmm.py +++ b/sumpy/fmm.py @@ -540,16 +540,16 @@ class SumpyExpansionWrangler(ExpansionWranglerInterface): # use a FilteredTargetListsInTreeOrder object. def box_source_list_kwargs(self): - return dict( - box_source_starts=self.tree.box_source_starts, - box_source_counts_nonchild=self.tree.box_source_counts_nonchild, - sources=self.tree.sources) + return { + "box_source_starts": self.tree.box_source_starts, + "box_source_counts_nonchild": self.tree.box_source_counts_nonchild, + "sources": self.tree.sources} def box_target_list_kwargs(self): - return dict( - box_target_starts=self.tree.box_target_starts, - box_target_counts_nonchild=self.tree.box_target_counts_nonchild, - targets=self.tree.targets) + return { + "box_target_starts": self.tree.box_target_starts, + "box_target_counts_nonchild": self.tree.box_target_counts_nonchild, + "targets": self.tree.targets} # }}} diff --git a/sumpy/kernel.py b/sumpy/kernel.py index 70dd14e25abf3feda2f184237ead5f33f471cb33..7eb70ff77893dddc612ea09542944cae38c1af22 100644 --- a/sumpy/kernel.py +++ b/sumpy/kernel.py @@ -1009,7 +1009,7 @@ class AxisSourceDerivative(DerivativeBase): def get_derivative_coeff_dict_at_source(self, expr_dict): expr_dict = self.inner_kernel.get_derivative_coeff_dict_at_source( expr_dict) - result = dict() + result = {} for mi, coeff in expr_dict.items(): new_mi = list(mi) new_mi[self.axis] += 1 diff --git a/sumpy/p2e.py b/sumpy/p2e.py index 9532f6ecf4c16270236651d149e384f5fb2951b6..c41dbb48679ba0cedb0ef75428dbdc18188389c5 100644 --- a/sumpy/p2e.py +++ b/sumpy/p2e.py @@ -213,8 +213,8 @@ class P2EFromSingleBox(P2EBase): assumptions="nsrc_boxes>=1", silenced_warnings="write_race(write_expn*)", default_offset=lp.auto, - fixed_parameters=dict(dim=self.dim, - strength_count=self.strength_count), + fixed_parameters={ + "dim": self.dim, "strength_count": self.strength_count}, lang_version=MOST_RECENT_LANGUAGE_VERSION) for knl in self.source_kernels: @@ -334,8 +334,8 @@ class P2EFromCSR(P2EBase): assumptions="ntgt_boxes>=1", silenced_warnings="write_race(write_expn*)", default_offset=lp.auto, - fixed_parameters=dict(dim=self.dim, - strength_count=self.strength_count), + fixed_parameters={"dim": self.dim, + "strength_count": self.strength_count}, lang_version=MOST_RECENT_LANGUAGE_VERSION) for knl in self.source_kernels: diff --git a/sumpy/p2p.py b/sumpy/p2p.py index 385e90b031a1b4ce4bbc478d82bfbdb8db1e609e..dc8368da09d968ecb64b59c9a6822577c3e71a20 100644 --- a/sumpy/p2p.py +++ b/sumpy/p2p.py @@ -236,10 +236,10 @@ class P2P(P2PBase): assumptions="nsources>=1 and ntargets>=1", name=self.name, default_offset=lp.auto, - fixed_parameters=dict( - dim=self.dim, - nstrengths=self.strength_count, - nresults=len(self.target_kernels)), + fixed_parameters={ + "dim": self.dim, + "nstrengths": self.strength_count, + "nresults": len(self.target_kernels)}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") @@ -301,7 +301,7 @@ class P2PMatrixGenerator(P2PBase): arguments, assumptions="nsources>=1 and ntargets>=1", name=self.name, - fixed_parameters=dict(dim=self.dim), + fixed_parameters={"dim": self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") @@ -380,12 +380,12 @@ class P2PMatrixSubsetGenerator(P2PBase): assumptions="nresult>=1", silenced_warnings="write_race(write_p2p*)", name=self.name, - fixed_parameters=dict(dim=self.dim), + fixed_parameters={"dim": self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") - loopy_knl = lp.add_dtypes(loopy_knl, - dict(nsources=np.int32, ntargets=np.int32)) + loopy_knl = lp.add_dtypes( + loopy_knl, {"nsources": np.int32, "ntargets": np.int32}) for knl in self.target_kernels + self.source_kernels: loopy_knl = knl.prepare_loopy_kernel(loopy_knl) @@ -620,17 +620,17 @@ class P2PFromCSR(P2PBase): name=self.name, silenced_warnings=["write_race(write_csr*)", "write_race(prefetch_src)", "write_race(prefetch_charge)"], - fixed_parameters=dict( - dim=self.dim, - nstrengths=self.strength_count, - nsplit=nsplit, - src_outer_limit=src_outer_limit, - tgt_outer_limit=tgt_outer_limit, - noutputs=len(self.target_kernels)), + fixed_parameters={ + "dim": self.dim, + "nstrengths": self.strength_count, + "nsplit": nsplit, + "src_outer_limit": src_outer_limit, + "tgt_outer_limit": tgt_outer_limit, + "noutputs": len(self.target_kernels)}, lang_version=MOST_RECENT_LANGUAGE_VERSION) - loopy_knl = lp.add_dtypes(loopy_knl, - dict(nsources=np.int32, ntargets=np.int32)) + loopy_knl = lp.add_dtypes( + loopy_knl, {"nsources": np.int32, "ntargets": np.int32}) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") loopy_knl = lp.tag_inames(loopy_knl, "istrength*:unr") diff --git a/sumpy/qbx.py b/sumpy/qbx.py index a3042ef91fcfe323ea38713e2b0b6a322237c753..bd9d8fd2283b6b26c3ca3ce3209f1008a36a7147 100644 --- a/sumpy/qbx.py +++ b/sumpy/qbx.py @@ -272,7 +272,7 @@ class LayerPotential(LayerPotentialBase): assumptions="ntargets>=1 and nsources>=1", default_offset=lp.auto, silenced_warnings="write_race(write_lpot*)", - fixed_parameters=dict(dim=self.dim), + fixed_parameters={"dim": self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") @@ -349,7 +349,7 @@ class LayerPotentialMatrixGenerator(LayerPotentialBase): name=self.name, assumptions="ntargets>=1 and nsources>=1", default_offset=lp.auto, - fixed_parameters=dict(dim=self.dim), + fixed_parameters={"dim": self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") @@ -429,12 +429,12 @@ class LayerPotentialMatrixSubsetGenerator(LayerPotentialBase): assumptions="nresult>=1", default_offset=lp.auto, silenced_warnings="write_race(write_lpot*)", - fixed_parameters=dict(dim=self.dim), + fixed_parameters={"dim": self.dim}, lang_version=MOST_RECENT_LANGUAGE_VERSION) loopy_knl = lp.tag_inames(loopy_knl, "idim*:unr") - loopy_knl = lp.add_dtypes(loopy_knl, - dict(nsources=np.int32, ntargets=np.int32)) + loopy_knl = lp.add_dtypes( + loopy_knl, {"nsources": np.int32, "ntargets": np.int32}) for knl in self.source_kernels + self.target_kernels: loopy_knl = knl.prepare_loopy_kernel(loopy_knl) diff --git a/sumpy/tools.py b/sumpy/tools.py index 3d79ded5b4f423b182d3969968cf397533ca9880..5dd536c9fa6011ffe6b67b266c6e64e31c662510 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -1101,8 +1101,8 @@ def loopy_fft(shape, inverse, complex_dtype, index_dtype=None, expression=exp_table[table_idx % n], id=f"exp_{ilev}", depends_on=frozenset([f"idx_{ilev}"]), - within_inames=frozenset(map(lambda x: x.name, - [*broadcast_dims, iN1_sum, iN1, iN2])), + within_inames=frozenset({x.name for x in + [*broadcast_dims, iN1_sum, iN1, iN2]}), temp_var_type=lp.Optional(complex_dtype)), lp.Assignment( assignee=x[(*broadcast_dims, ifft + nfft * (iN1*N2 + iN2))], diff --git a/sumpy/toys.py b/sumpy/toys.py index 12e85031d802355c7bf9c1d09c9a7023a971ccbc..9fa67cbc2b93f4609be5ac7a96e0321a60e93ab9 100644 --- a/sumpy/toys.py +++ b/sumpy/toys.py @@ -735,10 +735,10 @@ def draw_annotation(to_pt, from_pt, label, arrowprops=None, **kwargs): import matplotlib.pyplot as plt - my_arrowprops = dict( - facecolor="black", - edgecolor="black", - arrowstyle="->") + my_arrowprops = { + "facecolor": "black", + "edgecolor": "black", + "arrowstyle": "->"} my_arrowprops.update(arrowprops) @@ -784,9 +784,9 @@ class SchematicVisitor: # # ------> M - text_kwargs = dict( - verticalalignment="center", - horizontalalignment="center") + text_kwargs = { + "verticalalignment": "center", + "horizontalalignment": "center"} label = "${}_{{{}}}$".format( type(psource).__name__[0].lower().replace("l", "\\ell"), @@ -805,7 +805,7 @@ class SchematicVisitor: font_size = mpl.rcParams["font.size"] shrinkB = 7/8 * font_size # noqa - arrowprops = dict(shrinkB=shrinkB, arrowstyle="<|-") + arrowprops = {"shrinkB": shrinkB, "arrowstyle": "<|-"} draw_annotation(psource.derived_from.center, psource.center, label, arrowprops, **text_kwargs)