From 9213af48e4f83541794a1998ac90917cb187f06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20S=2E=20Dokken?= Date: Tue, 5 Dec 2023 13:53:36 +0100 Subject: [PATCH] Sort imports for safe MPI initialization --- python/.isort.cfg | 8 ++++++++ python/benchmarks/bench_contact_3D.py | 10 ++++++---- python/benchmarks/bench_elasticity.py | 7 ++++--- python/benchmarks/bench_elasticity_edge.py | 7 ++++--- python/benchmarks/bench_periodic.py | 5 +++-- python/benchmarks/post_proc.py | 2 +- python/benchmarks/ref_elasticity.py | 5 +++-- python/benchmarks/ref_periodic.py | 7 ++++--- python/benchmarks/visualize_iterations.py | 12 +++++++----- python/demos/create_and_export_mesh.py | 3 ++- python/demos/demo_contact_2D.py | 9 +++++---- python/demos/demo_contact_3D.py | 7 ++++--- python/demos/demo_elasticity.py | 5 +++-- python/demos/demo_elasticity_disconnect.py | 3 ++- python/demos/demo_elasticity_disconnect_2D.py | 3 ++- python/demos/demo_periodic3d_topological.py | 3 ++- python/demos/demo_periodic_geometrical.py | 5 +++-- python/demos/demo_periodic_gep.py | 5 +++-- python/demos/demo_stokes.py | 8 +++++--- python/demos/demo_stokes_nest.py | 5 +++-- python/dolfinx_mpc/__init__.py | 9 ++++----- python/dolfinx_mpc/assemble_matrix.py | 3 ++- python/dolfinx_mpc/assemble_vector.py | 3 ++- python/dolfinx_mpc/multipointconstraint.py | 3 ++- python/dolfinx_mpc/numba/assemble_matrix.py | 6 ++++-- python/dolfinx_mpc/numba/assemble_vector.py | 3 ++- python/dolfinx_mpc/numba/helpers.py | 5 +++-- python/dolfinx_mpc/numba/numba_setup.py | 13 +++++++------ python/dolfinx_mpc/problem.py | 3 ++- python/dolfinx_mpc/utils/__init__.py | 8 ++++---- python/dolfinx_mpc/utils/mpc_utils.py | 5 +++-- python/dolfinx_mpc/utils/test.py | 11 +++++++---- python/setup.py | 4 ++-- python/tests/mwe123.py | 11 +++++++---- python/tests/nitsche_ufl.py | 3 ++- python/tests/test_cube_contact.py | 5 +++-- python/tests/test_integration_domains.py | 5 +++-- python/tests/test_lifting.py | 12 +++++++----- python/tests/test_linear_problem.py | 5 +++-- python/tests/test_matrix_assembly.py | 8 +++++--- python/tests/test_mpc_pipeline.py | 5 +++-- python/tests/test_nonlinear_assembly.py | 5 +++-- python/tests/test_rectangular_assembly.py | 7 ++++--- python/tests/test_surface_integral.py | 5 +++-- python/tests/test_vector_assembly.py | 10 ++++++---- python/tests/test_vector_poisson.py | 5 +++-- 46 files changed, 170 insertions(+), 111 deletions(-) create mode 100644 python/.isort.cfg diff --git a/python/.isort.cfg b/python/.isort.cfg new file mode 100644 index 00000000..029ab068 --- /dev/null +++ b/python/.isort.cfg @@ -0,0 +1,8 @@ +[settings] +src_paths = benchmarks,demos,dolfinx_mpc +known_first_party = dolfinx_mpc +known_third_party = basix,dolfinx,ffcx,ufl,gmsh,numba,numpy,pytest,pyvista +known_mpi = mpi4py,petsc4py +sections=FUTURE,STDLIB,MPI,THIRDPARTY,FIRSTPARTY,LOCALFOLDER + +sections=FUTURE,STDLIB,MPI,THIRDPARTY,FIRSTPARTY,LOCALFOLDER \ No newline at end of file diff --git a/python/benchmarks/bench_contact_3D.py b/python/benchmarks/bench_contact_3D.py index ae4d6287..e30bb6d4 100644 --- a/python/benchmarks/bench_contact_3D.py +++ b/python/benchmarks/bench_contact_3D.py @@ -8,12 +8,16 @@ # between two cubes. from __future__ import annotations +import warnings from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import basix.ufl import numpy as np -from dolfinx import default_scalar_type, default_real_type +from dolfinx import default_real_type, default_scalar_type from dolfinx.common import Timer, TimingType, list_timings, timing from dolfinx.cpp.mesh import entities_to_geometry from dolfinx.fem import (Constant, Function, dirichletbc, form, functionspace, @@ -22,8 +26,6 @@ from dolfinx.mesh import (CellType, compute_midpoints, create_mesh, create_unit_cube, locate_entities_boundary, meshtags, refine) -from mpi4py import MPI -from petsc4py import PETSc from ufl import (Cell, Identity, Mesh, TestFunction, TrialFunction, VectorElement, dx, grad, inner, sym, tr) @@ -31,7 +33,7 @@ assemble_vector) from dolfinx_mpc.utils import (create_normal_approximation, log_info, rigid_motions_nullspace, rotation_matrix) -import warnings + comm = MPI.COMM_WORLD if default_real_type == np.float32: diff --git a/python/benchmarks/bench_elasticity.py b/python/benchmarks/bench_elasticity.py index 65603246..0c07cff2 100644 --- a/python/benchmarks/bench_elasticity.py +++ b/python/benchmarks/bench_elasticity.py @@ -10,17 +10,18 @@ from pathlib import Path from typing import Optional +from mpi4py import MPI +from petsc4py import PETSc + import basix.ufl import h5py import numpy as np from dolfinx.common import Timer, TimingType, list_timings -from dolfinx.fem import (Constant, Function, functionspace, dirichletbc, form, +from dolfinx.fem import (Constant, Function, dirichletbc, form, functionspace, locate_dofs_topological, set_bc) from dolfinx.io import XDMFFile from dolfinx.mesh import (create_unit_cube, locate_entities_boundary, meshtags, refine) -from mpi4py import MPI -from petsc4py import PETSc from ufl import (Identity, TestFunction, TrialFunction, ds, dx, grad, inner, sym, tr) diff --git a/python/benchmarks/bench_elasticity_edge.py b/python/benchmarks/bench_elasticity_edge.py index dbe663c4..353725de 100644 --- a/python/benchmarks/bench_elasticity_edge.py +++ b/python/benchmarks/bench_elasticity_edge.py @@ -9,18 +9,19 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import basix.ufl import h5py import numpy as np from dolfinx import default_scalar_type from dolfinx.common import Timer, TimingType, list_timings -from dolfinx.fem import (Constant, Function, functionspace, dirichletbc, form, +from dolfinx.fem import (Constant, Function, dirichletbc, form, functionspace, locate_dofs_topological, set_bc) from dolfinx.io import XDMFFile from dolfinx.mesh import (CellType, create_unit_cube, locate_entities_boundary, meshtags) -from mpi4py import MPI -from petsc4py import PETSc from ufl import (Identity, SpatialCoordinate, TestFunction, TrialFunction, as_vector, ds, dx, grad, inner, sym, tr) diff --git a/python/benchmarks/bench_periodic.py b/python/benchmarks/bench_periodic.py index a7b446b0..461bc0c8 100644 --- a/python/benchmarks/bench_periodic.py +++ b/python/benchmarks/bench_periodic.py @@ -15,6 +15,9 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import h5py import numpy as np from dolfinx import default_scalar_type @@ -24,8 +27,6 @@ from dolfinx.io import XDMFFile from dolfinx.mesh import (CellType, create_unit_cube, locate_entities_boundary, meshtags) -from mpi4py import MPI -from petsc4py import PETSc from ufl import (SpatialCoordinate, TestFunction, TrialFunction, dx, exp, grad, inner, pi, sin) diff --git a/python/benchmarks/post_proc.py b/python/benchmarks/post_proc.py index 8fe9ba60..d4123b7b 100644 --- a/python/benchmarks/post_proc.py +++ b/python/benchmarks/post_proc.py @@ -1,7 +1,7 @@ from __future__ import annotations -import numpy as np import matplotlib.pyplot as plt +import numpy as np # Res 0.1 31776, 0.05 234546, 0.025 1801086, 0.02 3488856, 0.0175 5147961,0.015 7960200 dofs = [31776, 234546, 1801086, 3488856, 5147961, 7960200] diff --git a/python/benchmarks/ref_elasticity.py b/python/benchmarks/ref_elasticity.py index 70be41ee..d3e35c3d 100644 --- a/python/benchmarks/ref_elasticity.py +++ b/python/benchmarks/ref_elasticity.py @@ -11,6 +11,9 @@ from time import perf_counter from typing import Optional +from mpi4py import MPI +from petsc4py import PETSc + import basix.ufl import h5py import numpy as np @@ -24,8 +27,6 @@ from dolfinx.log import LogLevel, log, set_log_level from dolfinx.mesh import (CellType, create_unit_cube, locate_entities_boundary, meshtags, refine) -from mpi4py import MPI -from petsc4py import PETSc from ufl import (Identity, SpatialCoordinate, TestFunction, TrialFunction, as_vector, ds, dx, grad, inner, sym, tr) diff --git a/python/benchmarks/ref_periodic.py b/python/benchmarks/ref_periodic.py index 73317e43..be9fbdcc 100644 --- a/python/benchmarks/ref_periodic.py +++ b/python/benchmarks/ref_periodic.py @@ -21,19 +21,20 @@ from time import perf_counter from typing import Optional +from mpi4py import MPI +from petsc4py import PETSc + import h5py import numpy as np from dolfinx import default_scalar_type from dolfinx.common import Timer, TimingType, list_timings -from dolfinx.fem import (Function, functionspace, dirichletbc, form, +from dolfinx.fem import (Function, dirichletbc, form, functionspace, locate_dofs_geometrical) from dolfinx.fem.petsc import (apply_lifting, assemble_matrix, assemble_vector, set_bc) from dolfinx.io import XDMFFile from dolfinx.log import LogLevel, log, set_log_level from dolfinx.mesh import CellType, create_unit_cube, refine -from mpi4py import MPI -from petsc4py import PETSc from ufl import (SpatialCoordinate, TestFunction, TrialFunction, dx, exp, grad, inner, pi, sin) diff --git a/python/benchmarks/visualize_iterations.py b/python/benchmarks/visualize_iterations.py index a771eceb..5b0402f3 100644 --- a/python/benchmarks/visualize_iterations.py +++ b/python/benchmarks/visualize_iterations.py @@ -1,13 +1,15 @@ from __future__ import annotations -import matplotlib.pyplot as plt -from matplotlib.ticker import MaxNLocator, LogLocator, NullFormatter -import matplotlib.transforms as mtransforms -import h5py -import mpi4py import argparse import sys + +import mpi4py + +import h5py +import matplotlib.pyplot as plt +import matplotlib.transforms as mtransforms import numpy as np +from matplotlib.ticker import LogLocator, MaxNLocator, NullFormatter def visualize_elasticity(): diff --git a/python/demos/create_and_export_mesh.py b/python/demos/create_and_export_mesh.py index 80a657fa..98db1efb 100644 --- a/python/demos/create_and_export_mesh.py +++ b/python/demos/create_and_export_mesh.py @@ -3,6 +3,8 @@ from pathlib import Path from typing import Dict, List, Sequence, Tuple, Union +from mpi4py import MPI + import dolfinx.common as _common import dolfinx.cpp as _cpp import dolfinx.io as _io @@ -11,7 +13,6 @@ import numpy as np import ufl from dolfinx.io import gmshio -from mpi4py import MPI import dolfinx_mpc.utils as _utils diff --git a/python/demos/demo_contact_2D.py b/python/demos/demo_contact_2D.py index 3b770e4e..7e5e5dd0 100644 --- a/python/demos/demo_contact_2D.py +++ b/python/demos/demo_contact_2D.py @@ -17,10 +17,12 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import numpy as np import scipy.sparse.linalg -from create_and_export_mesh import gmsh_2D_stacked, mesh_2D_dolfin -from dolfinx import default_scalar_type, default_real_type +from dolfinx import default_real_type, default_scalar_type from dolfinx.common import Timer, TimingType, list_timings from dolfinx.fem import (Constant, dirichletbc, form, functionspace, locate_dofs_geometrical) @@ -29,11 +31,10 @@ from dolfinx.io import XDMFFile from dolfinx.log import LogLevel, set_log_level from dolfinx.mesh import locate_entities_boundary, meshtags -from mpi4py import MPI -from petsc4py import PETSc from ufl import (Identity, Measure, TestFunction, TrialFunction, dx, grad, inner, sym, tr) +from create_and_export_mesh import gmsh_2D_stacked, mesh_2D_dolfin from dolfinx_mpc import LinearProblem, MultiPointConstraint from dolfinx_mpc.utils import (compare_mpc_lhs, compare_mpc_rhs, create_normal_approximation, diff --git a/python/demos/demo_contact_3D.py b/python/demos/demo_contact_3D.py index 8eb6d991..ebf62d86 100644 --- a/python/demos/demo_contact_3D.py +++ b/python/demos/demo_contact_3D.py @@ -12,18 +12,19 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import numpy as np import scipy.sparse.linalg -from create_and_export_mesh import gmsh_3D_stacked, mesh_3D_dolfin from dolfinx import default_real_type, default_scalar_type from dolfinx.common import Timer, TimingType, list_timings from dolfinx.io import XDMFFile from dolfinx.mesh import CellType -from mpi4py import MPI -from petsc4py import PETSc from ufl import Identity, TestFunction, TrialFunction, dx, grad, inner, sym, tr +from create_and_export_mesh import gmsh_3D_stacked, mesh_3D_dolfin from dolfinx_mpc import (MultiPointConstraint, apply_lifting, assemble_matrix, assemble_vector) from dolfinx_mpc.utils import (compare_mpc_lhs, compare_mpc_rhs, diff --git a/python/demos/demo_elasticity.py b/python/demos/demo_elasticity.py index 9e38cd2e..b4a894fd 100644 --- a/python/demos/demo_elasticity.py +++ b/python/demos/demo_elasticity.py @@ -7,6 +7,9 @@ from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import numpy as np import scipy.sparse.linalg @@ -14,8 +17,6 @@ from dolfinx.common import Timer from dolfinx.io import XDMFFile from dolfinx.mesh import create_unit_square, locate_entities_boundary -from mpi4py import MPI -from petsc4py import PETSc from ufl import (Identity, SpatialCoordinate, TestFunction, TrialFunction, as_vector, dx, grad, inner, sym, tr) diff --git a/python/demos/demo_elasticity_disconnect.py b/python/demos/demo_elasticity_disconnect.py index 8510ff1a..8b4bb6bc 100644 --- a/python/demos/demo_elasticity_disconnect.py +++ b/python/demos/demo_elasticity_disconnect.py @@ -9,6 +9,8 @@ from pathlib import Path +from mpi4py import MPI + import basix.ufl import gmsh import numpy as np @@ -16,7 +18,6 @@ from dolfinx.fem import (Constant, Function, dirichletbc, functionspace, locate_dofs_topological) from dolfinx.io import XDMFFile, gmshio -from mpi4py import MPI from ufl import (Identity, Measure, SpatialCoordinate, TestFunction, TrialFunction, as_vector, grad, inner, sym, tr) diff --git a/python/demos/demo_elasticity_disconnect_2D.py b/python/demos/demo_elasticity_disconnect_2D.py index 7ebb78f4..2afa88a9 100644 --- a/python/demos/demo_elasticity_disconnect_2D.py +++ b/python/demos/demo_elasticity_disconnect_2D.py @@ -9,6 +9,8 @@ from pathlib import Path +from mpi4py import MPI + import gmsh import numpy as np from dolfinx import default_scalar_type @@ -17,7 +19,6 @@ locate_dofs_topological) from dolfinx.io import XDMFFile, gmshio from dolfinx.mesh import locate_entities_boundary -from mpi4py import MPI from ufl import (Identity, Measure, SpatialCoordinate, TestFunction, TrialFunction, grad, inner, sym, tr) diff --git a/python/demos/demo_periodic3d_topological.py b/python/demos/demo_periodic3d_topological.py index 1c9f21f2..807cb0de 100644 --- a/python/demos/demo_periodic3d_topological.py +++ b/python/demos/demo_periodic3d_topological.py @@ -19,6 +19,8 @@ from pathlib import Path from typing import Dict, Union +from mpi4py import MPI + import dolfinx.fem as fem import numpy as np import scipy.sparse.linalg @@ -27,7 +29,6 @@ from dolfinx.io import VTXWriter from dolfinx.mesh import (CellType, create_unit_cube, locate_entities_boundary, meshtags) -from mpi4py import MPI from numpy.typing import NDArray from ufl import (SpatialCoordinate, TestFunction, TrialFunction, as_vector, dx, exp, grad, inner, pi, sin) diff --git a/python/demos/demo_periodic_geometrical.py b/python/demos/demo_periodic_geometrical.py index d283c109..7dc5e6dd 100644 --- a/python/demos/demo_periodic_geometrical.py +++ b/python/demos/demo_periodic_geometrical.py @@ -15,6 +15,9 @@ from pathlib import Path from typing import Union +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import numpy as np import scipy.sparse.linalg @@ -22,8 +25,6 @@ from dolfinx.common import Timer, TimingType, list_timings from dolfinx.io import XDMFFile from dolfinx.mesh import create_unit_square, locate_entities_boundary -from mpi4py import MPI -from petsc4py import PETSc from ufl import (SpatialCoordinate, TestFunction, TrialFunction, as_vector, dx, exp, grad, inner, pi, sin) diff --git a/python/demos/demo_periodic_gep.py b/python/demos/demo_periodic_gep.py index c3f0ff02..345d2855 100755 --- a/python/demos/demo_periodic_gep.py +++ b/python/demos/demo_periodic_gep.py @@ -31,13 +31,14 @@ from pathlib import Path from typing import List, Tuple +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import numpy as np from dolfinx import default_scalar_type from dolfinx.io import XDMFFile from dolfinx.mesh import create_unit_square, locate_entities_boundary, meshtags -from mpi4py import MPI -from petsc4py import PETSc from slepc4py import SLEPc from ufl import TestFunction, TrialFunction, dx, grad, inner diff --git a/python/demos/demo_stokes.py b/python/demos/demo_stokes.py index b75157b6..46123406 100644 --- a/python/demos/demo_stokes.py +++ b/python/demos/demo_stokes.py @@ -14,21 +14,23 @@ from pathlib import Path from typing import Union +from mpi4py import MPI +from petsc4py import PETSc + import basix.ufl -import dolfinx_mpc.utils import gmsh import numpy as np import scipy.sparse.linalg from dolfinx import common, default_scalar_type, fem, io from dolfinx.io import gmshio -from mpi4py import MPI from numpy.typing import NDArray -from petsc4py import PETSc from ufl import (FacetNormal, Identity, Measure, TestFunctions, TrialFunctions, div, dot, dx, grad, inner, outer, sym) from ufl.core.expr import Expr +import dolfinx_mpc.utils from dolfinx_mpc import LinearProblem, MultiPointConstraint + # - # ## Mesh generation # diff --git a/python/demos/demo_stokes_nest.py b/python/demos/demo_stokes_nest.py index 58726710..311c5fc6 100644 --- a/python/demos/demo_stokes_nest.py +++ b/python/demos/demo_stokes_nest.py @@ -13,6 +13,9 @@ from pathlib import Path +from mpi4py import MPI +from petsc4py import PETSc + import basix import dolfinx.io import gmsh @@ -21,8 +24,6 @@ import ufl from dolfinx import default_scalar_type from dolfinx.io import gmshio -from mpi4py import MPI -from petsc4py import PETSc from ufl.core.expr import Expr import dolfinx_mpc diff --git a/python/dolfinx_mpc/__init__.py b/python/dolfinx_mpc/__init__.py index 573d218f..bf2574ca 100644 --- a/python/dolfinx_mpc/__init__.py +++ b/python/dolfinx_mpc/__init__.py @@ -11,14 +11,13 @@ import dolfinx_mpc.cpp # New local assemblies -from .assemble_matrix import assemble_matrix, create_matrix_nest, \ - assemble_matrix_nest, create_sparsity_pattern -from .assemble_vector import assemble_vector, apply_lifting, \ - assemble_vector_nest, create_vector_nest +from .assemble_matrix import (assemble_matrix, assemble_matrix_nest, + create_matrix_nest, create_sparsity_pattern) +from .assemble_vector import (apply_lifting, assemble_vector, + assemble_vector_nest, create_vector_nest) from .multipointconstraint import MultiPointConstraint from .problem import LinearProblem - __all__ = ["assemble_matrix", "create_matrix_nest", "assemble_matrix_nest", "assemble_vector", "apply_lifting", "assemble_vector_nest", "create_vector_nest", "MultiPointConstraint", "LinearProblem", diff --git a/python/dolfinx_mpc/assemble_matrix.py b/python/dolfinx_mpc/assemble_matrix.py index e7ba5e6c..b47bb33a 100644 --- a/python/dolfinx_mpc/assemble_matrix.py +++ b/python/dolfinx_mpc/assemble_matrix.py @@ -7,9 +7,10 @@ from typing import Optional, Sequence, Union +from petsc4py import PETSc as _PETSc + import dolfinx.cpp as _cpp import dolfinx.fem as _fem -from petsc4py import PETSc as _PETSc from dolfinx_mpc import cpp diff --git a/python/dolfinx_mpc/assemble_vector.py b/python/dolfinx_mpc/assemble_vector.py index d30ac265..ea24066f 100644 --- a/python/dolfinx_mpc/assemble_vector.py +++ b/python/dolfinx_mpc/assemble_vector.py @@ -8,12 +8,13 @@ import contextlib from typing import List, Optional, Sequence +from petsc4py import PETSc as _PETSc + import dolfinx.cpp as _cpp import dolfinx.fem as _fem import dolfinx.la as _la import ufl from dolfinx.common import Timer -from petsc4py import PETSc as _PETSc import dolfinx_mpc.cpp diff --git a/python/dolfinx_mpc/multipointconstraint.py b/python/dolfinx_mpc/multipointconstraint.py index 92242fcd..075d8454 100644 --- a/python/dolfinx_mpc/multipointconstraint.py +++ b/python/dolfinx_mpc/multipointconstraint.py @@ -7,13 +7,14 @@ from typing import Callable, Dict, List, Optional, Tuple, Union +from petsc4py import PETSc as _PETSc + import dolfinx.cpp as _cpp import dolfinx.fem as _fem import dolfinx.mesh as _mesh import numpy import numpy.typing as npt from dolfinx import default_scalar_type -from petsc4py import PETSc as _PETSc import dolfinx_mpc.cpp diff --git a/python/dolfinx_mpc/numba/assemble_matrix.py b/python/dolfinx_mpc/numba/assemble_matrix.py index 620a29e6..3b43f507 100644 --- a/python/dolfinx_mpc/numba/assemble_matrix.py +++ b/python/dolfinx_mpc/numba/assemble_matrix.py @@ -7,17 +7,19 @@ from typing import List, Optional, Tuple +from petsc4py import PETSc as _PETSc + import cffi +import dolfinx import dolfinx.cpp as _cpp import dolfinx.fem as _fem import numba import numpy import numpy.typing as npt -import dolfinx from dolfinx.common import Timer + from dolfinx_mpc.assemble_matrix import create_sparsity_pattern from dolfinx_mpc.multipointconstraint import MultiPointConstraint -from petsc4py import PETSc as _PETSc from .helpers import _bcs, _forms, extract_slave_cells, pack_slave_facet_info from .numba_setup import initialize_petsc, sink diff --git a/python/dolfinx_mpc/numba/assemble_vector.py b/python/dolfinx_mpc/numba/assemble_vector.py index 1e7655b9..2329f950 100644 --- a/python/dolfinx_mpc/numba/assemble_vector.py +++ b/python/dolfinx_mpc/numba/assemble_vector.py @@ -7,6 +7,8 @@ from typing import Optional, Tuple +from petsc4py import PETSc as _PETSc + import cffi import dolfinx import dolfinx.cpp as _cpp @@ -17,7 +19,6 @@ import numpy import numpy.typing as npt from dolfinx.common import Timer -from petsc4py import PETSc as _PETSc from dolfinx_mpc.multipointconstraint import MultiPointConstraint diff --git a/python/dolfinx_mpc/numba/helpers.py b/python/dolfinx_mpc/numba/helpers.py index f6fc2bba..5e87db23 100644 --- a/python/dolfinx_mpc/numba/helpers.py +++ b/python/dolfinx_mpc/numba/helpers.py @@ -5,11 +5,12 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from typing import Union + +import dolfinx.cpp as _cpp import numba import numpy import numpy.typing as npt -from typing import Union -import dolfinx.cpp as _cpp _forms = Union[_cpp.fem.Form_float32, _cpp.fem.Form_float64, _cpp.fem.Form_complex128] _bcs = Union[_cpp.fem.DirichletBC_float32, _cpp.fem.DirichletBC_float64, diff --git a/python/dolfinx_mpc/numba/numba_setup.py b/python/dolfinx_mpc/numba/numba_setup.py index 60a0798d..f3d43468 100644 --- a/python/dolfinx_mpc/numba/numba_setup.py +++ b/python/dolfinx_mpc/numba/numba_setup.py @@ -9,16 +9,17 @@ import ctypes.util import importlib import os - -import numba -import numba.core.typing.cffi_utils as cffi_support -import numpy as np import typing -import cffi + import petsc4py.lib from mpi4py import MPI -from petsc4py import get_config as PETSc_get_config from petsc4py import PETSc +from petsc4py import get_config as PETSc_get_config + +import cffi +import numba +import numba.core.typing.cffi_utils as cffi_support +import numpy as np def initialize_petsc() -> typing.Tuple[cffi.FFI, typing.Any]: diff --git a/python/dolfinx_mpc/problem.py b/python/dolfinx_mpc/problem.py index d2422b9d..d1bfa8c3 100644 --- a/python/dolfinx_mpc/problem.py +++ b/python/dolfinx_mpc/problem.py @@ -8,12 +8,13 @@ import typing +from petsc4py import PETSc + import dolfinx.fem.petsc import ufl from dolfinx import cpp as _cpp from dolfinx import fem as _fem from dolfinx import la as _la -from petsc4py import PETSc from .assemble_matrix import assemble_matrix, create_sparsity_pattern from .assemble_vector import apply_lifting, assemble_vector diff --git a/python/dolfinx_mpc/utils/__init__.py b/python/dolfinx_mpc/utils/__init__.py index 3f91e69a..73fc5044 100644 --- a/python/dolfinx_mpc/utils/__init__.py +++ b/python/dolfinx_mpc/utils/__init__.py @@ -8,13 +8,13 @@ # flake8: noqa from __future__ import annotations +from .mpc_utils import (create_normal_approximation, + create_point_to_point_constraint, + determine_closest_block, facet_normal_approximation, + log_info, rigid_motions_nullspace, rotation_matrix) from .test import (compare_CSR, compare_mpc_lhs, compare_mpc_rhs, gather_constants, gather_PETScMatrix, gather_PETScVector, gather_transformation_matrix, get_assemblers) -from .mpc_utils import (create_normal_approximation, - create_point_to_point_constraint, determine_closest_block, - facet_normal_approximation, log_info, - rigid_motions_nullspace, rotation_matrix) __all__ = ["get_assemblers", "gather_PETScVector", "gather_PETScMatrix", "compare_mpc_lhs", "compare_mpc_rhs", "gather_transformation_matrix", "compare_CSR", "gather_constants", diff --git a/python/dolfinx_mpc/utils/mpc_utils.py b/python/dolfinx_mpc/utils/mpc_utils.py index f0f39601..576fda95 100644 --- a/python/dolfinx_mpc/utils/mpc_utils.py +++ b/python/dolfinx_mpc/utils/mpc_utils.py @@ -7,6 +7,9 @@ from contextlib import ExitStack +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.common as _common import dolfinx.cpp as _cpp import dolfinx.fem as _fem @@ -17,8 +20,6 @@ import numpy as np import ufl from dolfinx import default_scalar_type as _dt -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc.cpp diff --git a/python/dolfinx_mpc/utils/test.py b/python/dolfinx_mpc/utils/test.py index 699d98b7..d70b7934 100644 --- a/python/dolfinx_mpc/utils/test.py +++ b/python/dolfinx_mpc/utils/test.py @@ -8,14 +8,17 @@ __all__ = ["gather_PETScVector", "gather_PETScMatrix", "compare_mpc_lhs", "compare_mpc_rhs", "gather_transformation_matrix", "compare_CSR"] -import pytest -import numpy as np +from typing import Any + from mpi4py import MPI from petsc4py import PETSc + +import dolfinx.common +import numpy as np +import pytest import scipy.sparse + import dolfinx_mpc -import dolfinx.common -from typing import Any @pytest.fixture diff --git a/python/setup.py b/python/setup.py index f8fdf170..27dc636a 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,11 +1,11 @@ import os -import shlex import platform import re +import shlex import subprocess import sys -from itertools import chain from distutils.version import LooseVersion +from itertools import chain from setuptools import Extension, setup from setuptools.command.build_ext import build_ext diff --git a/python/tests/mwe123.py b/python/tests/mwe123.py index 8d3c46b2..2154c9a0 100644 --- a/python/tests/mwe123.py +++ b/python/tests/mwe123.py @@ -1,10 +1,13 @@ from __future__ import annotations -from dolfinx.mesh import create_unit_square, locate_entities_boundary, meshtags -from dolfinx import default_scalar_type -from dolfinx import fem -import dolfinx_mpc + from mpi4py import MPI + import numpy as np +from dolfinx import default_scalar_type, fem +from dolfinx.mesh import create_unit_square, locate_entities_boundary, meshtags + +import dolfinx_mpc + mesh = create_unit_square(MPI.COMM_WORLD, 1, 1) V = fem.functionspace(mesh, ("Lagrange", 1)) diff --git a/python/tests/nitsche_ufl.py b/python/tests/nitsche_ufl.py index abd4fc8e..f53379e4 100644 --- a/python/tests/nitsche_ufl.py +++ b/python/tests/nitsche_ufl.py @@ -5,6 +5,8 @@ from typing import Dict, Tuple +from petsc4py import PETSc as _PETSc + import numpy as np import ufl from dolfinx import common as _common @@ -14,7 +16,6 @@ from dolfinx import nls as _nls from dolfinx_contact.helpers import (R_minus, epsilon, lame_parameters, rigid_motions_nullspace, sigma_func) -from petsc4py import PETSc as _PETSc __all__ = ["nitsche_ufl"] diff --git a/python/tests/test_cube_contact.py b/python/tests/test_cube_contact.py index 88bd2e2e..cfd75eaa 100644 --- a/python/tests/test_cube_contact.py +++ b/python/tests/test_cube_contact.py @@ -8,6 +8,9 @@ # between two cubes. from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import gmsh import numpy as np @@ -17,8 +20,6 @@ from dolfinx import default_scalar_type from dolfinx.common import Timer, TimingType, list_timings from dolfinx.io import gmshio -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc import dolfinx_mpc.utils diff --git a/python/tests/test_integration_domains.py b/python/tests/test_integration_domains.py index cafab4d8..05dedb0f 100644 --- a/python/tests/test_integration_domains.py +++ b/python/tests/test_integration_domains.py @@ -5,6 +5,9 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import numpy as np import pytest import scipy.sparse.linalg @@ -12,8 +15,6 @@ from dolfinx import default_scalar_type, fem from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import compute_midpoints, create_unit_square, meshtags -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc from dolfinx_mpc.utils import get_assemblers # noqa: F401 diff --git a/python/tests/test_lifting.py b/python/tests/test_lifting.py index 186ac8d9..b86637fe 100644 --- a/python/tests/test_lifting.py +++ b/python/tests/test_lifting.py @@ -5,18 +5,20 @@ # SPDX-License-Identifier: MIT from __future__ import annotations -from dolfinx import fem -import dolfinx_mpc -import dolfinx_mpc.utils +from mpi4py import MPI +from petsc4py import PETSc + import numpy as np import pytest import scipy.sparse.linalg import ufl +from dolfinx import fem from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import CellType, create_unit_square + +import dolfinx_mpc +import dolfinx_mpc.utils from dolfinx_mpc.utils import get_assemblers # noqa: F401 -from mpi4py import MPI -from petsc4py import PETSc @pytest.mark.skipif(MPI.COMM_WORLD.size > 1, diff --git a/python/tests/test_linear_problem.py b/python/tests/test_linear_problem.py index 2942fb16..33f80383 100644 --- a/python/tests/test_linear_problem.py +++ b/python/tests/test_linear_problem.py @@ -5,14 +5,15 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import numpy as np import pytest import scipy.sparse.linalg import ufl from dolfinx import default_scalar_type, fem from dolfinx.mesh import create_unit_square, locate_entities_boundary, meshtags -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc import dolfinx_mpc.utils diff --git a/python/tests/test_matrix_assembly.py b/python/tests/test_matrix_assembly.py index f446f8c5..ee723ff3 100644 --- a/python/tests/test_matrix_assembly.py +++ b/python/tests/test_matrix_assembly.py @@ -5,16 +5,18 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI + import dolfinx.fem as fem -import dolfinx_mpc -import dolfinx_mpc.utils import numpy as np import pytest import ufl from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import CellType, create_unit_square + +import dolfinx_mpc +import dolfinx_mpc.utils from dolfinx_mpc.utils import get_assemblers # noqa: F401 -from mpi4py import MPI root = 0 diff --git a/python/tests/test_mpc_pipeline.py b/python/tests/test_mpc_pipeline.py index c5bccb65..54051c46 100644 --- a/python/tests/test_mpc_pipeline.py +++ b/python/tests/test_mpc_pipeline.py @@ -5,6 +5,9 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import numpy as np import pytest import scipy.sparse.linalg @@ -12,8 +15,6 @@ from dolfinx import default_scalar_type, fem from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import create_unit_square -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc import dolfinx_mpc.utils diff --git a/python/tests/test_nonlinear_assembly.py b/python/tests/test_nonlinear_assembly.py index b14d7f9e..4c8fab9d 100644 --- a/python/tests/test_nonlinear_assembly.py +++ b/python/tests/test_nonlinear_assembly.py @@ -5,6 +5,9 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import basix import dolfinx import dolfinx.fem.petsc @@ -13,8 +16,6 @@ import numpy as np import pytest import ufl -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc diff --git a/python/tests/test_rectangular_assembly.py b/python/tests/test_rectangular_assembly.py index fa3222c7..47e055f8 100644 --- a/python/tests/test_rectangular_assembly.py +++ b/python/tests/test_rectangular_assembly.py @@ -5,18 +5,19 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import basix import dolfinx import dolfinx.fem import dolfinx.mesh -import dolfinx_mpc.utils import numpy as np import pytest import ufl -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc +import dolfinx_mpc.utils @pytest.mark.parametrize("cell_type", diff --git a/python/tests/test_surface_integral.py b/python/tests/test_surface_integral.py index cda4fe09..cfb06086 100644 --- a/python/tests/test_surface_integral.py +++ b/python/tests/test_surface_integral.py @@ -5,6 +5,9 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import numpy as np import pytest @@ -13,8 +16,6 @@ from dolfinx import default_scalar_type from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import create_unit_square, locate_entities_boundary, meshtags -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc import dolfinx_mpc.utils diff --git a/python/tests/test_vector_assembly.py b/python/tests/test_vector_assembly.py index a13b75a3..9c3a29ea 100644 --- a/python/tests/test_vector_assembly.py +++ b/python/tests/test_vector_assembly.py @@ -5,17 +5,19 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem -import dolfinx_mpc -import dolfinx_mpc.utils import numpy as np import pytest import ufl from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import CellType, create_unit_square + +import dolfinx_mpc +import dolfinx_mpc.utils from dolfinx_mpc.utils import get_assemblers # noqa: F401 -from mpi4py import MPI -from petsc4py import PETSc @pytest.mark.parametrize("get_assemblers", ["C++", "numba"], indirect=True) diff --git a/python/tests/test_vector_poisson.py b/python/tests/test_vector_poisson.py index c97e0d92..1e265a77 100644 --- a/python/tests/test_vector_poisson.py +++ b/python/tests/test_vector_poisson.py @@ -5,6 +5,9 @@ # SPDX-License-Identifier: MIT from __future__ import annotations +from mpi4py import MPI +from petsc4py import PETSc + import dolfinx.fem as fem import numpy as np import pytest @@ -13,8 +16,6 @@ from dolfinx import default_scalar_type from dolfinx.common import Timer, TimingType, list_timings from dolfinx.mesh import create_unit_square -from mpi4py import MPI -from petsc4py import PETSc import dolfinx_mpc import dolfinx_mpc.utils