Skip to content
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
3 changes: 3 additions & 0 deletions .pylintrc-local.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
- arg: py-version
val: '3.10'

- arg: extension-pkg-whitelist
val: mayavi
4 changes: 2 additions & 2 deletions contrib/translations/PDE-reduction and translations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
" plt.scatter(x, y, c=coeffs, **kwargs)\n",
" plt.colorbar()\n",
"\n",
" for cid, coeff in zip(expn.get_coefficient_identifiers(), coeffs):\n",
" for cid, coeff in zip(expn.get_coefficient_identifiers(), coeffs, strict=True):\n",
" plt.text(cid[0], cid[1] + 0.2, f\"{coeff:.1f}\")"
]
},
Expand Down Expand Up @@ -308,7 +308,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
8 changes: 5 additions & 3 deletions contrib/translations/PDE-reduction-symbolic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@
"metadata": {},
"outputs": [],
"source": [
"eval_reduced = sum(a * b for a, b in zip(translated_reduce_coeffs, reduced_derivatives))\n",
"eval_full = sum(a * b for a, b in zip(translated_full_coeffs, full_derivatives))\n",
"eval_reduced = sum(a * b for a, b in zip(translated_reduce_coeffs, reduced_derivatives,\n",
" strict=True))\n",
"eval_full = sum(a * b for a, b in zip(translated_full_coeffs, full_derivatives,\n",
" strict=True))\n",
"\n",
"(eval_full - eval_reduced).simplify()"
]
Expand All @@ -118,7 +120,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ requires = [

[project]
name = "sumpy"
version = "2022.1"
version = "2024.0"
description = "Fast summation in Python"
readme = "README.rst"
license = { text = "MIT" }
authors = [
{ name = "Andreas Kloeckner", email = "inform@tiker.net" },
]
requires-python = ">=3.8"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
Expand Down Expand Up @@ -142,6 +142,7 @@ extend-exclude = [
]

[tool.mypy]
python_version = "3.10"
warn_unused_ignores = true

[[tool.mypy.overrides]]
Expand Down
2 changes: 1 addition & 1 deletion sumpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

import os
from typing import Hashable
from collections.abc import Hashable

import loopy as lp
from pytools.persistent_dict import WriteOncePersistentDict
Expand Down
4 changes: 2 additions & 2 deletions sumpy/assignment_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ def run_global_cse(self, extra_exprs=None):
new_assign_exprs = new_exprs[:len(assign_exprs)]
new_extra_exprs = new_exprs[len(assign_exprs):]

for name, new_expr in zip(assign_names, new_assign_exprs):
for name, new_expr in zip(assign_names, new_assign_exprs, strict=True):
self.assignments[name] = new_expr

for name, value in new_assignments:
assert isinstance(name, sym.Symbol)
self.add_assignment(name.name, value)

for name, new_expr in zip(assign_names, new_assign_exprs):
for name, new_expr in zip(assign_names, new_assign_exprs, strict=True):
# We want the assignment collection to be ordered correctly
# to make it easier for loopy to schedule.
# Deleting the original assignments and adding them again
Expand Down
4 changes: 2 additions & 2 deletions sumpy/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def __init__(self, complex_dtype=None):
def map_constant(self, expr, rec_self=None):
"""Convert complex values to numpy types
"""
if not isinstance(expr, (complex, np.complex64, np.complex128)):
if not isinstance(expr, complex | np.complex64 | np.complex128):
return IdentityMapper.map_constant(rec_self or self, expr,
rec_self=rec_self)

Expand Down Expand Up @@ -590,7 +590,7 @@ def map_sum(self, expr, *args):
new_children = tuple(first_group + second_group)
if len(new_children) == len(expr.children) and \
all(child is orig_child for child, orig_child in
zip(new_children, expr.children)):
zip(new_children, expr.children, strict=True)):
return expr
return prim.Sum(tuple(first_group+second_group))

Expand Down
4 changes: 2 additions & 2 deletions sumpy/cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def tree_cse(exprs, symbols, opt_subs=None):
excluded_symbols = set()

def find_repeated(expr):
if not isinstance(expr, (Basic, Unevaluated)):
if not isinstance(expr, Basic | Unevaluated):
return

if isinstance(expr, Basic) and expr.is_Atom:
Expand Down Expand Up @@ -505,7 +505,7 @@ def find_repeated(expr):
subs = {}

def rebuild(expr):
if not isinstance(expr, (Basic, Unevaluated)):
if not isinstance(expr, Basic | Unevaluated):
return expr

if not expr.args:
Expand Down
6 changes: 3 additions & 3 deletions sumpy/derivative_taker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"""

import logging
from typing import Any, Dict, Tuple
from typing import Any

import numpy as np

Expand Down Expand Up @@ -146,7 +146,7 @@ def diff(self, mi):
def get_derivative_taking_sequence(self, start_mi, end_mi):
current_mi = np.array(start_mi, dtype=int)
for idx, (mi_i, vec_i) in enumerate(
zip(self.mi_dist(end_mi, start_mi), self.var_list)):
zip(self.mi_dist(end_mi, start_mi), self.var_list, strict=True)):
for _ in range(1, 1 + mi_i):
current_mi[idx] += 1
yield vec_i, tuple(current_mi)
Expand Down Expand Up @@ -341,7 +341,7 @@ def diff(self, mi, q=0):

# {{{ DifferentiatedExprDerivativeTaker

DerivativeCoeffDict = Dict[Tuple[int, ...], Any]
DerivativeCoeffDict = dict[tuple[int, ...], Any]


@tag_dataclass
Expand Down
4 changes: 2 additions & 2 deletions sumpy/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def distribute_source_weights(self, src_weight_vecs, src_idx_all_ranks):
local_src_weight_vecs_device = [
cl.array.to_device(src_weight.queue, local_src_weight)
for local_src_weight, src_weight in
zip(local_src_weight_vecs_host, src_weight_vecs)]
zip(local_src_weight_vecs_host, src_weight_vecs, strict=True)]

return local_src_weight_vecs_device

Expand All @@ -70,7 +70,7 @@ def gather_potential_results(self, potentials, tgt_idx_all_ranks):
return make_obj_array([
cl.array.to_device(potentials_dev.queue, gathered_potentials_host)
for gathered_potentials_host, potentials_dev in
zip(gathered_potentials_host_vec, potentials)])
zip(gathered_potentials_host_vec, potentials, strict=True)])
else:
return None

Expand Down
5 changes: 3 additions & 2 deletions sumpy/expansion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

import logging
from abc import ABC, abstractmethod
from typing import Any, ClassVar, Hashable, Sequence
from collections.abc import Hashable, Sequence
from typing import Any, ClassVar

import loopy as lp
import pymbolic.primitives as prim
Expand Down Expand Up @@ -161,7 +162,7 @@ def coefficients_from_source_vec(self,
the coefficients of the expansion.
"""
result = [0]*len(self)
for knl, weight in zip(kernels, weights):
for knl, weight in zip(kernels, weights, strict=True):
coeffs = self.coefficients_from_source(knl, avec, bvec, rscale, sac=sac)
for i in range(len(result)):
result[i] += weight * coeffs[i]
Expand Down
8 changes: 4 additions & 4 deletions sumpy/expansion/diff_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"""

import logging
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from itertools import accumulate
from typing import Mapping, Sequence, Union

import numpy as np
import sympy as sp
Expand Down Expand Up @@ -74,7 +74,7 @@ class DerivativeIdentifier:
"""


Number_ish = Union[int, float, complex, np.number]
Number_ish = int | float | complex | np.number


@dataclass(frozen=True, eq=True)
Expand Down Expand Up @@ -126,7 +126,7 @@ def __add__(
assert self.dim == other_diff_op.dim
assert len(self.eqs) == len(other_diff_op.eqs)
eqs: list[Mapping[DerivativeIdentifier, sp.Expr]] = []
for eq, other_eq in zip(self.eqs, other_diff_op.eqs):
for eq, other_eq in zip(self.eqs, other_diff_op.eqs, strict=True):
res = dict(eq)
for k, v in other_eq.items():
if k in res:
Expand Down Expand Up @@ -267,7 +267,7 @@ def intersect(
scalar_pde = min(scalar_pdes, key=lambda x: x.degree()).monic()
pde_dict = {
DerivativeIdentifier(mi, 0): sym.sympify(coeff.as_expr().simplify()) for
(mi, coeff) in zip(scalar_pde.monoms(), scalar_pde.coeffs())
(mi, coeff) in zip(scalar_pde.monoms(), scalar_pde.coeffs(), strict=True)
}
results.append(LinearPDESystemOperator(pde.dim, (immutabledict(pde_dict),)))

Expand Down
2 changes: 1 addition & 1 deletion sumpy/expansion/level_to_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __init__(self, tol, err_const_laplace=0.01, err_const_helmholtz=100,
def __call__(self, kernel, kernel_args, tree, level):
from sumpy.kernel import HelmholtzKernel, LaplaceKernel

assert isinstance(kernel, (LaplaceKernel, HelmholtzKernel))
assert isinstance(kernel, LaplaceKernel | HelmholtzKernel)

laplace_order = int(np.ceil(
(np.log(self.tol) - np.log(self.err_const_laplace))
Expand Down
5 changes: 3 additions & 2 deletions sumpy/expansion/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def coefficients_from_source_vec(self, kernels, avec, bvec, rscale, weights,
base_taker = base_kernel.get_derivative_taker(avec, rscale, sac)
result = [0]*len(self)

for knl, weight in zip(kernels, weights):
for knl, weight in zip(kernels, weights, strict=True):
taker = knl.postprocess_at_source(base_taker, avec)
# Following is a hack to make sure cse works.
if 1:
Expand Down Expand Up @@ -237,7 +237,8 @@ def evaluate(self, kernel, coeffs, bvec, rscale, sac=None):
* mi_power(bvec_scaled, mi, evaluate=False)
/ mi_factorial(mi)
for coeff, mi in zip(
evaluated_coeffs, self.get_full_coefficient_identifiers()))
evaluated_coeffs, self.get_full_coefficient_identifiers(),
strict=True))

return kernel.postprocess_at_target(result, bvec)

Expand Down
2 changes: 1 addition & 1 deletion sumpy/expansion/loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

import logging
from typing import Sequence
from collections.abc import Sequence

import numpy as np

Expand Down
8 changes: 4 additions & 4 deletions sumpy/expansion/m2l.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def translation_classes_dependent_data(self, tgt_expansion, src_expansion,

# Add zero values needed to make the translation matrix circulant
derivatives_full = [0]*len(circulant_matrix_mis)
for expr, mi in zip(vector, needed_vector_terms):
for expr, mi in zip(vector, needed_vector_terms, strict=True):
derivatives_full[circulant_matrix_ident_to_index[mi]] = expr

return derivatives_full
Expand All @@ -437,7 +437,7 @@ def preprocess_multipole_exprs(self, tgt_expansion, src_expansion,
input_vector = [0] * len(circulant_matrix_mis)
for coeff, term in zip(
src_coeff_exprs,
src_expansion.get_coefficient_identifiers()):
src_expansion.get_coefficient_identifiers(), strict=True):
input_vector[circulant_matrix_ident_to_index[term]] = \
add_to_sac(sac, coeff)

Expand Down Expand Up @@ -760,7 +760,7 @@ def translate(self, tgt_expansion, src_expansion, src_coeff_exprs, src_rscale,
assert translation_classes_dependent_data
derivatives = translation_classes_dependent_data
assert len(src_coeff_exprs) == len(derivatives)
result = [a*b for a, b in zip(derivatives, src_coeff_exprs)]
result = [a*b for a, b in zip(derivatives, src_coeff_exprs, strict=True)]
return result

def translation_classes_dependent_data(self, tgt_expansion, src_expansion,
Expand Down Expand Up @@ -981,7 +981,7 @@ def translate(self, tgt_expansion, src_expansion, src_coeff_exprs, src_rscale,
assert translation_classes_dependent_data is not None
derivatives = translation_classes_dependent_data
assert len(derivatives) == len(src_coeff_exprs)
return [a * b for a, b in zip(derivatives, src_coeff_exprs)]
return [a * b for a, b in zip(derivatives, src_coeff_exprs, strict=True)]

def loopy_translate(self, tgt_expansion, src_expansion):
raise NotImplementedError
Expand Down
6 changes: 3 additions & 3 deletions sumpy/expansion/multipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def coefficients_from_source_vec(self, kernels, avec, bvec, rscale, weights,
rscale = 1

result = [0]*len(self.get_full_coefficient_identifiers())
for kernel, weight in zip(kernels, weights):
for kernel, weight in zip(kernels, weights, strict=True):
if isinstance(kernel, KernelWrapper):
coeffs = [
kernel.postprocess_at_source(mi_power(avec, mi), avec)
Expand Down Expand Up @@ -109,7 +109,7 @@ def evaluate(self, kernel, coeffs, bvec, rscale, sac=None):
taker = kernel.postprocess_at_target(base_taker, bvec)

result = []
for coeff, mi in zip(coeffs, self.get_coefficient_identifiers()):
for coeff, mi in zip(coeffs, self.get_coefficient_identifiers(), strict=True):
result.append(coeff * taker.diff(mi, lambda x: add_to_sac(sac, x)))

result = sym.Add(*tuple(result))
Expand Down Expand Up @@ -289,7 +289,7 @@ def translate_from(self, src_expansion, src_coeff_exprs, src_rscale,
for mi_i in range(tgt_mi[d]+1):
input_mi = mi_set_axis(tgt_mi, d, mi_i)
contrib = cur_dim_input_coeffs[tgt_mi_to_index[input_mi]]
for n, k, dist in zip(tgt_mi, input_mi, dvec):
for n, k, dist in zip(tgt_mi, input_mi, dvec, strict=True):
assert n >= k
contrib /= math.factorial(n-k)
contrib *= \
Expand Down
6 changes: 3 additions & 3 deletions sumpy/fmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def eval_direct(self, target_boxes, source_box_starts,
**kwargs)
events.append(evt)

for pot_i, pot_res_i in zip(pot, pot_res):
for pot_i, pot_res_i in zip(pot, pot_res, strict=True):
assert pot_i is pot_res_i
pot_i.add_event(evt)

Expand Down Expand Up @@ -957,7 +957,7 @@ def eval_multipoles(self,

wait_for = [evt]

for pot_i, pot_res_i in zip(pot, pot_res):
for pot_i, pot_res_i in zip(pot, pot_res, strict=True):
assert pot_i is pot_res_i

if events:
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def eval_locals(self, level_start_target_box_nrs, target_boxes, local_exps):
**kwargs)
events.append(evt)

for pot_i, pot_res_i in zip(pot, pot_res):
for pot_i, pot_res_i in zip(pot, pot_res, strict=True):
assert pot_i is pot_res_i

return (pot, SumpyTimingFuture(queue, events))
Expand Down
3 changes: 2 additions & 1 deletion sumpy/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ def get_global_scaling_const(self):

def update_persistent_hash(self, key_hash, key_builder):
key_hash.update(type(self).__name__.encode("utf8"))
for name, value in zip(self.init_arg_names, self.__getinitargs__()):
for name, value in zip(self.init_arg_names, self.__getinitargs__(),
strict=True):
if name in ["expression", "global_scaling_const"]:
from pymbolic.mapper.persistent_hash import (
PersistentHashWalkMapper as PersistentHashWalkMapper,
Expand Down
5 changes: 3 additions & 2 deletions sumpy/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def get_optimized_kernel(self, max_nsources_in_one_box,
# as vec for the first dimension
for i, (array_name, array_size, array_dtype) in \
enumerate(zip(local_arrays, local_array_sizes,
local_array_dtypes)):
local_array_dtypes, strict=True)):
if issubclass(array_dtype.type, np.complexfloating):
# pyopencl does not support complex data type vectors
continue
Expand All @@ -721,7 +721,8 @@ def get_optimized_kernel(self, max_nsources_in_one_box,

# We need to split isrc_prefetch and isrc_offset into chunks.
nsources = (max_nsources_in_one_box + nprefetch - 1) // nprefetch
for local_array, axis in zip(local_arrays, local_array_isrc_axis):
for local_array, axis in zip(local_arrays, local_array_isrc_axis,
strict=True):
knl = lp.split_array_axis(knl, local_array, axis, nsources)
knl = lp.split_iname(knl, "isrc_prefetch", nsources,
outer_iname="iprefetch")
Expand Down
2 changes: 1 addition & 1 deletion sumpy/point_calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def diff(self, axis, f_values, nderivs=1):
"""

from numbers import Number
if isinstance(f_values, (np.number, Number)):
if isinstance(f_values, np.number | Number):
# constants differentiate to 0
return 0

Expand Down
Loading