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

Bump Python to 3.10 #438

Merged
merged 3 commits into from
Nov 4, 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
3 changes: 3 additions & 0 deletions .pylintrc-local.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- arg: py-version
val: '3.10'

- arg: ignore
val:
- firedrake
Expand Down
8 changes: 4 additions & 4 deletions examples/moving-geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"""

import logging
from typing import Optional, Type

import numpy as np

Expand Down Expand Up @@ -104,7 +103,7 @@ def advance(actx, dt, t, x, fn):

def run(actx, *,
ambient_dim: int = 3,
resolution: Optional[int] = None,
resolution: int | None = None,
target_order: int = 4,
tmax: float = 1.0,
timestep: float = 1.0e-2,
Expand All @@ -128,7 +127,7 @@ def run(actx, *,
# a bit of work when reconstructing after a time step

if group_factory_name == "warp_and_blend":
group_factory_cls: Type[poly.HomogeneousOrderBasedGroupFactory] = (
group_factory_cls: type[poly.HomogeneousOrderBasedGroupFactory] = (
poly.PolynomialWarpAndBlend2DRestrictingGroupFactory)

unit_nodes = mp.warp_and_blend_nodes(ambient_dim - 1, mesh_order)
Expand Down Expand Up @@ -201,7 +200,8 @@ def source(t, x):
gradx = sum(
num_reference_derivative(discr, (i,), x)
for i in range(discr.dim))
intx = sum(actx.np.sum(xi * wi) for xi, wi in zip(x, discr.quad_weights()))
intx = sum(actx.np.sum(xi * wi)
for xi, wi in zip(x, discr.quad_weights(), strict=True))

assert gradx is not None
assert intx is not None
Expand Down
8 changes: 5 additions & 3 deletions examples/simple-dg.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def grad(self, vec):
for idim in range(self.volume_discr.dim)]

return make_obj_array([
sum(dref_i*ipder_i for dref_i, ipder_i in zip(dref, ipder[iambient]))
sum(dref_i*ipder_i
for dref_i, ipder_i in zip(dref, ipder[iambient], strict=True))
for iambient in range(self.volume_discr.ambient_dim)])

def div(self, vecs):
Expand Down Expand Up @@ -259,7 +260,7 @@ def inverse_mass(self, vec):
vec_i,
arg_names=("mass_inv_mat", "vec"),
tagged=(FirstAxisIsElementsTag(),)
) for grp, vec_i in zip(discr.groups, vec)
) for grp, vec_i in zip(discr.groups, vec, strict=True)
)
) / actx.thaw(self.vol_jacobian())

Expand Down Expand Up @@ -321,7 +322,8 @@ def face_mass(self, vec):
),
tagged=(FirstAxisIsElementsTag(),))
for afgrp, volgrp, vec_i in zip(all_faces_discr.groups,
vol_discr.groups, vec)
vol_discr.groups,
vec, strict=True)
)
)

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

from abc import ABC, abstractmethod
from typing import Hashable, Iterable, Optional, Protocol, runtime_checkable
from collections.abc import Hashable, Iterable
from typing import Protocol, runtime_checkable
from warnings import warn

import numpy as np
Expand Down Expand Up @@ -353,7 +354,7 @@ def __init__(self,
actx: ArrayContext,
mesh: _Mesh,
group_factory: ElementGroupFactory,
real_dtype: Optional[np.dtype] = None,
real_dtype: np.dtype | None = None,
_force_actx_clone: bool = True) -> None:
"""
:arg actx: an :class:`arraycontext.ArrayContext` used to perform
Expand Down Expand Up @@ -397,10 +398,10 @@ def __init__(self,
self._cached_nodes = None

def copy(self,
actx: Optional[ArrayContext] = None,
mesh: Optional[_Mesh] = None,
group_factory: Optional[ElementGroupFactory] = None,
real_dtype: Optional[np.dtype] = None) -> "Discretization":
actx: ArrayContext | None = None,
mesh: _Mesh | None = None,
group_factory: ElementGroupFactory | None = None,
real_dtype: np.dtype | None = None) -> "Discretization":
"""Creates a new object of the same type with all arguments that are not
*None* replaced. The copy is not recursive.
"""
Expand Down Expand Up @@ -461,7 +462,7 @@ def _new_array(self, actx, creation_func, dtype=None):
for grp in self.groups)))

def empty(self, actx: ArrayContext,
dtype: Optional[np.dtype] = None) -> _DOFArray:
dtype: np.dtype | None = None) -> _DOFArray:
"""Return an empty :class:`~meshmode.dof_array.DOFArray`.

:arg dtype: type special value 'c' will result in a
Expand All @@ -479,7 +480,7 @@ def empty(self, actx: ArrayContext,
return self._new_array(actx, actx.np.zeros, dtype=dtype)

def zeros(self, actx: ArrayContext,
dtype: Optional[np.dtype] = None) -> _DOFArray:
dtype: np.dtype | None = None) -> _DOFArray:
"""Return a zero-initialized :class:`~meshmode.dof_array.DOFArray`.

:arg dtype: type special value 'c' will result in a
Expand Down
2 changes: 1 addition & 1 deletion meshmode/discretization/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def check_connection(actx: ArrayContext, connection: DirectDiscretizationConnect

assert len(connection.groups) == len(to_discr.groups)

for cgrp, tgrp in zip(connection.groups, to_discr.groups):
for cgrp, tgrp in zip(connection.groups, to_discr.groups, strict=True):
for batch in cgrp.batches:
fgrp = from_discr.groups[batch.from_group_index]

Expand Down
4 changes: 2 additions & 2 deletions meshmode/discretization/connection/chained.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _build_batches(actx, from_bins, to_bins, batch):
def to_device(x):
return actx.freeze(actx.from_numpy(np.asarray(x)))

for ibatch, (from_bin, to_bin) in enumerate(zip(from_bins, to_bins)):
for ibatch, (from_bin, to_bin) in enumerate(zip(from_bins, to_bins, strict=True)):
yield InterpolationBatch(
from_group_index=batch[ibatch].from_group_index,
from_element_indices=to_device(from_bin),
Expand Down Expand Up @@ -248,7 +248,7 @@ def flatten_chained_connection(actx, connection):

# build new groups
groups = []
for igrp, (from_bin, to_bin) in enumerate(zip(from_bins, to_bins)):
for igrp, (from_bin, to_bin) in enumerate(zip(from_bins, to_bins, strict=True)):
groups.append(DiscretizationConnectionElementGroup(
list(_build_batches(actx, from_bin, to_bin,
batch_info[igrp]))))
Expand Down
29 changes: 15 additions & 14 deletions meshmode/discretization/connection/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"""

from abc import ABC, abstractmethod
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Generic, List, Optional, Sequence, Tuple
from typing import Generic

import numpy as np

Expand Down Expand Up @@ -51,7 +52,7 @@


def _reshape_and_preserve_tags(
actx: ArrayContext, ary: ArrayT, new_shape: Tuple[int, ...]) -> ArrayT:
actx: ArrayContext, ary: ArrayT, new_shape: tuple[int, ...]) -> ArrayT:
try:
tags = ary.tags
except AttributeError:
Expand Down Expand Up @@ -126,19 +127,19 @@ class InterpolationBatch(Generic[ArrayT]):
from_element_indices: ArrayT
to_element_indices: ArrayT
result_unit_nodes: np.ndarray
to_element_face: Optional[int]
to_element_face: int | None

def __post_init__(self):
self._global_from_element_indices_cache: \
Optional[Tuple[ArrayT, ArrayT]] = None
self._global_from_element_indices_cache: (
tuple[ArrayT, ArrayT] | None) = None

@property
def nelements(self) -> int:
return len(self.from_element_indices)

def _global_from_element_indices(
self, actx: ArrayContext, to_group: ElementGroupBase
) -> Tuple[ArrayT, ArrayT]:
) -> tuple[ArrayT, ArrayT]:
"""Returns a version of :attr:`from_element_indices` that is usable
without :attr:`to_element_indices`, consisting of a tuple.
The first entry of the tuple is an array of flags indicating
Expand Down Expand Up @@ -408,7 +409,7 @@ def _resample_matrix(self, actx: ArrayContext, to_group_index: int,
# {{{ _resample_point_pick_indices

def _resample_point_pick_indices(self, to_group_index: int, ibatch_index: int,
tol_multiplier: Optional[float] = None):
tol_multiplier: float | None = None):
"""If :meth:`_resample_matrix` *R* is a row subset of a permutation
matrix *P*, return the index subset I so that ``x[I] == R @ x`` up to
machine epsilon multiplied by *tol_multiplier* (or an internally
Expand All @@ -431,7 +432,7 @@ def _resample_point_pick_indices(self, to_group_index: int, ibatch_index: int,
tol_multiplier=None: (to_group_index, ibatch_index, tol_multiplier))
def _frozen_resample_point_pick_indices(self, actx: ArrayContext,
to_group_index: int, ibatch_index: int,
tol_multiplier: Optional[float] = None):
tol_multiplier: float | None = None):
result = self._resample_point_pick_indices(
to_group_index=to_group_index,
ibatch_index=ibatch_index,
Expand All @@ -444,7 +445,7 @@ def _frozen_resample_point_pick_indices(self, actx: ArrayContext,
# }}}

@memoize_method
def is_permutation(self, tol_multiplier: Optional[float] = None) -> bool:
def is_permutation(self, tol_multiplier: float | None = None) -> bool:
"""Return *True* if no interpolation is used in applying this connection,
i.e. if the source unit nodes in the connection
(cf. :class:`InterpolationBatch.result_unit_nodes`) match up
Expand All @@ -463,7 +464,7 @@ def is_permutation(self, tol_multiplier: Optional[float] = None) -> bool:

def _per_target_group_pick_info(
self, actx: ArrayContext, i_tgrp: int
) -> Optional[Sequence[_FromGroupPickData]]:
) -> Sequence[_FromGroupPickData] | None:
"""Returns a list of :class:`_FromGroupPickData`, one per source group
from which data is to be transferred, or *None*, if conditions for
this representation are not met.
Expand All @@ -487,7 +488,7 @@ def _per_target_group_pick_info(
if not batch_source_groups:
return None

result: List[_FromGroupPickData] = []
result: list[_FromGroupPickData] = []
for source_group_index in batch_source_groups:
batch_indices_for_this_source_group = [
i for i, batch in enumerate(cgrp.batches)
Expand Down Expand Up @@ -552,7 +553,7 @@ def _per_target_group_pick_info(

def _global_point_pick_info(
self, actx: ArrayContext
) -> Sequence[Optional[Sequence[_FromGroupPickData]]]:
) -> Sequence[Sequence[_FromGroupPickData] | None]:
if self._global_point_pick_info_cache is not None:
return self._global_point_pick_info_cache

Expand Down Expand Up @@ -708,7 +709,7 @@ def group_pick_knl(is_surjective: bool):

group_arrays = []
for i_tgrp, (cgrp, group_pick_info) in enumerate(
zip(self.groups, self._global_point_pick_info(actx))):
zip(self.groups, self._global_point_pick_info(actx), strict=True)):

group_array_contributions = []

Expand Down Expand Up @@ -925,7 +926,7 @@ def knl():
tgt_node_nr_base = 0
mats = []
for i_tgrp, (tgrp, cgrp) in enumerate(
zip(conn.to_discr.groups, conn.groups)):
zip(conn.to_discr.groups, conn.groups, strict=True)):
for i_batch, batch in enumerate(cgrp.batches):
if not len(batch.from_element_indices):
continue
Expand Down
12 changes: 6 additions & 6 deletions meshmode/discretization/connection/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import logging
from dataclasses import dataclass
from typing import Optional

import numpy as np

Expand Down Expand Up @@ -165,7 +164,7 @@ def make_face_restriction(
discr: Discretization,
group_factory: ElementGroupFactory,
boundary_tag: BoundaryTag,
per_face_groups: Optional[bool] = False
per_face_groups: bool | None = False
) -> DirectDiscretizationConnection:
"""Create a mesh, a discretization and a connection to restrict
a function on *discr* to its values on the edges of element faces
Expand Down Expand Up @@ -232,7 +231,7 @@ def make_face_restriction(
connection_data = {}

for igrp, (grp, fagrp_list) in enumerate(
zip(discr.groups, discr.mesh.facial_adjacency_groups)):
zip(discr.groups, discr.mesh.facial_adjacency_groups, strict=True)):

mgrp = grp.mesh_el_group

Expand All @@ -252,7 +251,7 @@ def make_face_restriction(
if isinstance(fagrp, InteriorAdjacencyGroup)]
for fagrp in int_grps:
group_boundary_faces.extend(
zip(fagrp.elements, fagrp.element_faces))
zip(fagrp.elements, fagrp.element_faces, strict=True))

elif boundary_tag is FACE_RESTR_ALL:
group_boundary_faces.extend(
Expand All @@ -271,7 +270,8 @@ def make_face_restriction(
group_boundary_faces.extend(
zip(
bdry_grp.elements,
bdry_grp.element_faces))
bdry_grp.element_faces,
strict=True))

# }}}

Expand Down Expand Up @@ -383,7 +383,7 @@ def make_face_to_all_faces_embedding(
actx: ArrayContext,
faces_connection: DirectDiscretizationConnection,
all_faces_discr: Discretization,
from_discr: Optional[Discretization] = None
from_discr: Discretization | None = None
) -> DirectDiscretizationConnection:
"""Return a
:class:`meshmode.discretization.connection.DiscretizationConnection`
Expand Down
2 changes: 1 addition & 1 deletion meshmode/discretization/connection/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def vandermonde_matrix(grp):
c_i,
arg_names=("vdm", "coeffs"),
tagged=(FirstAxisIsElementsTag(),))
for grp, c_i in zip(self.to_discr.groups, coefficients)
for grp, c_i in zip(self.to_discr.groups, coefficients, strict=True)
)
)

Expand Down
15 changes: 10 additions & 5 deletions meshmode/discretization/connection/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def _build_interpolation_batches_for_group(
assert len(refinement_result) == num_children
# Refined -> interpolates to children
for from_bin, to_bin, child_idx in zip(
from_bins[1:], to_bins[1:], refinement_result):
from_bins[1:], to_bins[1:], refinement_result,
strict=True):
from_bin.append(elt_idx)
to_bin.append(child_idx)

Expand All @@ -97,8 +98,10 @@ def _build_interpolation_batches_for_group(

from itertools import chain
for from_bin, to_bin, unit_nodes in zip(
from_bins, to_bins,
chain([fine_unit_nodes], mapped_unit_nodes)):
from_bins,
to_bins,
chain([fine_unit_nodes], mapped_unit_nodes),
strict=True):
if not from_bin:
continue
yield InterpolationBatch(
Expand Down Expand Up @@ -148,8 +151,10 @@ def make_refinement_connection(actx, refiner, coarse_discr, group_factory):

groups = []
for group_idx, (coarse_discr_group, fine_discr_group, record) in \
enumerate(zip(coarse_discr.groups, fine_discr.groups,
refiner.group_refinement_records)):
enumerate(zip(coarse_discr.groups,
fine_discr.groups,
refiner.group_refinement_records,
strict=True)):
groups.append(
DiscretizationConnectionElementGroup(
list(_build_interpolation_batches_for_group(
Expand Down
3 changes: 2 additions & 1 deletion meshmode/discretization/connection/same_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def make_same_mesh_connection(actx, to_discr, from_discr):
return IdentityDiscretizationConnection(from_discr)

groups = []
for igrp, (fgrp, tgrp) in enumerate(zip(from_discr.groups, to_discr.groups)):
for igrp, (fgrp, tgrp) in enumerate(
zip(from_discr.groups, to_discr.groups, strict=True)):
from arraycontext.metadata import NameHint
all_elements = actx.tag(NameHint(f"all_el_ind_grp{igrp}"),
actx.tag_axis(0,
Expand Down
8 changes: 4 additions & 4 deletions meshmode/discretization/poly_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ def quadrature_rule(self):
else:
nodes_tp = self._nodes

for idim, (nodes, basis) in enumerate(zip(nodes_tp, self._basis.bases)):
for idim, (nodes, basis) in enumerate(
zip(nodes_tp, self._basis.bases, strict=True)):
# get current dimension's nodes
iaxis = (*(0,)*idim, slice(None), *(0,)*(self.dim-idim-1))
nodes = nodes[iaxis]
Expand Down Expand Up @@ -939,9 +940,8 @@ def default_simplex_group_factory(base_dim, order):
"""

try:
# recursivenodes is only importable in Python 3.8 since
# it uses :func:`math.comb`, so need to check if it can
# be imported.
# FIXME: this is a hard dependency (in pyproject.toml) now, so this
# shouldn't be needed
import recursivenodes # noqa: F401
except ImportError:
# If it cannot be imported, use warp-and-blend nodes.
Expand Down
Loading
Loading