Skip to content

Commit

Permalink
Drop some long-deprecated functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Jul 5, 2024
1 parent 9001070 commit 5397085
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 70 deletions.
9 changes: 0 additions & 9 deletions arraycontext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
from .impl.pyopencl import PyOpenCLArrayContext
from .impl.pytato import PytatoJAXArrayContext, PytatoPyOpenCLArrayContext
from .loopy import make_loopy_program

# deprecated, remove in 2022.
from .metadata import _FirstAxisIsElementsTag
from .pytest import (
PytestArrayContextFactory,
PytestPyOpenCLArrayContextFactory,
Expand Down Expand Up @@ -170,12 +167,6 @@ def _deprecated_acf():
"get_container_context": (
"get_container_context_opt",
get_container_context_opt, 2022),
"FirstAxisIsElementsTag": (
"meshmode.transform_metadata.FirstAxisIsElementsTag",
_FirstAxisIsElementsTag, 2022),
"_acf": ("<no replacement yet>", _deprecated_acf, 2022),
"DeviceArray": ("Array", Array, 2023),
"DeviceScalar": ("Scalar", Scalar, 2023),
}


Expand Down
26 changes: 2 additions & 24 deletions arraycontext/impl/pyopencl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,32 +324,10 @@ def transform_loopy_program(self, t_unit):
"to create this kernel?")

all_inames = default_entrypoint.all_inames()
# FIXME: This could be much smarter.
inner_iname = None

# import with underscore to avoid DeprecationWarning
from arraycontext.metadata import _FirstAxisIsElementsTag

if (len(default_entrypoint.instructions) == 1
and isinstance(default_entrypoint.instructions[0], lp.Assignment)
and any(isinstance(tag, _FirstAxisIsElementsTag)
# FIXME: Firedrake branch lacks kernel tags
for tag in getattr(default_entrypoint, "tags", ()))):
stmt, = default_entrypoint.instructions

out_inames = [v.name for v in stmt.assignee.index_tuple]
assert out_inames
outer_iname = out_inames[0]
if len(out_inames) >= 2:
inner_iname = out_inames[1]

elif "iel" in all_inames:
outer_iname = "iel"

if "idof" in all_inames:
inner_iname = "idof"
inner_iname = None

elif "i0" in all_inames:
if "i0" in all_inames:
outer_iname = "i0"

if "i1" in all_inames:
Expand Down
28 changes: 1 addition & 27 deletions arraycontext/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
"""

from dataclasses import dataclass
from warnings import warn

from pytools.tag import Tag, UniqueTag
from pytools.tag import UniqueTag


@dataclass(frozen=True)
Expand All @@ -49,29 +48,4 @@ def __post_init__(self):
raise ValueError("'name' must be an identifier")


# {{{ deprecation handling

try:
from meshmode.transform_metadata import (
FirstAxisIsElementsTag as _FirstAxisIsElementsTag,
)
except ImportError:
# placeholder in case meshmode is too old to have it.
class _FirstAxisIsElementsTag(Tag): # type: ignore[no-redef]
pass


def __getattr__(name):
if name == "FirstAxisIsElementsTag":
warn(f"'arraycontext.{name}' is deprecated. "
f"Use 'meshmode.transform_metadata.{name}' instead. "
f"'arraycontext.{name}' will continue to work until 2022.",
DeprecationWarning, stacklevel=2)
return _FirstAxisIsElementsTag
else:
raise AttributeError(name)

# }}}


# vim: foldmethod=marker
22 changes: 12 additions & 10 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import pytest

from pytools.obj_array import make_obj_array
from pytools.tag import Tag

from arraycontext import (
ArrayContainer,
ArrayContext,
EagerJAXArrayContext,
FirstAxisIsElementsTag,
PyOpenCLArrayContext,
PytatoPyOpenCLArrayContext,
dataclass_array_container,
Expand Down Expand Up @@ -735,8 +735,7 @@ def test_array_context_einsum_array_manipulation(actx_factory, spec):
rng = np.random.default_rng()

mat = actx.from_numpy(rng.normal(size=(10, 10)))
res = actx.to_numpy(actx.einsum(spec, mat,
tagged=(FirstAxisIsElementsTag())))
res = actx.to_numpy(actx.einsum(spec, mat))
ans = np.einsum(spec, actx.to_numpy(mat))
assert np.allclose(res, ans)

Expand All @@ -752,8 +751,7 @@ def test_array_context_einsum_array_matmatprods(actx_factory, spec):

mat_a = actx.from_numpy(rng.normal(size=(5, 5)))
mat_b = actx.from_numpy(rng.normal(size=(5, 5)))
res = actx.to_numpy(actx.einsum(spec, mat_a, mat_b,
tagged=(FirstAxisIsElementsTag())))
res = actx.to_numpy(actx.einsum(spec, mat_a, mat_b))
ans = np.einsum(spec, actx.to_numpy(mat_a), actx.to_numpy(mat_b))
assert np.allclose(res, ans)

Expand All @@ -768,8 +766,7 @@ def test_array_context_einsum_array_tripleprod(actx_factory, spec):
mat_a = actx.from_numpy(rng.normal(size=(7, 5)))
mat_b = actx.from_numpy(rng.normal(size=(5, 7)))
vec = actx.from_numpy(rng.normal(size=(7)))
res = actx.to_numpy(actx.einsum(spec, mat_a, mat_b, vec,
tagged=(FirstAxisIsElementsTag())))
res = actx.to_numpy(actx.einsum(spec, mat_a, mat_b, vec))
ans = np.einsum(spec,
actx.to_numpy(mat_a),
actx.to_numpy(mat_b),
Expand Down Expand Up @@ -1523,6 +1520,11 @@ def _twice(x):

# {{{ test_taggable_cl_array_tags

@dataclass(frozen=True)
class MySampleTag(Tag):
pass


def test_taggable_cl_array_tags(actx_factory):
actx = actx_factory()
if not isinstance(actx, PyOpenCLArrayContext):
Expand All @@ -1535,10 +1537,10 @@ def test_taggable_cl_array_tags(actx_factory):

from arraycontext.impl.pyopencl.taggable_cl_array import to_tagged_cl_array
tagged_ary = to_tagged_cl_array(ary, axes=None,
tags=frozenset((FirstAxisIsElementsTag(),)))
tags=frozenset((MySampleTag(),)))

assert tagged_ary.base_data is ary.base_data
assert tagged_ary.tags == frozenset((FirstAxisIsElementsTag(),))
assert tagged_ary.tags == frozenset((MySampleTag(),))

# }}}

Expand All @@ -1550,7 +1552,7 @@ def test_taggable_cl_array_tags(actx_factory):

assert tagged_ary.base_data is ary.base_data
assert tagged_ary.tags == frozenset(
(FirstAxisIsElementsTag(), ElementwiseMapKernelTag())
(MySampleTag(), ElementwiseMapKernelTag())
)

# }}}
Expand Down

0 comments on commit 5397085

Please sign in to comment.