Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some deprecations #419

Merged
merged 5 commits into from
Jul 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion examples/moving-geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def source(t, x):
if __name__ == "__main__":
cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
actx = PyOpenCLArrayContext(queue)
actx = PyOpenCLArrayContext(queue, force_device_scalars=True)

from pytools import ProcessTimer
for _ in range(1):
Expand Down
2 changes: 1 addition & 1 deletion examples/plot-connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def main():
cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
actx = PyOpenCLArrayContext(queue)
actx = PyOpenCLArrayContext(queue, force_device_scalars=True)

from meshmode.mesh.generation import ( # noqa: F401
generate_icosahedron,
Expand Down
8 changes: 4 additions & 4 deletions examples/simple-dg.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ def face_jacobian(self, where):
@memoize_method
def get_inverse_mass_matrix(self, grp, dtype):
import modepy as mp
matrix = mp.inverse_mass_matrix(
grp.basis_obj().functions,
grp.unit_nodes)
matrix = mp.inverse_mass_matrix(grp.basis_obj(), grp.unit_nodes)

actx = self._setup_actx
return actx.freeze(actx.from_numpy(matrix))
Expand Down Expand Up @@ -441,7 +439,9 @@ def bump(actx, discr, t=0):
/ source_width**2))


@with_container_arithmetic(bcast_obj_array=True, rel_comparison=True)
@with_container_arithmetic(bcast_obj_array=True,
rel_comparison=True,
_cls_has_array_context_attr=True)
@dataclass_array_container
@dataclass(frozen=True)
class WaveState:
Expand Down
19 changes: 12 additions & 7 deletions meshmode/discretization/poly_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def mass_matrix(grp: InterpolatoryElementGroupBase) -> np.ndarray:

assert grp.is_orthonormal_basis()
return mp.mass_matrix(
grp.basis_obj().functions,
grp.basis_obj(),
grp.unit_nodes)


Expand Down Expand Up @@ -288,13 +288,18 @@ def quadrature_rule(self):
class _MassMatrixQuadratureElementGroup(PolynomialSimplexElementGroupBase):
@memoize_method
def quadrature_rule(self):
basis_fcts = self.basis_obj().functions
basis = self.basis_obj()
nodes = self._interp_nodes
mass_matrix = mp.mass_matrix(basis_fcts, nodes)
mass_matrix = mp.mass_matrix(basis, nodes)
weights = np.dot(mass_matrix,
np.ones(len(basis_fcts)))
np.ones(len(basis.functions)))
return mp.Quadrature(nodes, weights, exact_to=self.order)

@property
@memoize_method
def unit_nodes(self):
return self._interp_nodes
inducer marked this conversation as resolved.
Show resolved Hide resolved

@property
@abstractmethod
def _interp_nodes(self):
Expand Down Expand Up @@ -571,11 +576,11 @@ def basis_obj(self):

@memoize_method
def quadrature_rule(self):
basis_fcts = self._basis.functions
basis = self._basis
nodes = self._nodes
mass_matrix = mp.mass_matrix(basis_fcts, nodes)
mass_matrix = mp.mass_matrix(basis, nodes)
weights = np.dot(mass_matrix,
np.ones(len(basis_fcts)))
np.ones(len(basis.functions)))
return mp.Quadrature(nodes, weights, exact_to=self.order)

@property
Expand Down
3 changes: 1 addition & 2 deletions meshmode/mesh/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,8 +1646,7 @@ def not_none(vi: Optional[np.ndarray]) -> np.ndarray:
new_vertex_indices = np.cumsum(used_flags, dtype=mesh.vertex_id_dtype) - 1
new_vertex_indices[~used_flags] = -1

return replace(
mesh,
return mesh.copy(
vertices=mesh.vertices[:, used_flags],
groups=tuple(
replace(grp, vertex_indices=new_vertex_indices[grp.vertex_indices])
Expand Down
23 changes: 11 additions & 12 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from arraycontext import (
dataclass_array_container,
flatten,
pytest_generate_tests_for_array_contexts,
with_container_arithmetic,
)
Expand Down Expand Up @@ -142,33 +143,31 @@ def _get_test_containers(actx, ambient_dim=2):
@pytest.mark.parametrize("ord", [2, np.inf])
def test_container_norm(actx_factory, ord):
actx = actx_factory()

c_test = _get_test_containers(actx)

# {{{ actx.np.linalg.norm
# {{{ flat_norm

from pytools.obj_array import make_obj_array
c = MyContainer(name="hey", mass=1, momentum=make_obj_array([2, 3]), enthalpy=5)
c_obj_ary = make_obj_array([c, c])

n1 = actx.np.linalg.norm(c_obj_ary, ord)
n1 = flat_norm(c_obj_ary, ord)
n2 = np.linalg.norm([1, 2, 3, 5]*2, ord)
assert abs(n1 - n2) < 1e-12

# }}}

# {{{ flat_norm

# check nested vs actx.np.linalg.norm
assert actx.to_numpy(abs(
flat_norm(c_test[1], ord=ord)
- actx.np.linalg.norm(c_test[1], ord=ord))) < 1e-12

# check nested container with only Numbers (and no actx)
assert abs(flat_norm(c_obj_ary, ord=ord) - n2) < 1.0e-12
assert abs(
flat_norm(np.array([1, 1], dtype=object), ord=ord)
- np.linalg.norm([1, 1], ord=ord)) < 1.0e-12

# check nested
n1 = actx.to_numpy(flat_norm(c_test[1], ord=ord))
n2 = np.linalg.norm([
np.linalg.norm(actx.to_numpy(flatten(ary, actx)), ord=ord) for ary in c_test[1]
], ord=ord)
assert abs(n1 - n2) < 1e-12

# }}}

# }}}
Expand Down
3 changes: 1 addition & 2 deletions test/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ def test_remove_unused_vertices():

assert mesh.vertices is not None

mesh2 = replace(
mesh,
mesh2 = mesh.copy(
vertices=np.concatenate([np.zeros((3, 1)), mesh.vertices], axis=1),
groups=tuple(
replace(
Expand Down
2 changes: 1 addition & 1 deletion test/test_meshmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def test_mesh_without_vertices(actx_factory):
groups = [
replace(grp, nodes=grp.nodes, vertex_indices=None)
for grp in mesh.groups]
mesh = make_mesh(None, groups, is_conforming=False)
mesh = make_mesh(None, groups, is_conforming=None)

# try refining it
from meshmode.mesh.refinement import refine_uniformly
Expand Down
Loading