Skip to content

Commit ebd4828

Browse files
Merge branch 'main' into cupyactx
2 parents f16bc29 + cda6110 commit ebd4828

8 files changed

Lines changed: 24824 additions & 55 deletions

File tree

.basedpyright/baseline.json

Lines changed: 24764 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/ci.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,42 @@ jobs:
3131
pip install ruff
3232
ruff check
3333
34-
pylint:
35-
name: Pylint
34+
mypy:
35+
name: Mypy
3636
runs-on: ubuntu-latest
3737
steps:
3838
- uses: actions/checkout@v4
3939
- name: "Main Script"
4040
run: |
41+
set -x
4142
USE_CONDA_BUILD=1
42-
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh
43-
4443
CONDA_ENVIRONMENT=.test-conda-env-py3.yml
4544
echo "- cupy" >> "$CONDA_ENVIRONMENT"
4645
47-
. ./prepare-and-run-pylint.sh "$(basename $GITHUB_REPOSITORY)" examples/*.py test/test_*.py
46+
curl -L -O https://tiker.net/ci-support-v0
47+
. ./ci-support-v0
4848
49-
mypy:
50-
name: Mypy
49+
build_py_project_in_conda_env
50+
python -m pip install mypy pytest
51+
./run-mypy.sh
52+
53+
basedpyright:
5154
runs-on: ubuntu-latest
5255
steps:
5356
- uses: actions/checkout@v4
5457
- name: "Main Script"
5558
run: |
59+
EXTRA_INSTALL="pytest types-colorama types-Pygments"
5660
curl -L -O https://tiker.net/ci-support-v0
5761
. ./ci-support-v0
5862
5963
CONDA_ENVIRONMENT=.test-conda-env-py3.yml
6064
echo "- cupy" >> "$CONDA_ENVIRONMENT"
6165
6266
build_py_project_in_conda_env
63-
python -m pip install mypy pytest
64-
./run-mypy.sh
67+
cipip install basedpyright
68+
69+
basedpyright "$(get_proj_name)" test
6570
6671
pytest3_pocl:
6772
name: Pytest Conda Py3 POCL

.gitlab-ci.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,6 @@ Ruff:
115115
except:
116116
- tags
117117

118-
Pylint:
119-
script: |
120-
EXTRA_INSTALL="jax[cpu]"
121-
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh
122-
. ./prepare-and-run-pylint.sh "$CI_PROJECT_NAME" examples/*.py test/test_*.py
123-
tags:
124-
- python3
125-
except:
126-
- tags
127-
128118
Mypy:
129119
script: |
130120
EXTRA_INSTALL="mypy pytest"

arraycontext/fake_numpy.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,6 @@ def norm(self, ary, ord=None):
234234

235235
actx = self._array_context
236236

237-
try:
238-
from meshmode.dof_array import DOFArray, flat_norm
239-
except ImportError:
240-
pass
241-
else:
242-
if isinstance(ary, DOFArray):
243-
from warnings import warn
244-
warn("Taking an actx.np.linalg.norm of a DOFArray is deprecated. "
245-
"(DOFArrays use 2D arrays internally, and "
246-
"actx.np.linalg.norm should compute matrix norms of those.) "
247-
"This will stop working in 2022. "
248-
"Use meshmode.dof_array.flat_norm instead.",
249-
DeprecationWarning, stacklevel=2)
250-
251-
return flat_norm(ary, ord=ord)
252-
253237
try:
254238
iterable = serialize_container(ary)
255239
except NotAnArrayContainerError:

arraycontext/impl/jax/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ def call_loopy(self, t_unit, **kwargs):
132132

133133
def einsum(self, spec, *args, arg_names=None, tagged=()):
134134
import jax.numpy as jnp
135-
if arg_names is not None:
136-
from warnings import warn
137-
warn("'arg_names' don't bear any significance in "
138-
f"{type(self).__name__}.", stacklevel=2)
139-
140135
return jnp.einsum(spec, *args)
141136

142137
def clone(self):

arraycontext/impl/pyopencl/fake_numpy.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@
4747
from arraycontext.loopy import LoopyBasedFakeNumpyNamespace
4848

4949

50-
try:
51-
import pyopencl as cl # noqa: F401
52-
import pyopencl.array as cl_array
53-
except ImportError:
54-
pass
55-
56-
5750
# {{{ fake numpy
5851

5952
class PyOpenCLFakeNumpyNamespace(LoopyBasedFakeNumpyNamespace):
@@ -121,6 +114,7 @@ def _copy(subary):
121114
return self._array_context._rec_map_container(_copy, ary)
122115

123116
def arange(self, *args, **kwargs):
117+
import pyopencl.array as cl_array
124118
return cl_array.arange(self._array_context.queue, *args, **kwargs)
125119

126120
# }}}
@@ -155,13 +149,15 @@ def _rec_ravel(a):
155149
return rec_map_array_container(_rec_ravel, a)
156150

157151
def concatenate(self, arrays, axis=0):
152+
import pyopencl.array as cl_array
158153
return cl_array.concatenate(
159154
arrays, axis,
160155
self._array_context.queue,
161156
self._array_context.allocator
162157
)
163158

164159
def stack(self, arrays, axis=0):
160+
import pyopencl.array as cl_array
165161
return rec_multimap_array_container(
166162
lambda *args: cl_array.stack(arrays=args, axis=axis,
167163
queue=self._array_context.queue),
@@ -172,6 +168,7 @@ def stack(self, arrays, axis=0):
172168
# {{{ linear algebra
173169

174170
def vdot(self, x, y, dtype=None):
171+
import pyopencl.array as cl_array
175172
return rec_multimap_reduce_array_container(
176173
sum,
177174
partial(cl_array.vdot, dtype=dtype, queue=self._array_context.queue),
@@ -189,6 +186,7 @@ def _all(ary):
189186
return np.int8(all([ary]))
190187
return ary.all(queue=queue)
191188

189+
import pyopencl.array as cl_array
192190
return rec_map_reduce_array_container(
193191
partial(reduce, partial(cl_array.minimum, queue=queue)),
194192
_all,
@@ -202,6 +200,7 @@ def _any(ary):
202200
return np.int8(any([ary]))
203201
return ary.any(queue=queue)
204202

203+
import pyopencl.array as cl_array
205204
return rec_map_reduce_array_container(
206205
partial(reduce, partial(cl_array.maximum, queue=queue)),
207206
_any,
@@ -215,6 +214,8 @@ def array_equal(self, a: ArrayOrContainer, b: ArrayOrContainer) -> Array:
215214
true_ary = actx.from_numpy(np.int8(True))
216215
false_ary = actx.from_numpy(np.int8(False))
217216

217+
import pyopencl.array as cl_array
218+
218219
def rec_equal(x: ArrayOrContainer, y: ArrayOrContainer) -> cl_array.Array:
219220
if type(x) is not type(y):
220221
return false_ary
@@ -270,12 +271,15 @@ def not_equal(self, x, y):
270271
return rec_multimap_array_container(operator.ne, x, y)
271272

272273
def logical_or(self, x, y):
274+
import pyopencl.array as cl_array
273275
return rec_multimap_array_container(cl_array.logical_or, x, y)
274276

275277
def logical_and(self, x, y):
278+
import pyopencl.array as cl_array
276279
return rec_multimap_array_container(cl_array.logical_and, x, y)
277280

278281
def logical_not(self, x):
282+
import pyopencl.array as cl_array
279283
return rec_map_array_container(cl_array.logical_not, x)
280284

281285
# }}}
@@ -290,11 +294,13 @@ def _rec_sum(ary):
290294
if axis not in [None, tuple(range(ary.ndim))]:
291295
raise NotImplementedError(f"Sum over '{axis}' axes not supported.")
292296

297+
import pyopencl.array as cl_array
293298
return cl_array.sum(ary, dtype=dtype, queue=self._array_context.queue)
294299

295300
return rec_map_reduce_array_container(sum, _rec_sum, a)
296301

297302
def maximum(self, x, y):
303+
import pyopencl.array as cl_array
298304
return rec_multimap_array_container(
299305
partial(cl_array.maximum, queue=self._array_context.queue),
300306
x, y)
@@ -308,8 +314,10 @@ def amax(self, a, axis=None):
308314
def _rec_max(ary):
309315
if axis not in [None, tuple(range(ary.ndim))]:
310316
raise NotImplementedError(f"Max. over '{axis}' axes not supported.")
317+
import pyopencl.array as cl_array
311318
return cl_array.max(ary, queue=queue)
312319

320+
import pyopencl.array as cl_array
313321
return rec_map_reduce_array_container(
314322
partial(reduce, partial(cl_array.maximum, queue=queue)),
315323
_rec_max,
@@ -318,6 +326,7 @@ def _rec_max(ary):
318326
max = amax
319327

320328
def minimum(self, x, y):
329+
import pyopencl.array as cl_array
321330
return rec_multimap_array_container(
322331
partial(cl_array.minimum, queue=self._array_context.queue),
323332
x, y)
@@ -331,8 +340,10 @@ def amin(self, a, axis=None):
331340
def _rec_min(ary):
332341
if axis not in [None, tuple(range(ary.ndim))]:
333342
raise NotImplementedError(f"Min. over '{axis}' axes not supported.")
343+
import pyopencl.array as cl_array
334344
return cl_array.min(ary, queue=queue)
335345

346+
import pyopencl.array as cl_array
336347
return rec_map_reduce_array_container(
337348
partial(reduce, partial(cl_array.minimum, queue=queue)),
338349
_rec_min,
@@ -351,6 +362,7 @@ def where(self, criterion, then, else_):
351362
def where_inner(inner_crit, inner_then, inner_else):
352363
if isinstance(inner_crit, bool | np.bool_):
353364
return inner_then if inner_crit else inner_else
365+
import pyopencl.array as cl_array
354366
return cl_array.if_positive(inner_crit != 0, inner_then, inner_else,
355367
queue=self._array_context.queue)
356368

arraycontext/impl/pytato/utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,7 @@ def map_data_wrapper(self, expr: DataWrapper) -> Array:
199199
np_data = self.actx.to_numpy(expr.data)
200200
assert isinstance(np_data, np.ndarray)
201201

202-
# https://github.com/pylint-dev/pylint/issues/3893
203-
# pylint: disable=unexpected-keyword-arg
204-
# type-ignore: discussed at
205-
# https://github.com/inducer/arraycontext/pull/289#discussion_r1855523967
206-
# possibly related: https://github.com/python/mypy/issues/17375
207-
return DataWrapper( # type: ignore[call-arg]
202+
return DataWrapper(
208203
data=np_data,
209204
shape=expr.shape,
210205
axes=expr.axes,

pyproject.toml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "arraycontext"
77
version = "2024.0"
88
description = "Choose your favorite numpy-workalike"
99
readme = "README.rst"
10-
license = { text = "MIT" }
10+
license = "MIT"
1111
authors = [
1212
{ name = "Andreas Kloeckner", email = "inform@tiker.net" },
1313
]
@@ -17,7 +17,6 @@ classifiers = [
1717
"Intended Audience :: Developers",
1818
"Intended Audience :: Other Audience",
1919
"Intended Audience :: Science/Research",
20-
"License :: OSI Approved :: MIT License",
2120
"Natural Language :: English",
2221
"Programming Language :: Python",
2322
"Programming Language :: Python :: 3 :: Only",
@@ -133,3 +132,28 @@ ignore_missing_imports = true
133132
extend-ignore-re = [
134133
"(?Rm)^.*(#|//)\\s*spellchecker:\\s*disable-line$"
135134
]
135+
136+
[tool.basedpyright]
137+
reportImplicitStringConcatenation = "none"
138+
reportUnnecessaryIsInstance = "none"
139+
reportUnusedCallResult = "none"
140+
reportExplicitAny = "none"
141+
142+
# This reports even cycles that are qualified by 'if TYPE_CHECKING'. Not what
143+
# we care about at this moment.
144+
# https://github.com/microsoft/pyright/issues/746
145+
reportImportCycles = "none"
146+
pythonVersion = "3.10"
147+
pythonPlatform = "All"
148+
149+
[[tool.basedpyright.executionEnvironments]]
150+
root = "test"
151+
reportUnknownArgumentType = "hint"
152+
reportUnknownMemberType = "hint"
153+
reportUnknownVariableType = "hint"
154+
reportUnknownParameterType = "hint"
155+
reportMissingTypeArgument = "hint"
156+
reportPrivateUsage = "none"
157+
reportMissingTypeStubs = "hint"
158+
reportAny = "hint"
159+

0 commit comments

Comments
 (0)