Skip to content
4 changes: 4 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"DOFDescriptorLike": "pytential.symbolic.dof_desc.DOFDescriptorLike",
}

nitpick_ignore_regex = [
["py:class", r"boxtree\.array_context\.(.+)"],
]
Comment on lines +21 to +23
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this once the boxtree changes go in.


intersphinx_mapping = {
"arraycontext": ("https://documen.tician.de/arraycontext", None),
"boxtree": ("https://documen.tician.de/boxtree", None),
Expand Down
5 changes: 5 additions & 0 deletions doc/qbx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ QBX internals
This page documents :mod:`pytential` internals and is not typically
needed in end-user applications.

Array Context
-------------

.. automodule:: pytential.array_context

Refinement
----------

Expand Down
2 changes: 1 addition & 1 deletion examples/helmholtz-dirichlet.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import numpy as np
import numpy.linalg as la

from meshmode.array_context import PyOpenCLArrayContext
from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory,
)

from pytential import bind, sym
from pytential.array_context import PyOpenCLArrayContext
from pytential.target import PointsTarget


Expand Down Expand Up @@ -80,7 +80,7 @@
fmm_order=fmm_order
)

from sumpy.visualization import FieldPlotter

Check warning on line 83 in examples/helmholtz-dirichlet.py

View workflow job for this annotation

GitHub Actions / basedpyright

Stub file not found for "sumpy.visualization" (reportMissingTypeStubs)
fplot = FieldPlotter(np.zeros(2), extent=5, npoints=500)
targets = actx.from_numpy(fplot.points)

Expand All @@ -94,7 +94,7 @@

# {{{ describe bvp

from sumpy.kernel import HelmholtzKernel, LaplaceKernel

Check warning on line 97 in examples/helmholtz-dirichlet.py

View workflow job for this annotation

GitHub Actions / basedpyright

Stub file not found for "sumpy.kernel" (reportMissingTypeStubs)
kernel = HelmholtzKernel(2)

sigma_sym = sym.var("sigma")
Expand Down
2 changes: 1 addition & 1 deletion examples/laplace-dirichlet-3d.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np

from meshmode.array_context import PyOpenCLArrayContext
from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory,
)

from pytential import bind, sym
from pytential.array_context import PyOpenCLArrayContext
from pytential.target import PointsTarget


Expand Down Expand Up @@ -72,7 +72,7 @@
fmm_order=fmm_order,
)

from sumpy.visualization import FieldPlotter

Check warning on line 75 in examples/laplace-dirichlet-3d.py

View workflow job for this annotation

GitHub Actions / basedpyright

Stub file not found for "sumpy.visualization" (reportMissingTypeStubs)
fplot = FieldPlotter(np.zeros(3), extent=20, npoints=50)
targets = actx.from_numpy(fplot.points)

Expand All @@ -86,7 +86,7 @@

# {{{ describe bvp

from sumpy.kernel import LaplaceKernel

Check warning on line 89 in examples/laplace-dirichlet-3d.py

View workflow job for this annotation

GitHub Actions / basedpyright

Stub file not found for "sumpy.kernel" (reportMissingTypeStubs)
kernel = LaplaceKernel(3)

sigma_sym = sym.var("sigma")
Expand Down
2 changes: 1 addition & 1 deletion examples/laplace-dirichlet-simple.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np

from meshmode.array_context import PyOpenCLArrayContext
from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory,
)

from pytential import bind, sym
from pytential.array_context import PyOpenCLArrayContext
from pytential.target import PointsTarget


Expand Down Expand Up @@ -59,7 +59,7 @@
fmm_order=fmm_order
)

from sumpy.visualization import FieldPlotter

Check warning on line 62 in examples/laplace-dirichlet-simple.py

View workflow job for this annotation

GitHub Actions / basedpyright

Stub file not found for "sumpy.visualization" (reportMissingTypeStubs)
fplot = FieldPlotter(np.zeros(2), extent=5, npoints=500)
targets = actx.from_numpy(fplot.points)

Expand All @@ -73,7 +73,7 @@

# {{{ describe bvp

from sumpy.kernel import LaplaceKernel

Check warning on line 76 in examples/laplace-dirichlet-simple.py

View workflow job for this annotation

GitHub Actions / basedpyright

Stub file not found for "sumpy.kernel" (reportMissingTypeStubs)
kernel = LaplaceKernel(2)

sigma_sym = sym.var("sigma")
Expand Down
2 changes: 1 addition & 1 deletion examples/scaling-study.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np

from meshmode.array_context import PyOpenCLArrayContext
from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory,
)

from pytential import bind, sym
from pytential.array_context import PyOpenCLArrayContext
from pytential.target import PointsTarget


Expand Down
6 changes: 2 additions & 4 deletions examples/cost.py → experiments/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def calibrate_cost_model(ctx):

for _ in range(RUNS):
timing_data = {}
bound_op.eval({"sigma": sigma}, array_context=actx,
timing_data=timing_data)
bound_op.eval({"sigma": sigma}, array_context=actx)

model_results.append(modeled_cost)
timing_results.append(timing_data)
Expand Down Expand Up @@ -175,8 +174,7 @@ def test_cost_model(ctx, calibration_params):
temp_timing_results = []
for _ in range(RUNS):
timing_data = {}
bound_op.eval({"sigma": sigma},
array_context=actx, timing_data=timing_data)
bound_op.eval({"sigma": sigma}, array_context=actx)
temp_timing_results.append(one(timing_data.values()))

timing_result = {}
Expand Down
92 changes: 92 additions & 0 deletions pytential/array_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from __future__ import annotations


__copyright__ = "Copyright (C) 2022 Alexandru Fikl"

__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

from arraycontext.pytest import (
_PytestPyOpenCLArrayContextFactoryWithClass,
register_pytest_array_context_factory,
)
from sumpy.array_context import ( # noqa: F401
PyOpenCLArrayContext as SumpyPyOpenCLArrayContext,
make_loopy_program,
)


__doc__ = """
.. autoclass:: PyOpenCLArrayContext
"""


# {{{ PyOpenCLArrayContext

class PyOpenCLArrayContext(SumpyPyOpenCLArrayContext):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should this inherit from the meshmode and the sumpy array contexts? Presumably it needs functionality from both to handle the mesh and the FMM..

def transform_loopy_program(self, t_unit):
kernel = t_unit.default_entrypoint
options = kernel.options

if not options.return_dict or not options.no_numpy:
raise ValueError(
"loopy kernels passed to 'call_loopy' must have 'return_dict' "
"and 'no_numpy' options set. Did you use 'make_loopy_program' "
f"to create the kernel '{kernel.name}'?")

# FIXME: this probably needs some proper logic
from meshmode.array_context import _transform_loopy_inner
transformed_t_unit = _transform_loopy_inner(t_unit)

if transformed_t_unit is not None:
return transformed_t_unit

return t_unit

# }}}


# {{{ pytest

def _acf():
import pyopencl as cl
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

return PyOpenCLArrayContext(queue, force_device_scalars=True)


class PytestPyOpenCLArrayContextFactory(
_PytestPyOpenCLArrayContextFactoryWithClass):
actx_class = PyOpenCLArrayContext

Check failure on line 78 in pytential/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Type "actx_class" is not assignable to declared type "property"   Type "type[PyOpenCLArrayContext]" is not assignable to type "property" (reportAssignmentType)

Check failure on line 78 in pytential/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

"actx_class" incorrectly overrides property of same name in class "_PytestPyOpenCLArrayContextFactoryWithClass" (reportIncompatibleMethodOverride)

def __call__(self):
# NOTE: prevent any cache explosions during testing!
from sympy.core.cache import clear_cache
clear_cache()

return super().__call__()


register_pytest_array_context_factory(
"pytential.pyopencl",
PytestPyOpenCLArrayContextFactory)

# }}}
16 changes: 8 additions & 8 deletions pytential/linalg/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,29 @@
from pytential.qbx.utils import tree_code_container
tcc = tree_code_container(lpot_source._setup_actx)

tree, _ = tcc.build_tree()(actx.queue,
tree, _ = tcc.build_tree()(actx,

Check failure on line 123 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument of type "PyOpenCLArrayContext" cannot be assigned to parameter "actx" of type "PyOpenCLArrayContext" in function "__call__"   "arraycontext.impl.pyopencl.PyOpenCLArrayContext" is not assignable to "boxtree.array_context.PyOpenCLArrayContext" (reportArgumentType)
particles=flatten(
actx.thaw(discr.nodes()), actx, leaf_class=DOFArray
),
max_particles_in_box=max_particles_in_box,
kind=tree_kind)

from boxtree import box_flags_enum
tree = tree.get(actx.queue)
# FIXME: maybe this should use IS_LEAF once available?

tree = actx.to_numpy(tree)
# FIXME maybe this should use IS_LEAF once available?
assert tree.box_flags is not None

Check failure on line 134 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Cannot access attribute "box_flags" for class "ndarray[_AnyShape, dtype[Any]]"   Attribute "box_flags" is unknown (reportAttributeAccessIssue)
leaf_boxes, = (
tree.box_flags & box_flags_enum.HAS_SOURCE_OR_TARGET_CHILD_BOXES == 0

Check failure on line 136 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Cannot access attribute "box_flags" for class "ndarray[_AnyShape, dtype[Any]]"   Attribute "box_flags" is unknown (reportAttributeAccessIssue)
).nonzero()

indices = np.empty(len(leaf_boxes), dtype=object)
starts: onp.Array1D[np.integer] | None = None

for i, ibox in enumerate(leaf_boxes):
box_start = tree.box_source_starts[ibox]

Check failure on line 143 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Cannot access attribute "box_source_starts" for class "ndarray[_AnyShape, dtype[Any]]"   Attribute "box_source_starts" is unknown (reportAttributeAccessIssue)
box_end = box_start + tree.box_source_counts_cumul[ibox]

Check failure on line 144 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Cannot access attribute "box_source_counts_cumul" for class "ndarray[_AnyShape, dtype[Any]]"   Attribute "box_source_counts_cumul" is unknown (reportAttributeAccessIssue)
indices[i] = tree.user_source_ids[box_start:box_end]

Check failure on line 145 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Cannot access attribute "user_source_ids" for class "ndarray[_AnyShape, dtype[Any]]"   Attribute "user_source_ids" is unknown (reportAttributeAccessIssue)
else:
if discr.ambient_dim != 2 and discr.dim == 1:
raise ValueError("only curves are supported for 'tree_kind=None'")
Expand Down Expand Up @@ -766,12 +767,11 @@
assert isinstance(setup_actx, PyOpenCLArrayContext)

tcc = tree_code_container(setup_actx)
tree, _ = tcc.build_tree()(actx.queue, targets,
max_particles_in_box=max_particles_in_box)
query, _ = tcc.build_area_query()(actx.queue, tree, pxy.centers, pxy.radii)
tree, _ = tcc.build_tree()(actx, targets, max_particles_in_box=max_particles_in_box)

Check failure on line 770 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument of type "PyOpenCLArrayContext" cannot be assigned to parameter "actx" of type "PyOpenCLArrayContext" in function "__call__"   "arraycontext.impl.pyopencl.PyOpenCLArrayContext" is not assignable to "boxtree.array_context.PyOpenCLArrayContext" (reportArgumentType)
query, _ = tcc.build_area_query()(actx, tree, pxy.centers, pxy.radii)

Check failure on line 771 in pytential/linalg/proxy.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument of type "PyOpenCLArrayContext" cannot be assigned to parameter "actx" of type "PyOpenCLArrayContext" in function "__call__"   "arraycontext.impl.pyopencl.PyOpenCLArrayContext" is not assignable to "boxtree.array_context.PyOpenCLArrayContext" (reportArgumentType)

tree = tree.get(actx.queue)
query = query.get(actx.queue)
tree = actx.to_numpy(tree)
query = actx.to_numpy(query)

# }}}

Expand Down
Loading
Loading