From 1bd548d10f0d581c05a7d722ea58104314102029 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 30 Aug 2026 13:44:28 -0500 Subject: [PATCH 1/2] Placate ruff 0.16.5 --- arraycontext/container/arithmetic.py | 2 +- arraycontext/container/dataclass.py | 2 +- arraycontext/container/traversal.py | 2 +- arraycontext/context.py | 14 ++++----- arraycontext/impl/numpy/fake_numpy.py | 4 +-- arraycontext/impl/pyopencl/__init__.py | 2 +- arraycontext/impl/pyopencl/fake_numpy.py | 6 ++-- arraycontext/impl/pytato/compile.py | 2 +- arraycontext/impl/pytato/fake_numpy.py | 4 +-- arraycontext/pytest.py | 2 +- test/test_arraycontext.py | 37 ++++++++++++------------ 11 files changed, 37 insertions(+), 40 deletions(-) diff --git a/arraycontext/container/arithmetic.py b/arraycontext/container/arithmetic.py index dc8e422f..8f14eaad 100644 --- a/arraycontext/container/arithmetic.py +++ b/arraycontext/container/arithmetic.py @@ -738,7 +738,7 @@ def {fname}(arg2, arg1): code = gen.get().rstrip()+"\n" result_dict = {"_MODULE_SOURCE_CODE": code, "cls": cls} - exec(compile(code, f"", "exec"), # ruff:ignore[exec-builtin] + exec(compile(code, f"", "exec"), result_dict) return cls diff --git a/arraycontext/container/dataclass.py b/arraycontext/container/dataclass.py index 75630110..a1e003b0 100644 --- a/arraycontext/container/dataclass.py +++ b/arraycontext/container/dataclass.py @@ -247,7 +247,7 @@ def _deserialize_init_arrays_code_{lower_cls_name}( """) exec_dict = {"cls": cls, "_MODULE_SOURCE_CODE": serialize_code} - exec(compile(serialize_code, f"", # ruff:ignore[exec-builtin] + exec(compile(serialize_code, f"", "exec"), exec_dict) return cls diff --git a/arraycontext/container/traversal.py b/arraycontext/container/traversal.py index e84595ff..9be819b3 100644 --- a/arraycontext/container/traversal.py +++ b/arraycontext/container/traversal.py @@ -1209,7 +1209,7 @@ def treat_as_scalar(x: ArrayOrContainerOrScalar) -> bool: raise TypeError( "both arguments must have the same type if they are both " "non-object-array array containers.") - return multimap_array_container(lambda x, y: outer(x, y), a, b) + return multimap_array_container(outer, a, b) # }}} diff --git a/arraycontext/context.py b/arraycontext/context.py index 695d3155..57ac9634 100644 --- a/arraycontext/context.py +++ b/arraycontext/context.py @@ -495,15 +495,11 @@ def _get_csr_matmul_prg(self, out_ndim: int) -> loopy.TranslationUnit: out_shape_comp_names = ("nrows", *out_extra_shape_comp_names) domains: list[str] = [] - domains.append( - "{ [" + ",".join(out_inames) + "] : " - + " and ".join( - f"0 <= {iname} < {shape_comp_name}" - for iname, shape_comp_name in zip( - out_inames, out_shape_comp_names, strict=True)) - + " }") - domains.append( - "{ [iel] : iel_lbound <= iel < iel_ubound }") + domains.extend(("{ [" + ",".join(out_inames) + "] : " + " and ".join( + f"0 <= {iname} < {shape_comp_name}" + for iname, shape_comp_name + in zip(out_inames, out_shape_comp_names, strict=True)) + + " }", "{ [iel] : iel_lbound <= iel < iel_ubound }")) temporary_variables: Mapping[str, lp.TemporaryVariable] = { "iel_lbound": lp.TemporaryVariable( diff --git a/arraycontext/impl/numpy/fake_numpy.py b/arraycontext/impl/numpy/fake_numpy.py index 01998eb8..09d09918 100644 --- a/arraycontext/impl/numpy/fake_numpy.py +++ b/arraycontext/impl/numpy/fake_numpy.py @@ -239,11 +239,11 @@ def vdot(self, a, b): def any(self, a, /): return rec_map_reduce_array_container(partial(reduce, np.logical_or), - lambda subary: np.any(subary), a) + np.any, a) def all(self, a, /): return rec_map_reduce_array_container(partial(reduce, np.logical_and), - lambda subary: np.all(subary), a) + np.all, a) @override def array_equal(self, diff --git a/arraycontext/impl/pyopencl/__init__.py b/arraycontext/impl/pyopencl/__init__.py index 06753c52..7058010a 100644 --- a/arraycontext/impl/pyopencl/__init__.py +++ b/arraycontext/impl/pyopencl/__init__.py @@ -152,7 +152,7 @@ def __init__(self, super().__init__() self.context = queue.context self.queue = queue - self.allocator = allocator if allocator else None + self.allocator = allocator or None if wait_event_queue_length is None: wait_event_queue_length = 10 diff --git a/arraycontext/impl/pyopencl/fake_numpy.py b/arraycontext/impl/pyopencl/fake_numpy.py index 8de9904b..a1887fbd 100644 --- a/arraycontext/impl/pyopencl/fake_numpy.py +++ b/arraycontext/impl/pyopencl/fake_numpy.py @@ -365,7 +365,7 @@ def sum(self, dtype: DTypeLike | None = None, ) -> ArrayOrScalar: if isinstance(axis, int): - axis = axis, + axis = (axis,) def _rec_sum(ary): if axis not in [None, tuple(range(ary.ndim))]: @@ -400,7 +400,7 @@ def max(self, queue = self._array_context.queue if isinstance(axis, int): - axis = axis, + axis = (axis,) def _rec_max(ary): if axis not in [None, tuple(range(ary.ndim))]: @@ -438,7 +438,7 @@ def min(self, queue = self._array_context.queue if isinstance(axis, int): - axis = axis, + axis = (axis,) def _rec_min(ary): if axis not in [None, tuple(range(ary.ndim))]: diff --git a/arraycontext/impl/pytato/compile.py b/arraycontext/impl/pytato/compile.py index b16baa64..c030081d 100644 --- a/arraycontext/impl/pytato/compile.py +++ b/arraycontext/impl/pytato/compile.py @@ -173,7 +173,7 @@ def id_collector(keys, ary): def _to_input_for_compiled( ary: AllowedArrayTc, actx: _BasePytatoArrayContext) -> AllowedArrayTc: - """ + r""" Preprocess *ary* before turning it into a :class:`pytato.array.Placeholder` in :meth:`LazilyCompilingFunctionCaller.__call__`. diff --git a/arraycontext/impl/pytato/fake_numpy.py b/arraycontext/impl/pytato/fake_numpy.py index debf736f..3bcaee1a 100644 --- a/arraycontext/impl/pytato/fake_numpy.py +++ b/arraycontext/impl/pytato/fake_numpy.py @@ -175,12 +175,12 @@ def stack(self, arrays, axis=0): def all(self, a, /): return rec_map_reduce_array_container( partial(reduce, pt.logical_and), - lambda subary: pt.all(subary), a) + pt.all, a) def any(self, a, /): return rec_map_reduce_array_container( partial(reduce, pt.logical_or), - lambda subary: pt.any(subary), a) + pt.any, a) @override def array_equal(self, diff --git a/arraycontext/pytest.py b/arraycontext/pytest.py index dda02047..c8826018 100644 --- a/arraycontext/pytest.py +++ b/arraycontext/pytest.py @@ -421,7 +421,7 @@ def inner(metafunc: pytest.Metafunc) -> None: arg_value_tuples = sorted([ tuple(arg_dict[name] for name in arg_names) for arg_dict in arg_values_with_actx - ], key=lambda x: str(x)) + ], key=str) metafunc.parametrize(arg_names, arg_value_tuples, ids=ids) diff --git a/test/test_arraycontext.py b/test/test_arraycontext.py index 30eb8a88..8a5d0217 100644 --- a/test/test_arraycontext.py +++ b/test/test_arraycontext.py @@ -24,6 +24,7 @@ """ import logging +import math from dataclasses import dataclass from functools import partial from typing import TYPE_CHECKING, cast @@ -891,7 +892,7 @@ def _check_allclose(f, arg1, arg2, atol=5.0e-14): partial(_check_allclose, lambda x: 3 * x), ary, 2 * ary + ary) rec_multimap_array_container( - partial(_check_allclose, lambda x: actx.np.sin(x)), + partial(_check_allclose, actx.np.sin), ary, actx.np.sin(ary)) with pytest.raises(TypeError): @@ -1186,11 +1187,11 @@ def test_actx_compile(actx_factory: ArrayContextFactory): vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) - scaled_speed = compiled_rhs(np.float64(3.14), vel) + scaled_speed = compiled_rhs(np.float64(math.pi), vel) result = actx.to_numpy(scaled_speed) - np.testing.assert_allclose(result.u, -3.14*v_y) - np.testing.assert_allclose(result.v, 3.14*v_x) + np.testing.assert_allclose(result.u, -math.pi*v_y) + np.testing.assert_allclose(result.v, math.pi*v_x) def test_actx_compile_python_scalar(actx_factory: ArrayContextFactory): @@ -1204,11 +1205,11 @@ def test_actx_compile_python_scalar(actx_factory: ArrayContextFactory): vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) - scaled_speed = compiled_rhs(3.14, vel) + scaled_speed = compiled_rhs(math.pi, vel) result = actx.to_numpy(scaled_speed) - np.testing.assert_allclose(result.u, -3.14*v_y) - np.testing.assert_allclose(result.v, 3.14*v_x) + np.testing.assert_allclose(result.u, -math.pi*v_y) + np.testing.assert_allclose(result.v, math.pi*v_x) def test_actx_compile_kwargs(actx_factory: ArrayContextFactory): @@ -1222,11 +1223,11 @@ def test_actx_compile_kwargs(actx_factory: ArrayContextFactory): vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) - scaled_speed = compiled_rhs(3.14, vel=vel) + scaled_speed = compiled_rhs(math.pi, vel=vel) result = actx.to_numpy(scaled_speed) - np.testing.assert_allclose(result.u, -3.14*v_y) - np.testing.assert_allclose(result.v, 3.14*v_x) + np.testing.assert_allclose(result.u, -math.pi*v_y) + np.testing.assert_allclose(result.v, math.pi*v_x) def test_actx_compile_with_tuple_output_keys(actx_factory: ArrayContextFactory): @@ -1247,11 +1248,11 @@ def my_rhs(scale, vel): vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) - scaled_speed = compiled_rhs(3.14, vel=vel) + scaled_speed = compiled_rhs(math.pi, vel=vel) result = actx.to_numpy(scaled_speed)[0, 0] - np.testing.assert_allclose(result.u, -3.14*v_y) - np.testing.assert_allclose(result.v, 3.14*v_x) + np.testing.assert_allclose(result.u, -math.pi*v_y) + np.testing.assert_allclose(result.v, math.pi*v_x) def test_actx_compile_with_outlined_function(actx_factory: ArrayContextFactory): @@ -1286,14 +1287,14 @@ def multi_scale_and_orthogonalize( vel1 = Velocity2D(v1_x_actx, v1_y_actx, actx) vel2 = Velocity2D(v2_x_actx, v2_y_actx, actx) - scaled_speed1, scaled_speed2 = compiled_rhs(np.float64(3.14), vel1, vel2) + scaled_speed1, scaled_speed2 = compiled_rhs(np.float64(math.pi), vel1, vel2) result1 = actx.to_numpy(scaled_speed1) result2 = actx.to_numpy(scaled_speed2) - np.testing.assert_allclose(result1.u, -3.14*v1_y) - np.testing.assert_allclose(result1.v, 3.14*v1_x) - np.testing.assert_allclose(result2.u, -3.14*v2_y) - np.testing.assert_allclose(result2.v, 3.14*v2_x) + np.testing.assert_allclose(result1.u, -math.pi*v1_y) + np.testing.assert_allclose(result1.v, math.pi*v1_x) + np.testing.assert_allclose(result2.u, -math.pi*v2_y) + np.testing.assert_allclose(result2.v, math.pi*v2_x) # }}} From d3357f320bca210de7b711958fac941410ac2d90 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 30 Aug 2026 13:49:27 -0500 Subject: [PATCH 2/2] Update baseline --- .basedpyright/baseline.json | 122 +----------------------------------- 1 file changed, 1 insertion(+), 121 deletions(-) diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 458a61f3..e7f15d70 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -1005,47 +1005,7 @@ "code": "reportAny", "range": { "startColumn": 15, - "endColumn": 71, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 40, - "endColumn": 64, - "lineCount": 1 - } - }, - { - "code": "reportUnknownLambdaType", - "range": { - "startColumn": 47, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportUnknownLambdaType", - "range": { - "startColumn": 50, - "endColumn": 51, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 59, - "endColumn": 60, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 62, - "endColumn": 63, + "endColumn": 52, "lineCount": 1 } } @@ -2989,22 +2949,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 53, - "endColumn": 59, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 68, - "endColumn": 74, - "lineCount": 1 - } - }, { "code": "reportMissingParameterType", "range": { @@ -3013,22 +2957,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 53, - "endColumn": 59, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 68, - "endColumn": 74, - "lineCount": 1 - } - }, { "code": "reportReturnType", "range": { @@ -9153,22 +9081,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 23, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 38, - "endColumn": 44, - "lineCount": 1 - } - }, { "code": "reportMissingParameterType", "range": { @@ -9177,22 +9089,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 23, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 38, - "endColumn": 44, - "lineCount": 1 - } - }, { "code": "reportUnknownParameterType", "range": { @@ -11191,22 +11087,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownLambdaType", - "range": { - "startColumn": 48, - "endColumn": 49, - "lineCount": 1 - } - }, - { - "code": "reportUnknownLambdaType", - "range": { - "startColumn": 51, - "endColumn": 65, - "lineCount": 1 - } - }, { "code": "reportUnusedExpression", "range": {