From 97d37cb51d36650f217d307f0f33b666819ee48e Mon Sep 17 00:00:00 2001 From: Pierre Marchand Date: Tue, 30 Jan 2024 11:46:20 +0100 Subject: [PATCH] fixup format --- .github/workflows/CI.yml | 13 ++--------- example/ddm_solver.py | 3 +-- example/define_custom_local_operator.py | 2 +- ..._block_jacobi_solver_with_default_build.py | 3 +-- ...ock_jacobi_solver_with_no_default_build.py | 3 +-- example/use_cluster_with_given_partition.py | 3 +-- example/use_custom_dense_block_generator.py | 3 +-- example/use_custom_local_operator.py | 3 +-- example/use_default_build.py | 4 +--- example/use_local_build.py | 4 +--- example/use_no_default_build.py | 3 +-- pyproject.toml | 22 ++++++++++++++----- setup.py | 14 +++++++----- tests/conftest.py | 6 +++-- tests/test_cluster.py | 3 +-- tests/test_ddm_solver.py | 16 +------------- tests/test_distributed_operator.py | 3 --- 17 files changed, 44 insertions(+), 64 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0ad0519..63c27b1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -153,18 +153,9 @@ jobs: make cmake-format git diff --exit-code - - name: Check module imports with isort - if: matrix.CODE_COVERAGE == 'ON' + - name: Check with ruff run: | - python3 -m pip install isort - python3 -m isort example --check-only --diff - python3 -m isort tests --check-only --diff - - - name: Check formatting with black - if: matrix.CODE_COVERAGE == 'ON' - uses: psf/black@stable - with: - src: "./example ./tests" + ruff . - name: Generate coverage reports if: matrix.CODE_COVERAGE == 'ON' diff --git a/example/ddm_solver.py b/example/ddm_solver.py index df9e342..8dd208d 100644 --- a/example/ddm_solver.py +++ b/example/ddm_solver.py @@ -1,11 +1,10 @@ +import Htool import matplotlib.pyplot as plt import mpi4py import numpy as np from create_geometry import create_random_geometries from define_custom_generators import CustomGeneratorWithPermutation -import Htool - # Random geometry size = 500 dimension = 3 diff --git a/example/define_custom_local_operator.py b/example/define_custom_local_operator.py index f1c441b..c28c4ce 100644 --- a/example/define_custom_local_operator.py +++ b/example/define_custom_local_operator.py @@ -29,7 +29,7 @@ def __init__( def add_vector_product( self, trans, alpha, input: np.array, beta, output: np.array ) -> None: - # Beware, you need to use inplace operation for output to keep the underlying data + # Beware, inplace operation needed for output to keep the underlying data output *= beta if trans == "N": output += alpha * self.data.dot(input) diff --git a/example/use_block_jacobi_solver_with_default_build.py b/example/use_block_jacobi_solver_with_default_build.py index cbd40a0..d7352ed 100644 --- a/example/use_block_jacobi_solver_with_default_build.py +++ b/example/use_block_jacobi_solver_with_default_build.py @@ -1,11 +1,10 @@ +import Htool import matplotlib.pyplot as plt import mpi4py import numpy as np from create_geometry import create_random_geometries from define_custom_generators import CustomGenerator -import Htool - # Random geometry size = 500 dimension = 3 diff --git a/example/use_block_jacobi_solver_with_no_default_build.py b/example/use_block_jacobi_solver_with_no_default_build.py index 7658b1f..e5ccc11 100644 --- a/example/use_block_jacobi_solver_with_no_default_build.py +++ b/example/use_block_jacobi_solver_with_no_default_build.py @@ -1,11 +1,10 @@ +import Htool import matplotlib.pyplot as plt import mpi4py import numpy as np from create_geometry import create_partitionned_geometries from define_custom_generators import CustomGenerator -import Htool - # Random geometry size = 500 dimension = 3 diff --git a/example/use_cluster_with_given_partition.py b/example/use_cluster_with_given_partition.py index 279e44a..2306eae 100644 --- a/example/use_cluster_with_given_partition.py +++ b/example/use_cluster_with_given_partition.py @@ -1,9 +1,8 @@ +import Htool import matplotlib.pyplot as plt import mpi4py from create_geometry import create_partitionned_geometries -import Htool - # Random geometry nb_rows = 500 nb_cols = 500 diff --git a/example/use_custom_dense_block_generator.py b/example/use_custom_dense_block_generator.py index 83fa788..5514172 100644 --- a/example/use_custom_dense_block_generator.py +++ b/example/use_custom_dense_block_generator.py @@ -1,11 +1,10 @@ +import Htool import mpi4py import numpy as np from create_geometry import create_partitionned_geometries from define_custom_dense_blocks_generator import CustomDenseBlocksGenerator from define_custom_generators import CustomGenerator -import Htool - # Random geometry nb_rows = 500 nb_cols = 500 diff --git a/example/use_custom_local_operator.py b/example/use_custom_local_operator.py index 29fb0c6..9d952d3 100644 --- a/example/use_custom_local_operator.py +++ b/example/use_custom_local_operator.py @@ -1,11 +1,10 @@ +import Htool import mpi4py import numpy as np from create_geometry import create_partitionned_geometries from define_custom_generators import CustomGenerator from define_custom_local_operator import CustomLocalOperator -import Htool - # Random geometry nb_rows = 500 nb_cols = 500 diff --git a/example/use_default_build.py b/example/use_default_build.py index 1697cc0..e8278af 100644 --- a/example/use_default_build.py +++ b/example/use_default_build.py @@ -1,12 +1,10 @@ - +import Htool import matplotlib.pyplot as plt import mpi4py import numpy as np from create_geometry import create_partitionned_geometries from define_custom_generators import CustomGenerator -import Htool - # Random geometry nb_rows = 500 nb_cols = 500 diff --git a/example/use_local_build.py b/example/use_local_build.py index 9b365c9..2607705 100644 --- a/example/use_local_build.py +++ b/example/use_local_build.py @@ -1,4 +1,4 @@ - +import Htool import matplotlib.pyplot as plt import mpi4py import numpy as np @@ -6,8 +6,6 @@ from define_custom_generators import CustomGenerator from define_custom_local_operator import CustomLocalOperator -import Htool - # Random geometry target_size = 500 source_size = 500 diff --git a/example/use_no_default_build.py b/example/use_no_default_build.py index 6cf07eb..6d1b1c8 100644 --- a/example/use_no_default_build.py +++ b/example/use_no_default_build.py @@ -1,11 +1,10 @@ +import Htool import matplotlib.pyplot as plt import mpi4py import numpy as np from create_geometry import create_partitionned_geometries from define_custom_generators import CustomGenerator -import Htool - # Random geometry nb_rows = 500 nb_cols = 500 diff --git a/pyproject.toml b/pyproject.toml index b04bc03..15936f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,13 +29,25 @@ test = ["matplotlib>=3.0.0", "pytest"] "Homepage" = "https://github.com/htool-ddm/htool_python" "Bug Tracker" = "https://github.com/htool-ddm/htool_python/issues" -[tool.black] +[tool.ruff] line-length = 88 +indent-width = 4 +exclude = ["lib", "cmake-format.py"] + +[tool.ruff.lint] +select = [ + "E", # pycodestyle + "F", # Pyflakes + "UP", # pyupgrade + "B", # flake8-bugbear + "SIM", # flake8-simplify + "I", # isort +] +ignore = [] -[tool.isort] -profile = "black" -known_local_folder = 'Htool,example' -skip = "lib" +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] [build-system] diff --git a/setup.py b/setup.py index ae6b1b2..5732f45 100644 --- a/setup.py +++ b/setup.py @@ -101,12 +101,16 @@ def build_extension(self, ext): # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level # across all generators. - if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: + if ( + "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ + and hasattr(self, "parallel") + and self.parallel + ): # self.parallel is a Python 3 only way to set parallel jobs by hand # using -j in the build_ext call, not supported by pip or PyPA-build. - if hasattr(self, "parallel") and self.parallel: - # CMake 3.12+ only. - build_args += [f"-j{self.parallel}"] + + # CMake 3.12+ only. + build_args += [f"-j{self.parallel}"] build_temp = Path(self.build_temp) / ext.name if not build_temp.exists(): @@ -161,7 +165,7 @@ def build_extension(self, ext): version="0.9.0", author="Pierre Marchand", author_email="", - description="A pybind11 interface to Htool, a header only c++ library that provides Hierarchical matrices.", + description="""A pybind11 interface to Htool.""", long_description="", ext_modules=[CMakeExtension("Htool")], cmdclass=dict(build_ext=CMakeBuild), diff --git a/tests/conftest.py b/tests/conftest.py index 8f0dafe..f7db6e7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -306,7 +306,7 @@ def load_data_solver(symmetry, mu): "rb", ) as input: data = input.read() - l = struct.unpack("@I", data[:4]) + # l = struct.unpack("@I", data[:4]) rhs = np.frombuffer(data[4:], dtype=np.dtype("complex128")) f = np.zeros(len(rhs), dtype="complex128") if mu > 1: @@ -375,7 +375,9 @@ def load_data_solver(symmetry, mu): (m, n) = struct.unpack("@II", data[:8]) # print(m,n) local_neumann_matrix = np.frombuffer(data[8:], dtype=np.dtype("complex128")) - local_neumann_matrix = np.transpose(local_neumann_matrix.reshape((m, n),order='C')).copy("F") + local_neumann_matrix = np.transpose( + local_neumann_matrix.reshape((m, n), order="C") + ).copy("F") return [ A, x_ref, diff --git a/tests/test_cluster.py b/tests/test_cluster.py index 64ea810..f2266a0 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1,9 +1,8 @@ +import Htool import matplotlib.pyplot as plt import mpi4py import pytest -import Htool - @pytest.mark.parametrize( "dimension,nb_rows,nb_cols,symmetry,is_partition_given", diff --git a/tests/test_ddm_solver.py b/tests/test_ddm_solver.py index 119773b..1c128d0 100644 --- a/tests/test_ddm_solver.py +++ b/tests/test_ddm_solver.py @@ -1,5 +1,3 @@ -import time - import Htool import mpi4py import numpy as np @@ -292,19 +290,7 @@ def test_ddm_solver( solver.set_hpddm_args( "-hpddm_schwarz_coarse_correction " + hpddm_schwarz_coarse_correction ) - # solver.build_coarse_space(local_neumann_matrix) - # print(default_solver_builder.block_diagonal_dense_matrix.flags) - # print(local_neumann_matrix.flags) - # geneo_space_operator_builder = ( - # Htool.ComplexGeneoCoarseSpaceDenseBuilder.GeneoWithNu( - # cluster.get_cluster_on_partition(mpi4py.MPI.COMM_WORLD.rank).get_size(), - # default_solver_builder.block_diagonal_dense_matrix, - # local_neumann_matrix, - # symmetry, - # UPLO, - # 2, - # ) - # ) + geneo_space_operator_builder = None if geneo_type == "geneo_nu": geneo_space_operator_builder = Htool.ComplexGeneoCoarseSpaceDenseBuilder( diff --git a/tests/test_distributed_operator.py b/tests/test_distributed_operator.py index 17cb2a3..dbabcd0 100644 --- a/tests/test_distributed_operator.py +++ b/tests/test_distributed_operator.py @@ -1,9 +1,6 @@ -import mpi4py import numpy as np import pytest -import Htool - @pytest.mark.parametrize("epsilon", [1e-3, 1e-6]) @pytest.mark.parametrize("eta", [10])