Skip to content

Commit

Permalink
general: enable and fix flake8-isort issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Mar 5, 2024
1 parent f840754 commit bd17454
Show file tree
Hide file tree
Showing 55 changed files with 521 additions and 576 deletions.
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from urllib.request import urlopen


_conf_url = \
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
with urlopen(_conf_url) as _inf:
Expand Down Expand Up @@ -54,4 +55,5 @@
# why this name is as global-sounding as it is.
import sys


sys._BUILDING_SPHINX_DOCS = True
7 changes: 4 additions & 3 deletions examples/from_firedrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def main(visualize=True):
except ImportError:
return 0

from meshmode.interop.firedrake import build_connection_from_firedrake
from firedrake import (
UnitSquareMesh, FunctionSpace, SpatialCoordinate, Function, cos
)
Function, FunctionSpace, SpatialCoordinate, UnitSquareMesh, cos)

from meshmode.interop.firedrake import build_connection_from_firedrake

# Create a firedrake mesh and interpolate cos(x+y) onto it
fd_mesh = UnitSquareMesh(10, 10)
Expand All @@ -62,6 +62,7 @@ def main(visualize=True):

# Plot the meshmode meshes that the connections connect to
import matplotlib.pyplot as plt

from meshmode.mesh.visualization import draw_2d_mesh
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.set_title("FiredrakeConnection")
Expand Down
3 changes: 2 additions & 1 deletion examples/mesh-to-tikz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from meshmode.mesh.io import generate_gmsh, FileSource
from meshmode.mesh.io import FileSource, generate_gmsh
from meshmode.mesh.visualization import mesh_to_tikz


h = 0.3
order = 1

Expand Down
8 changes: 5 additions & 3 deletions examples/moving-geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
THE SOFTWARE.
"""

import logging
from typing import Optional, Type

import numpy as np

import pyopencl as cl
from pytools import keyed_memoize_in
from pytools.obj_array import make_obj_array

from meshmode.array_context import PyOpenCLArrayContext
from meshmode.transform_metadata import FirstAxisIsElementsTag

from pytools import keyed_memoize_in
from pytools.obj_array import make_obj_array

import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -121,6 +122,7 @@ def run(actx, *,
# {{{ element groups

import modepy as mp

import meshmode.discretization.poly_element as poly

# NOTE: picking the same unit nodes for the mesh and the discr saves
Expand Down
6 changes: 3 additions & 3 deletions examples/multiple-meshes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import numpy as np # noqa
import sys

import numpy as np # noqa


order = 4


def main():
from meshmode.mesh.generation import ( # noqa
make_curve_mesh, starfish)
from meshmode.mesh.generation import make_curve_mesh, starfish # noqa
mesh1 = make_curve_mesh(starfish, np.linspace(0, 1, 20), 4)

from meshmode.mesh.processing import affine_map, merge_disjoint_meshes
Expand Down
4 changes: 3 additions & 1 deletion examples/parallel-vtkhdf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging

import numpy as np

from meshmode.mesh import Mesh


logger = logging.getLogger(__file__)


Expand Down Expand Up @@ -33,8 +35,8 @@ def main(*, ambient_dim: int) -> None:
from mpi4py import MPI
comm = MPI.COMM_WORLD

from meshmode.mesh.processing import partition_mesh
from meshmode.distributed import membership_list_to_map
from meshmode.mesh.processing import partition_mesh

order = 5
nelements = 64 if ambient_dim == 3 else 256
Expand Down
13 changes: 7 additions & 6 deletions examples/plot-connectivity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np # noqa

import pyopencl as cl

from meshmode.array_context import PyOpenCLArrayContext


order = 4


Expand All @@ -12,15 +14,15 @@ def main():
actx = PyOpenCLArrayContext(queue)

from meshmode.mesh.generation import ( # noqa: F401
generate_sphere, generate_icosahedron,
generate_torus)
generate_icosahedron, generate_sphere, generate_torus)

#mesh = generate_sphere(1, order=order)
mesh = generate_icosahedron(1, order=order)
#mesh = generate_torus(3, 1, order=order)

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import \
PolynomialWarpAndBlend3DRestrictingGroupFactory
from meshmode.discretization.poly_element import (
PolynomialWarpAndBlend3DRestrictingGroupFactory)

discr = Discretization(
actx, mesh, PolynomialWarpAndBlend3DRestrictingGroupFactory(order))
Expand All @@ -32,8 +34,7 @@ def main():
("f", actx.thaw(discr.nodes()[0])),
])

from meshmode.discretization.visualization import \
write_nodal_adjacency_vtk_file
from meshmode.discretization.visualization import write_nodal_adjacency_vtk_file

write_nodal_adjacency_vtk_file("adjacency.vtu",
mesh)
Expand Down
38 changes: 17 additions & 21 deletions examples/simple-dg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,26 @@
THE SOFTWARE.
"""

import logging
from dataclasses import dataclass

import numpy as np
import numpy.linalg as la # noqa

import pyopencl as cl
import pyopencl.array as cla # noqa

from pytools import memoize_method, log_process
from arraycontext import (
ArrayContainer, dataclass_array_container, map_array_container,
with_container_arithmetic)
from pytools import log_process, memoize_method
from pytools.obj_array import flat_obj_array, make_obj_array

from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa
from meshmode.array_context import PyOpenCLArrayContext, PytatoPyOpenCLArrayContext
from meshmode.dof_array import DOFArray, flat_norm
from meshmode.array_context import (PyOpenCLArrayContext,
PytatoPyOpenCLArrayContext)
from arraycontext import (
ArrayContainer,
map_array_container,
with_container_arithmetic,
dataclass_array_container,
)
from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa
from meshmode.transform_metadata import FirstAxisIsElementsTag

import logging

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -73,8 +70,8 @@ def __init__(self, actx, mesh, order):
self.order = order

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import \
PolynomialWarpAndBlend2DRestrictingGroupFactory
from meshmode.discretization.poly_element import (
PolynomialWarpAndBlend2DRestrictingGroupFactory)
self.group_factory = PolynomialWarpAndBlend2DRestrictingGroupFactory(
order=order)
self.volume_discr = Discretization(actx, mesh, self.group_factory)
Expand Down Expand Up @@ -103,7 +100,7 @@ def boundary_connection(self, boundary_tag):
@memoize_method
def interior_faces_connection(self):
from meshmode.discretization.connection import (
make_face_restriction, FACE_RESTR_INTERIOR)
FACE_RESTR_INTERIOR, make_face_restriction)
return make_face_restriction(
self.volume_discr._setup_actx,
self.volume_discr,
Expand All @@ -113,16 +110,15 @@ def interior_faces_connection(self):

@memoize_method
def opposite_face_connection(self):
from meshmode.discretization.connection import \
make_opposite_face_connection
from meshmode.discretization.connection import make_opposite_face_connection

return make_opposite_face_connection(
self._setup_actx, self.interior_faces_connection())

@memoize_method
def all_faces_connection(self):
from meshmode.discretization.connection import (
make_face_restriction, FACE_RESTR_ALL)
FACE_RESTR_ALL, make_face_restriction)
return make_face_restriction(
self.volume_discr._setup_actx,
self.volume_discr,
Expand All @@ -132,8 +128,8 @@ def all_faces_connection(self):

@memoize_method
def get_to_all_face_embedding(self, where):
from meshmode.discretization.connection import \
make_face_to_all_faces_embedding
from meshmode.discretization.connection import (
make_face_to_all_faces_embedding)

faces_conn = self.get_connection("vol", where)
return make_face_to_all_faces_embedding(
Expand Down Expand Up @@ -277,7 +273,7 @@ def get_local_face_mass_matrix(self, afgrp, volgrp, dtype):
shape = mp.Simplex(volgrp.dim)

for face in mp.faces_for_shape(shape):
from modepy import basis_for_space, quadrature_for_space, PN, Simplex
from modepy import PN, Simplex, basis_for_space, quadrature_for_space
face_space = PN(volgrp.dim - 1, volgrp.order)
face_shape = Simplex(volgrp.dim-1)
face_quad = quadrature_for_space(face_space, face_shape)
Expand Down
9 changes: 5 additions & 4 deletions examples/to_firedrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


import numpy as np

import pyopencl as cl

from meshmode.array_context import PyOpenCLArrayContext
Expand Down Expand Up @@ -63,8 +64,8 @@ def main():
order = 3

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import \
InterpolatoryQuadratureSimplexGroupFactory
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory)
group_factory = InterpolatoryQuadratureSimplexGroupFactory(order=order)
discr = Discretization(actx, mesh, group_factory)

Expand All @@ -91,8 +92,8 @@ def main():

# set up dirichlet laplace problem in fd and solve
from firedrake import (
FunctionSpace, TrialFunction, TestFunction, Function, inner, grad, dx,
Constant, project, DirichletBC, solve)
Constant, DirichletBC, Function, FunctionSpace, TestFunction, TrialFunction,
dx, grad, inner, project, solve)

# because it's easier to write down the variational problem,
# we're going to project from our "DG" space
Expand Down
13 changes: 7 additions & 6 deletions examples/tp-lagrange-stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

import numpy as np
import numpy.linalg as la

import modepy
import pyopencl as cl
from meshmode.array_context import PyOpenCLArrayContext
import meshmode.mesh.generation as mgen
import meshmode.discretization.poly_element as poly

import meshmode.discretization.connection as conn
import meshmode.discretization.poly_element as poly
import meshmode.mesh.generation as mgen
from meshmode.array_context import PyOpenCLArrayContext
from meshmode.discretization import Discretization
from meshmode.mesh import Mesh, BTAG_ALL

import modepy
from meshmode.mesh import BTAG_ALL, Mesh


def main():
Expand Down
2 changes: 2 additions & 0 deletions meshmode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"""

from builtins import FileExistsError # noqa: F401

from meshmode.mesh.tools import AffineMap # noqa: F401


Expand All @@ -53,6 +54,7 @@ def _acf():
argument when running them from the command line.
"""
import pyopencl as cl

from meshmode.array_context import PyOpenCLArrayContext

context = cl._csc()
Expand Down
19 changes: 10 additions & 9 deletions meshmode/array_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@

import sys
from warnings import warn
from arraycontext import PyOpenCLArrayContext as PyOpenCLArrayContextBase
from arraycontext import PytatoPyOpenCLArrayContext as PytatoPyOpenCLArrayContextBase

from arraycontext import (
PyOpenCLArrayContext as PyOpenCLArrayContextBase,
PytatoPyOpenCLArrayContext as PytatoPyOpenCLArrayContextBase)
from arraycontext.pytest import (
_PytestPyOpenCLArrayContextFactoryWithClass,
_PytestPytatoPyOpenCLArrayContextFactory,
register_pytest_array_context_factory)
_PytestPyOpenCLArrayContextFactoryWithClass,
_PytestPytatoPyOpenCLArrayContextFactory, register_pytest_array_context_factory)


def thaw(actx, ary):
Expand All @@ -48,11 +49,11 @@ def thaw(actx, ary):

def _transform_loopy_inner(t_unit):
import loopy as lp
from meshmode.transform_metadata import FirstAxisIsElementsTag
from arraycontext.transform_metadata import ElementwiseMapKernelTag

from pymbolic.primitives import Subscript, Variable

from meshmode.transform_metadata import FirstAxisIsElementsTag

default_ep = t_unit.default_entrypoint

# FIXME: Firedrake branch lacks kernel tags
Expand Down Expand Up @@ -155,8 +156,8 @@ def _transform_loopy_inner(t_unit):

# {{{ element/dof iname tag

from meshmode.transform_metadata import \
ConcurrentElementInameTag, ConcurrentDOFInameTag
from meshmode.transform_metadata import (
ConcurrentDOFInameTag, ConcurrentElementInameTag)
el_inames = [iname.name
for iname in default_ep.inames.values()
if ConcurrentElementInameTag() in iname.tags]
Expand Down
15 changes: 6 additions & 9 deletions meshmode/discretization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,22 @@
"""

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

import numpy as np

import loopy as lp
from arraycontext import ArrayContext, make_loopy_program, tag_axes
from pytools import memoize_in, memoize_method, keyed_memoize_in
from pytools import keyed_memoize_in, memoize_in, memoize_method
from pytools.obj_array import make_obj_array
from meshmode.transform_metadata import (
ConcurrentElementInameTag, ConcurrentDOFInameTag,
FirstAxisIsElementsTag, DiscretizationElementAxisTag,
DiscretizationDOFAxisTag)

# underscored because it shouldn't be imported from here.
from meshmode.dof_array import DOFArray as _DOFArray
from meshmode.mesh import (
Mesh as _Mesh,
MeshElementGroup as _MeshElementGroup)
from meshmode.mesh import Mesh as _Mesh, MeshElementGroup as _MeshElementGroup
from meshmode.transform_metadata import (
ConcurrentDOFInameTag, ConcurrentElementInameTag, DiscretizationDOFAxisTag,
DiscretizationElementAxisTag, FirstAxisIsElementsTag)


__doc__ = """
Expand Down
Loading

0 comments on commit bd17454

Please sign in to comment.