Skip to content
Merged

Bpr #231

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
58,106 changes: 58,106 additions & 0 deletions .basedpyright/baseline.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ on:
schedule:
- cron: '17 3 * * 0'

concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v5
- name: "Main Script"
run: |
uv run --only-group lint ruff check
Expand All @@ -25,8 +29,7 @@ jobs:
- uses: actions/checkout@v4
- uses: crate-ci/typos@master

mypy:
name: Mypy
basedpyright:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -39,8 +42,9 @@ jobs:
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_conda_env
python -m pip install mypy
mypy $(get_proj_name)
cipip install pytest pyfmmlib scipy matplotlib pyvisfile
cipip install basedpyright
basedpyright

pylint:
name: Pylint
Expand Down
12 changes: 0 additions & 12 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,6 @@ Pylint:
except:
- tags

Mypy:
script: |
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_venv
python -m pip install mypy
mypy $(get_proj_name)
tags:
- python3
except:
- tags

Downstream:
parallel:
matrix:
Expand Down
24 changes: 24 additions & 0 deletions doc/codegen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@ Code Generation
.. automodule:: sumpy.codegen
.. automodule:: sumpy.assignment_collection
.. automodule:: sumpy.cse

References
----------

This is only here because Sphinx (the documentation tool) fails to resolve these
references properly.

.. currentmodule:: lp

.. class:: TranslationUnit

See :class:`loopy.TranslationUnit`.

.. currentmodule:: sp

.. class:: Expr

See :class:`sympy.core.expr.Expr`.

.. currentmodule:: np

.. class:: ndarray

See :class:`numpy.ndarray`.
95 changes: 71 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "sumpy"
version = "2024.0"
description = "Fast summation in Python"
readme = "README.rst"
license = { text = "MIT" }
license = "MIT"
authors = [
{ name = "Andreas Kloeckner", email = "[email protected]" },
]
Expand All @@ -17,8 +17,6 @@ classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: Other Audience",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering",
Expand Down Expand Up @@ -93,6 +91,7 @@ extend-select = [
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle
"TC",
]
extend-ignore = [
"C90", # McCabe complexity
Expand Down Expand Up @@ -144,28 +143,76 @@ extend-exclude = [
"notes/*/*.eps",
]

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

[[tool.mypy.overrides]]
module = [
"boxtree.*",
"loopy.*",
"matplotlib.*",
"mayavi.*",
"pyfmmlib.*",
"pymbolic.*",
"pyopencl.*",
"pyvisfile.*",
"pyvkfft.*",
"scipy.*",
"symengine.*",
"sympy.*",
]
ignore_missing_imports = true

[tool.pytest.ini_options]
markers = [
"mpi: tests distributed FMM",
]

[tool.basedpyright]
reportImplicitStringConcatenation = "none"
reportUnnecessaryIsInstance = "none"
reportUnusedCallResult = "none"
reportExplicitAny = "none"
reportPrivateUsage = "none"

# Multiple reasons for this:
# - make_subst_func is reported as having an incomplete type (but only in CI?)
# - numpy scalar types are reported as incomplete (because of "any" precision)
reportUnknownVariableType = "none"

reportUnreachable = "hint"
reportUnnecessaryComparison = "hint"
reportPossiblyUnboundVariable = "hint"

# This reports even cycles that are qualified by 'if TYPE_CHECKING'. Not what
# we care about at this moment.
# https://github.com/microsoft/pyright/issues/746
reportImportCycles = "none"

pythonVersion = "3.10"
pythonPlatform = "All"

exclude = [
"doc",
"build",
"benchmarks",
"contrib",
".conda-root",
]

[[tool.basedpyright.executionEnvironments]]
root = "test"
reportUnknownArgumentType = "none"
reportUnknownVariableType = "none"
reportUnknownParameterType = "hint"
reportMissingParameterType = "none"
reportAttributeAccessIssue = "hint"
reportMissingTypeStubs = "hint"
reportUnknownLambdaType = "hint"
reportUnusedImport = "hint"
reportUnusedParameter = "none"
reportUnannotatedClassAttribute = "hint"
reportAny = "hint"
reportUnknownMemberType = "hint"
reportMissingImports = "none"
reportArgumentType = "hint"
reportOperatorIssue = "hint"

[[tool.basedpyright.executionEnvironments]]
root = "examples"
reportUnknownArgumentType = "none"
reportUnknownVariableType = "none"
reportUnknownParameterType = "hint"
reportMissingParameterType = "none"
reportAttributeAccessIssue = "hint"
reportMissingTypeStubs = "hint"
reportUnknownLambdaType = "hint"
reportUnusedImport = "hint"
reportUnusedParameter = "none"
reportUnannotatedClassAttribute = "hint"
reportAny = "hint"
reportUnknownMemberType = "hint"
reportMissingImports = "none"
reportArgumentType = "hint"
reportOperatorIssue = "hint"

9 changes: 7 additions & 2 deletions sumpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
"""

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

import loopy as lp
from pytools.persistent_dict import WriteOncePersistentDict

from sumpy.e2e import (
Expand All @@ -44,6 +43,12 @@
from sumpy.version import VERSION_TEXT


if TYPE_CHECKING:
from collections.abc import Hashable

import loopy as lp


__all__ = [
"P2P",
"E2EFromCSR",
Expand Down
9 changes: 7 additions & 2 deletions sumpy/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
THE SOFTWARE.
"""


import logging
import re
from abc import ABC
from typing import ParamSpec

import numpy as np
from constantdict import constantdict
Expand All @@ -43,6 +44,9 @@
logger = logging.getLogger(__name__)


P = ParamSpec("P")


__doc__ = """

Conversion of :mod:`sympy` expressions to :mod:`loopy`
Expand Down Expand Up @@ -237,7 +241,8 @@ def register_optimization_preambles(loopy_knl, device):

# {{{ custom mapper base classes

class CSECachingIdentityMapper(IdentityMapper, CSECachingMapperMixin):
class CSECachingIdentityMapper(
IdentityMapper[P], CSECachingMapperMixin[Expression, P], ABC):
pass


Expand Down
6 changes: 3 additions & 3 deletions sumpy/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from boxtree.distributed.calculation import DistributedExpansionWrangler

import pyopencl as cl
import pyopencl.array as cl_array

from sumpy.fmm import SumpyExpansionWrangler

Expand All @@ -49,7 +49,7 @@ def distribute_source_weights(self, src_weight_vecs, src_idx_all_ranks):
src_weight_vecs_host, src_idx_all_ranks)

local_src_weight_vecs_device = [
cl.array.to_device(src_weight.queue, local_src_weight)
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, strict=True)]

Expand All @@ -68,7 +68,7 @@ def gather_potential_results(self, potentials, tgt_idx_all_ranks):
if mpi_rank == 0:
from pytools.obj_array import make_obj_array
return make_obj_array([
cl.array.to_device(potentials_dev.queue, gathered_potentials_host)
cl_array.to_device(potentials_dev.queue, gathered_potentials_host)
for gathered_potentials_host, potentials_dev in
zip(gathered_potentials_host_vec, potentials, strict=True)])
else:
Expand Down
13 changes: 9 additions & 4 deletions sumpy/expansion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@

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

import loopy as lp
import pymbolic.primitives as prim
from pytools import memoize_method

import sumpy.symbolic as sym
from sumpy.kernel import Kernel
from sumpy.tools import add_mi


if TYPE_CHECKING:
from collections.abc import Hashable, Sequence

import loopy as lp

from sumpy.kernel import Kernel


logger = logging.getLogger(__name__)


Expand Down
6 changes: 5 additions & 1 deletion 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 TYPE_CHECKING

import numpy as np
import sympy as sp
Expand All @@ -41,6 +41,10 @@
from sumpy.tools import add_mi


if TYPE_CHECKING:
from collections.abc import Mapping, Sequence


logger = logging.getLogger(__name__)

__doc__ = """
Expand Down
11 changes: 8 additions & 3 deletions sumpy/expansion/loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

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

import numpy as np

Expand All @@ -33,11 +33,16 @@

import sumpy.symbolic as sym
from sumpy.assignment_collection import SymbolicAssignmentCollection
from sumpy.expansion import ExpansionBase
from sumpy.kernel import Kernel
from sumpy.tools import gather_loopy_arguments, gather_loopy_source_arguments


if TYPE_CHECKING:
from collections.abc import Sequence

from sumpy.expansion import ExpansionBase
from sumpy.kernel import Kernel


logger = logging.getLogger(__name__)


Expand Down
7 changes: 4 additions & 3 deletions sumpy/expansion/m2l.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

import logging
from abc import ABC, abstractmethod
from typing import Any, ClassVar
from typing import Any, ClassVar, cast

import numpy as np

import loopy as lp
import pymbolic
import pymbolic.primitives as p

import sumpy.symbolic as sym
from sumpy.tools import add_to_sac, matvec_toeplitz_upper_triangular
Expand Down Expand Up @@ -1075,8 +1076,8 @@ def loopy_translation_classes_dependent_data(tgt_expansion, src_expansion,
for i in range(len(insns)):
insn = insns[i]
if isinstance(insn, lp.Assignment) and \
insn.assignee.name.startswith(vec_name):
idx = int(insn.assignee.name[len(vec_name):])
cast("p.Variable", insn.assignee).name.startswith(vec_name):
idx = int(cast("p.Variable", insn.assignee).name[len(vec_name):])
insns[i] = lp.Assignment(
assignee=data[idx],
expression=insn.expression,
Expand Down
Loading
Loading