From bfb9bc07337df950ea2f75bc2c0f6e45cb443c7e Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Thu, 16 Oct 2025 16:23:11 +0200 Subject: [PATCH 01/13] add file ddm/mpi.py for MockMPI and MPIWrapper (previously in Struphy, now moved here) --- psydac/ddm/cart.py | 21 ++++++--- psydac/ddm/mpi.py | 105 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 psydac/ddm/mpi.py diff --git a/psydac/ddm/cart.py b/psydac/ddm/cart.py index 56251b22c..49714512f 100644 --- a/psydac/ddm/cart.py +++ b/psydac/ddm/cart.py @@ -3,8 +3,14 @@ import os import numpy as np from itertools import product -from mpi4py import MPI - +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI + +from psydac.ddm.mpi import MockMPI from psydac.ddm.partition import compute_dims, partition_procs_per_patch @@ -31,11 +37,14 @@ def find_mpi_type( dtype ): MPI datatype to be used for communication. """ - if isinstance( dtype, MPI.Datatype ): - mpi_type = dtype + if not isinstance(MPI, MockMPI): + if isinstance( dtype, MPI.Datatype ): + mpi_type = dtype + else: + nt = np.dtype( dtype ) + mpi_type = MPI._typedict[nt.char] else: - nt = np.dtype( dtype ) - mpi_type = MPI._typedict[nt.char] + mpi_type = np.dtype( dtype ) return mpi_type diff --git a/psydac/ddm/mpi.py b/psydac/ddm/mpi.py new file mode 100644 index 000000000..d4a31a118 --- /dev/null +++ b/psydac/ddm/mpi.py @@ -0,0 +1,105 @@ +from dataclasses import dataclass +from time import time +from typing import TYPE_CHECKING + + +# Might not be needed +class MPICommWrapper: + def __init__(self, use_mpi=True): + self.use_mpi = use_mpi + if use_mpi: + from mpi4py import MPI + + self.comm = MPI.COMM_WORLD + else: + self.comm = MockComm() + + def __getattr__(self, name): + return getattr(self.comm, name) + + +class MockComm: + def __getattr__(self, name): + # Return a function that does nothing and returns None + def dummy(*args, **kwargs): + return None + + return dummy + + # Override some functions + def Get_rank(self): + return 0 + + def Get_size(self): + return 1 + + def Barrier(self): + return + + +class MPIwrapper: + def __init__(self, use_mpi: bool = False): + self.use_mpi = use_mpi + if use_mpi: + from mpi4py import MPI + + self._MPI = MPI + print("MPI is enabled") + else: + self._MPI = MockMPI() + print("MPI is NOT enabled") + + @property + def MPI(self): + return self._MPI + + +class MockMPI: + def __getattr__(self, name): + # Return a function that does nothing and returns None + def dummy(*args, **kwargs): + return None + + return dummy + + # Override some functions + @property + def COMM_WORLD(self): + return MockComm() + + class Comm: + x = None + + # def comm_Get_rank(self): + # return 0 + + # def comm_Get_size(self): + # return 1 + + +try: + from mpi4py import MPI + + _comm = MPI.COMM_WORLD + rank = _comm.Get_rank() + size = _comm.Get_size() + mpi_enabled = size > 1 +except ImportError: + # mpi4py not installed + mpi_enabled = False +except Exception: + # mpi4py installed but not running under mpirun + mpi_enabled = False + +# TODO: add environment variable for mpi use +mpi_wrapper = MPIwrapper(use_mpi=mpi_enabled) + +# TYPE_CHECKING is True when type checking (e.g., mypy), but False at runtime. +if TYPE_CHECKING: + from mpi4py import MPI + + mpi = MPI +else: + mpi = mpi_wrapper.MPI + +print(f"{mpi = }") \ No newline at end of file From 2f39539206272427e7a5b3e15df12bf60a235f67 Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Thu, 16 Oct 2025 16:58:20 +0200 Subject: [PATCH 02/13] fix assertions in cart.py --- psydac/ddm/cart.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/psydac/ddm/cart.py b/psydac/ddm/cart.py index 49714512f..78a2bf78b 100644 --- a/psydac/ddm/cart.py +++ b/psydac/ddm/cart.py @@ -72,7 +72,8 @@ class MultiPatchDomainDecomposition: def __init__(self, ncells, periods, comm=None, num_threads=None): assert len( ncells ) == len( periods ) - if comm is not None:assert isinstance( comm, MPI.Comm ) + if not isinstance(MPI, MockMPI) and comm is not None: + assert isinstance( comm, MPI.Comm ) num_threads = num_threads if num_threads else int(os.environ.get('OMP_NUM_THREADS', 1)) # Store input arguments @@ -215,7 +216,8 @@ def __init__(self, ncells, periods, comm=None, global_comm=None, num_threads=Non assert len( ncells ) == len( periods ) assert all( n >=1 for n in ncells ) assert all( isinstance( period, bool ) for period in periods ) - if comm is not None: assert isinstance( comm, MPI.Comm ) + if not isinstance(MPI, MockMPI) and comm is not None: + assert isinstance( comm, MPI.Comm ) self._ncells = tuple ( ncells ) self._periods = tuple ( periods ) From 73ece1cf90efaf61015c1d30f61aa32c8615ac4a Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Thu, 16 Oct 2025 17:20:43 +0200 Subject: [PATCH 03/13] fix mpi4py imports everywhere --- mpi_tester.py | 16 +++++++++++++-- psydac/ddm/blocking_data_exchanger.py | 7 ++++++- psydac/ddm/cart.py | 8 ++++++-- psydac/ddm/interface_data_exchanger.py | 7 ++++++- psydac/ddm/nonblocking_data_exchanger.py | 7 ++++++- psydac/ddm/tests/test_cart_1d.py | 8 +++++++- psydac/ddm/tests/test_cart_2d.py | 8 +++++++- psydac/ddm/tests/test_cart_3d.py | 8 +++++++- psydac/ddm/tests/test_multicart_2d.py | 8 +++++++- psydac/fem/partitioning.py | 7 ++++++- psydac/fem/tensor.py | 8 +++++++- psydac/fem/tests/test_spline_interpolation.py | 8 +++++++- psydac/fem/tests/test_splines_par.py | 7 ++++++- psydac/linalg/block.py | 8 +++++++- psydac/linalg/stencil.py | 7 ++++++- psydac/linalg/tests/test_block.py | 16 +++++++-------- psydac/linalg/tests/test_fft.py | 7 ++++++- .../tests/test_stencil_interface_matrix.py | 8 +++++++- psydac/linalg/tests/test_stencil_vector.py | 20 +++++++++---------- .../linalg/tests/test_stencil_vector_space.py | 14 ++++++------- 20 files changed, 140 insertions(+), 47 deletions(-) diff --git a/mpi_tester.py b/mpi_tester.py index ca3dba1ae..c6eb32a8f 100644 --- a/mpi_tester.py +++ b/mpi_tester.py @@ -101,7 +101,13 @@ def MPITest(commsize): def test_stuff(comm): pass """ - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + if not isinstance(commsize, (tuple, list)): commsize = (commsize,) @@ -182,7 +188,13 @@ def __init__(self): #--------------------------------------------------------------------------- @property def comm(self): - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + return MPI.COMM_WORLD #--------------------------------------------------------------------------- diff --git a/psydac/ddm/blocking_data_exchanger.py b/psydac/ddm/blocking_data_exchanger.py index ca83b140a..df9df0c3e 100644 --- a/psydac/ddm/blocking_data_exchanger.py +++ b/psydac/ddm/blocking_data_exchanger.py @@ -1,7 +1,12 @@ # coding: utf-8 import numpy as np -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from .cart import CartDecomposition, find_mpi_type from .basic import CartDataExchanger diff --git a/psydac/ddm/cart.py b/psydac/ddm/cart.py index 78a2bf78b..b4c00de01 100644 --- a/psydac/ddm/cart.py +++ b/psydac/ddm/cart.py @@ -216,8 +216,12 @@ def __init__(self, ncells, periods, comm=None, global_comm=None, num_threads=Non assert len( ncells ) == len( periods ) assert all( n >=1 for n in ncells ) assert all( isinstance( period, bool ) for period in periods ) - if not isinstance(MPI, MockMPI) and comm is not None: - assert isinstance( comm, MPI.Comm ) + if isinstance(MPI, MockMPI): + comm = None + else: + if comm is not None: + assert isinstance( comm, MPI.Comm ) + self._ncells = tuple ( ncells ) self._periods = tuple ( periods ) diff --git a/psydac/ddm/interface_data_exchanger.py b/psydac/ddm/interface_data_exchanger.py index cd60d8792..fb74ab4f7 100644 --- a/psydac/ddm/interface_data_exchanger.py +++ b/psydac/ddm/interface_data_exchanger.py @@ -1,6 +1,11 @@ # coding: utf-8 -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from .cart import InterfaceCartDecomposition, find_mpi_type diff --git a/psydac/ddm/nonblocking_data_exchanger.py b/psydac/ddm/nonblocking_data_exchanger.py index 4c482518d..88a6ae334 100644 --- a/psydac/ddm/nonblocking_data_exchanger.py +++ b/psydac/ddm/nonblocking_data_exchanger.py @@ -2,7 +2,12 @@ import numpy as np from itertools import product -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from .cart import CartDecomposition, find_mpi_type from .basic import CartDataExchanger diff --git a/psydac/ddm/tests/test_cart_1d.py b/psydac/ddm/tests/test_cart_1d.py index b3e51d3ad..55d7b7011 100644 --- a/psydac/ddm/tests/test_cart_1d.py +++ b/psydac/ddm/tests/test_cart_1d.py @@ -11,7 +11,13 @@ def run_cart_1d( data_exchanger_type, verbose=False ): import numpy as np - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + from psydac.ddm.cart import DomainDecomposition, CartDecomposition #--------------------------------------------------------------------------- diff --git a/psydac/ddm/tests/test_cart_2d.py b/psydac/ddm/tests/test_cart_2d.py index 5974a50a9..f2c24260b 100644 --- a/psydac/ddm/tests/test_cart_2d.py +++ b/psydac/ddm/tests/test_cart_2d.py @@ -9,7 +9,13 @@ def run_cart_2d( data_exchanger_type, verbose=False , nprocs=None, reverse_axis=None): import numpy as np - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + from psydac.ddm.cart import DomainDecomposition, CartDecomposition #--------------------------------------------------------------------------- diff --git a/psydac/ddm/tests/test_cart_3d.py b/psydac/ddm/tests/test_cart_3d.py index 20b6326f4..00ba32b88 100644 --- a/psydac/ddm/tests/test_cart_3d.py +++ b/psydac/ddm/tests/test_cart_3d.py @@ -9,7 +9,13 @@ def run_cart_3d( data_exchanger_type, verbose=False ): import numpy as np - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + from psydac.ddm.cart import DomainDecomposition, CartDecomposition #--------------------------------------------------------------------------- diff --git a/psydac/ddm/tests/test_multicart_2d.py b/psydac/ddm/tests/test_multicart_2d.py index 4b1bbddb3..062749430 100644 --- a/psydac/ddm/tests/test_multicart_2d.py +++ b/psydac/ddm/tests/test_multicart_2d.py @@ -36,7 +36,13 @@ def get_plus_starts_ends(minus_starts, minus_ends, minus_npts, plus_npts, minus_ #=============================================================================== def run_carts_2d(): import numpy as np - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + from psydac.ddm.cart import MultiPatchDomainDecomposition, CartDecomposition, create_interfaces_cart from psydac.ddm.blocking_data_exchanger import BlockingCartDataExchanger from psydac.ddm.interface_data_exchanger import InterfaceCartDataExchanger diff --git a/psydac/fem/partitioning.py b/psydac/fem/partitioning.py index 33b3e90a3..804cf87e2 100644 --- a/psydac/fem/partitioning.py +++ b/psydac/fem/partitioning.py @@ -2,7 +2,12 @@ import os import numpy as np -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import CartDecomposition, InterfaceCartDecomposition, create_interfaces_cart from psydac.core.bsplines import elements_spans diff --git a/psydac/fem/tensor.py b/psydac/fem/tensor.py index 39736af1f..02203922c 100644 --- a/psydac/fem/tensor.py +++ b/psydac/fem/tensor.py @@ -5,7 +5,13 @@ of compact support """ -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI + import numpy as np import itertools import h5py diff --git a/psydac/fem/tests/test_spline_interpolation.py b/psydac/fem/tests/test_spline_interpolation.py index 6e27d60ca..b2777a46b 100644 --- a/psydac/fem/tests/test_spline_interpolation.py +++ b/psydac/fem/tests/test_spline_interpolation.py @@ -1,7 +1,13 @@ # coding: utf-8 # Copyright 2018 Yaman Güçlü -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI + import numpy as np import pytest import time diff --git a/psydac/fem/tests/test_splines_par.py b/psydac/fem/tests/test_splines_par.py index c1dae5afe..4c62b7734 100644 --- a/psydac/fem/tests/test_splines_par.py +++ b/psydac/fem/tests/test_splines_par.py @@ -9,7 +9,12 @@ from psydac.ddm.cart import DomainDecomposition from numpy import linspace -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI def test_2d_1(): diff --git a/psydac/linalg/block.py b/psydac/linalg/block.py index b9fdc7d4b..8e9ce7a48 100644 --- a/psydac/linalg/block.py +++ b/psydac/linalg/block.py @@ -1064,7 +1064,13 @@ def compute_interface_matrices_transpose(self): if not self.codomain.parallel: return blocks, blocks_T - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + from psydac.linalg.stencil import StencilInterfaceMatrix if not isinstance(self.codomain, BlockVectorSpace): diff --git a/psydac/linalg/stencil.py b/psydac/linalg/stencil.py index 4c62139fc..c8fac007b 100644 --- a/psydac/linalg/stencil.py +++ b/psydac/linalg/stencil.py @@ -9,7 +9,12 @@ from types import MappingProxyType from scipy.sparse import coo_matrix, diags as sp_diags -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from psydac.linalg.basic import VectorSpace, Vector, LinearOperator from psydac.ddm.cart import find_mpi_type, CartDecomposition, InterfaceCartDecomposition diff --git a/psydac/linalg/tests/test_block.py b/psydac/linalg/tests/test_block.py index cf887da29..880f316a6 100644 --- a/psydac/linalg/tests/test_block.py +++ b/psydac/linalg/tests/test_block.py @@ -4,6 +4,12 @@ import numpy as np from scipy.sparse import csr_matrix from random import random, seed +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from psydac.linalg.direct_solvers import SparseSolver from psydac.linalg.stencil import StencilVectorSpace, StencilVector, StencilMatrix @@ -999,8 +1005,6 @@ def test_block_linear_operator_parallel_dot( dtype, n1, n2, p1, p2, P1, P2 ): # set seed for reproducibility seed(n1*n2*p1*p2) - from mpi4py import MPI - comm = MPI.COMM_WORLD D = DomainDecomposition([n1,n2], periods=[P1,P2], comm=comm) @@ -1130,7 +1134,6 @@ def test_block_linear_operator_parallel_dot( dtype, n1, n2, p1, p2, P1, P2 ): def test_block_vector_2d_parallel_array_to_psydac(dtype, n1, n2, p1, p2, s1, s2, P1, P2): npts = [n1, n2] - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition @@ -1221,7 +1224,6 @@ def test_block_vector_2d_parallel_topetsc( dtype, n1, n2, p1, p2, P1, P2 ): # set seed for reproducibility seed(n1*n2*p1*p2) - from mpi4py import MPI comm = MPI.COMM_WORLD D = DomainDecomposition([n1,n2], periods=[P1,P2], comm=comm) @@ -1269,7 +1271,6 @@ def test_block_vector_2d_parallel_topetsc( dtype, n1, n2, p1, p2, P1, P2 ): def test_block_linear_operator_1d_parallel_topetsc( dtype, n1, p1, P1): # set seed for reproducibility seed(n1*p1) - from mpi4py import MPI D = DomainDecomposition([n1], periods=[P1], comm=MPI.COMM_WORLD) @@ -1343,7 +1344,6 @@ def test_block_linear_operator_1d_parallel_topetsc( dtype, n1, p1, P1): def test_block_linear_operator_2d_parallel_topetsc( dtype, n1, n2, p1, p2, P1, P2): # set seed for reproducibility seed(n1*n2*p1*p2) - from mpi4py import MPI comm = MPI.COMM_WORLD D = DomainDecomposition([n1,n2], periods=[P1,P2], comm=comm) @@ -1427,9 +1427,7 @@ def test_block_matrix_operator_parallel_dot_backend( dtype, n1, n2, p1, p2, P1, else: factor = 1 # set seed for reproducibility - - from mpi4py import MPI - + comm = MPI.COMM_WORLD D = DomainDecomposition([n1,n2], periods=[P1,P2], comm=comm) diff --git a/psydac/linalg/tests/test_fft.py b/psydac/linalg/tests/test_fft.py index a9bcef459..d3fa6fed7 100644 --- a/psydac/linalg/tests/test_fft.py +++ b/psydac/linalg/tests/test_fft.py @@ -1,7 +1,12 @@ import pytest import scipy.fft as scifft import numpy as np -from mpi4py import MPI +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from psydac.linalg.fft import * from psydac.ddm.cart import DomainDecomposition, CartDecomposition diff --git a/psydac/linalg/tests/test_stencil_interface_matrix.py b/psydac/linalg/tests/test_stencil_interface_matrix.py index 60693952c..499f3a61b 100644 --- a/psydac/linalg/tests/test_stencil_interface_matrix.py +++ b/psydac/linalg/tests/test_stencil_interface_matrix.py @@ -226,7 +226,13 @@ def test_stencil_interface_matrix_3d_serial_init(dtype, n1, n2, n3, p1, p2, p3, @pytest.mark.parallel def test_stencil_interface_matrix_2d_parallel_dot(n1, n2, p1, p2, expected): - from mpi4py import MPI + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from mpi4py import MPI + else: + from psydac.ddm.mpi import mpi as MPI + from psydac.ddm.cart import MultiPatchDomainDecomposition, CartDecomposition, create_interfaces_cart from psydac.linalg.block import BlockVectorSpace, BlockVector, BlockLinearOperator diff --git a/psydac/linalg/tests/test_stencil_vector.py b/psydac/linalg/tests/test_stencil_vector.py index 0983edf80..2f3a78ac8 100644 --- a/psydac/linalg/tests/test_stencil_vector.py +++ b/psydac/linalg/tests/test_stencil_vector.py @@ -2,6 +2,12 @@ import pytest import numpy as np +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilVectorSpace, StencilVector, StencilMatrix from psydac.linalg.utilities import array_to_psydac, petsc_to_psydac @@ -528,7 +534,6 @@ def test_stencil_vector_2d_serial_update_ghost_region_interior(dtype, n1, n2, p1 @pytest.mark.parallel def test_stencil_vector_1d_parallel_init(dtype, n1, p1, s1, P1=True): - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition @@ -564,7 +569,6 @@ def test_stencil_vector_1d_parallel_init(dtype, n1, p1, s1, P1=True): @pytest.mark.parallel def test_stencil_vector_2d_parallel_init(dtype, n1, n2, p1, p2, s1, s2, P1=True, P2=False): - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition @@ -602,7 +606,7 @@ def test_stencil_vector_2d_parallel_init(dtype, n1, n2, p1, p2, s1, s2, P1=True, @pytest.mark.parallel @pytest.mark.petsc def test_stencil_vector_2d_parallel_topetsc(dtype, n1, n2, p1, p2, s1, s2, P1, P2): - from mpi4py import MPI + comm = MPI.COMM_WORLD # Create domain decomposition @@ -645,7 +649,7 @@ def test_stencil_vector_2d_parallel_topetsc(dtype, n1, n2, p1, p2, s1, s2, P1, P @pytest.mark.parallel @pytest.mark.petsc def test_stencil_vector_1d_parallel_topetsc(dtype, n1, p1, s1, P1): - from mpi4py import MPI + comm = MPI.COMM_WORLD # Create domain decomposition @@ -696,7 +700,7 @@ def test_stencil_vector_1d_parallel_topetsc(dtype, n1, p1, s1, P1): @pytest.mark.parallel @pytest.mark.petsc def test_stencil_vector_3d_parallel_topetsc(dtype, n1, n2, n3, p1, p2, p3, s1, s2, s3, P1, P2, P3): - from mpi4py import MPI + comm = MPI.COMM_WORLD # Create domain decomposition @@ -746,7 +750,6 @@ def test_stencil_vector_3d_parallel_topetsc(dtype, n1, n2, n3, p1, p2, p3, s1, s @pytest.mark.parallel def test_stencil_vector_3d_parallel_init(dtype, n1, n2, n3, p1, p2, p3, s1, s2, s3, P1=True, P2=False, P3=True): - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition @@ -783,8 +786,6 @@ def test_stencil_vector_3d_parallel_init(dtype, n1, n2, n3, p1, p2, p3, s1, s2, @pytest.mark.parallel def test_stencil_vector_2d_parallel_toarray(dtype, n1, n2, p1, p2, s1, s2, P1=True, P2=False): # Create domain decomposition - from mpi4py import MPI - comm = MPI.COMM_WORLD D = DomainDecomposition([n1, n2], periods=[P1, P2], comm=comm) @@ -853,7 +854,6 @@ def test_stencil_vector_2d_parallel_toarray(dtype, n1, n2, p1, p2, s1, s2, P1=Tr def test_stencil_vector_2d_parallel_array_to_psydac(dtype, n1, n2, p1, p2, s1, s2, P1, P2): npts = [n1, n2] - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition @@ -909,7 +909,6 @@ def test_stencil_vector_2d_parallel_array_to_psydac(dtype, n1, n2, p1, p2, s1, s @pytest.mark.parametrize('s2', [1]) @pytest.mark.parallel def test_stencil_vector_2d_parallel_dot(dtype, n1, n2, p1, p2, s1, s2, P1=True, P2=False): - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition @@ -977,7 +976,6 @@ def test_stencil_vector_2d_parallel_dot(dtype, n1, n2, p1, p2, s1, s2, P1=True, @pytest.mark.parametrize('s3', [1]) @pytest.mark.parallel def test_stencil_vector_3d_parallel_dot(dtype, n1, n2, n3, p1, p2, p3, s1, s2, s3, P1=True, P2=False, P3=True): - from mpi4py import MPI comm = MPI.COMM_WORLD # Create domain decomposition diff --git a/psydac/linalg/tests/test_stencil_vector_space.py b/psydac/linalg/tests/test_stencil_vector_space.py index 2ef09b26e..31388fe2e 100644 --- a/psydac/linalg/tests/test_stencil_vector_space.py +++ b/psydac/linalg/tests/test_stencil_vector_space.py @@ -1,5 +1,11 @@ import pytest import numpy as np +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mpi4py import MPI +else: + from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilVectorSpace, StencilVector from psydac.ddm.cart import DomainDecomposition, CartDecomposition, find_mpi_type @@ -279,8 +285,6 @@ def test_stencil_vector_space_2D_serial_set_interface(dtype, n1, n2, p1, p2, s1, def test_stencil_vector_space_1d_parallel_init(dtype, n1, p1, s1, P1): - from mpi4py import MPI - comm = MPI.COMM_WORLD # Create domain decomposition D = DomainDecomposition([n1], periods=[P1], comm=comm) @@ -326,8 +330,6 @@ def test_stencil_vector_space_1d_parallel_init(dtype, n1, p1, s1, P1): def test_stencil_vector_space_2d_parallel_init(dtype, n1, n2, p1, p2, s1, s2, P1, P2): - from mpi4py import MPI - comm = MPI.COMM_WORLD # Create domain decomposition D = DomainDecomposition([n1, n2], periods=[P1, P2], comm=comm) @@ -373,8 +375,6 @@ def test_stencil_vector_space_2d_parallel_init(dtype, n1, n2, p1, p2, s1, s2, P1 def test_stencil_vector_space_3d_parallel_init(dtype, n1, n2, n3, p1, p2, p3, s1, s2, s3, P1=True, P2=False, P3=True): - from mpi4py import MPI - comm = MPI.COMM_WORLD # Create domain decomposition D = DomainDecomposition([n1, n2, n3], periods=[P1, P2, P3], comm=comm) @@ -413,8 +413,6 @@ def test_stencil_vector_space_3d_parallel_init(dtype, n1, n2, n3, p1, p2, p3, s1 def test_stencil_vector_space_2D_parallel_parent(dtype, n1, n2, P1=True, P2=False): - from mpi4py import MPI - comm = MPI.COMM_WORLD # Create domain decomposition D = DomainDecomposition([n1, n2], periods=[P1, P2], comm=comm) From 04e3980c10eba5ba371491b53c65eb1c4f523b70 Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 07:28:37 +0200 Subject: [PATCH 04/13] make mpi4py an optional dependency; run tests without mpi too --- .github/workflows/testing.yml | 18 ++++++++++++------ psydac/ddm/mpi.py | 3 --- pyproject.toml | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 98d80ceb0..897eebe89 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -328,9 +328,9 @@ jobs: # f = h5py.File('parallel_test.hdf5', 'w', driver='mpio', comm=MPI.COMM_WORLD) # print(f)" - - name: Install project + - name: Install project without mpi run: | - python -m pip install ".[test]" --no-cache-dir + python -m pip install ".[test,mpi]" --no-cache-dir python -m pip freeze - name: Compile psydac kernels @@ -362,15 +362,20 @@ jobs: run: | python -m pytest -n auto --pyargs psydac -m "not parallel and not petsc" - - name: Run MPI tests with Pytest + - name: Run single-process PETSc tests with Pytest working-directory: ./pytest run: | - python mpi_tester.py --mpirun="mpiexec -n 4 ${MPI_OPTS}" --pyargs psydac -m "parallel and not petsc" + python -m pytest -n auto --pyargs psydac -m "not parallel and petsc" - - name: Run single-process PETSc tests with Pytest + - name: Install project with mpi + run: | + python -m pip install ".[mpi]" + python -m pip freeze + + - name: Run MPI tests with Pytest working-directory: ./pytest run: | - python -m pytest -n auto --pyargs psydac -m "not parallel and petsc" + python mpi_tester.py --mpirun="mpiexec -n 4 ${MPI_OPTS}" --pyargs psydac -m "parallel and not petsc" - name: Run MPI PETSc tests with Pytest working-directory: ./pytest @@ -381,6 +386,7 @@ jobs: if: always() run: | rm -rf pytest + test_struphy: runs-on: ${{ matrix.os }} strategy: diff --git a/psydac/ddm/mpi.py b/psydac/ddm/mpi.py index d4a31a118..dc2161083 100644 --- a/psydac/ddm/mpi.py +++ b/psydac/ddm/mpi.py @@ -66,9 +66,6 @@ def dummy(*args, **kwargs): @property def COMM_WORLD(self): return MockComm() - - class Comm: - x = None # def comm_Get_rank(self): # return 0 diff --git a/pyproject.toml b/pyproject.toml index 3e45a3bde..6ad294fa3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,6 @@ dependencies = [ # Our packages from PyPi 'pyccel >= 2.0.1', - 'mpi4py >= 4', 'h5py', # When pyccel is run in parallel with MPI, it uses tblib to pickle @@ -45,6 +44,9 @@ test = [ 'pytest >= 4.5', 'pytest-xdist >= 1.16', ] +mpi = [ + 'mpi4py >= 4', +] [project.urls] Homepage = "https://github.com/pyccel/psydac" From 1eb029704c9e6ac5e02db451944b089bc20e70c3 Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 07:44:45 +0200 Subject: [PATCH 05/13] add forgotton change --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 897eebe89..d1ac0757b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -330,7 +330,7 @@ jobs: - name: Install project without mpi run: | - python -m pip install ".[test,mpi]" --no-cache-dir + python -m pip install ".[test]" --no-cache-dir python -m pip freeze - name: Compile psydac kernels From af5279aadba3d59c851a2d0174dc28eaee05722b Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 07:50:59 +0200 Subject: [PATCH 06/13] change version to 2.5.0 for last release still on GitLab --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6ad294fa3..e7717ce09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "psydac" -version = "2.4.5.dev0" +version = "2.5.0.dev0" description = "Python package for isogeometric analysis (IGA)" readme = "README.md" requires-python = ">= 3.10" From e81aee44adff6582573e631d24ef535ccb6556f5 Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 09:14:34 +0200 Subject: [PATCH 07/13] install Struphy from branch 467-no-mpi; perform Struphy unit tests on 1 and 2 processes --- .github/workflows/testing.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d1ac0757b..73c8e968a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -475,7 +475,7 @@ jobs: run: | python -m pip install --upgrade pip - - name: Install project + - name: Install project without mpi run: | python -m pip install ".[test]" --no-cache-dir python -m pip freeze @@ -485,11 +485,11 @@ jobs: echo "PSYDAC_DIR=$GITHUB_WORKSPACE" >> $GITHUB_ENV echo "STRUPHY_DIR=$GITHUB_WORKSPACE/struphy" >> $GITHUB_ENV - - name: Clone struphy from GitLab #TODO: Set branch to devel + - name: Clone struphy from GitLab #TODO: Set branch to 467-no-mpi run: | - git clone https://gitlab.mpcdf.mpg.de/struphy/struphy.git $STRUPHY_DIR + git clone https://gitlab.mpcdf.mpg.de/struphy/struphy.git@467-no-mpi $STRUPHY_DIR - - name: Install struphy + - name: Install struphy without mpi working-directory: ${{ env.STRUPHY_DIR }} run: | echo "Psydac location for this branch" @@ -526,6 +526,16 @@ jobs: run: | struphy test models --fast + - name: Install mpi4py + working-directory: ${{ env.STRUPHY_DIR }} + run: | + pip install -U mpi4py + + - name: Run struphy unit tests with mpi + working-directory: ${{ env.STRUPHY_DIR }} + run: | + struphy test unit --mpi 2 + - name: Remove test directory if: always() run: | From c423b57715702ba47ddeadc9eeca2d7386a8b60c Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 09:21:52 +0200 Subject: [PATCH 08/13] checkout correct Struphy branch 467-no-mpi --- .github/workflows/testing.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 73c8e968a..85d80a312 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -487,7 +487,7 @@ jobs: - name: Clone struphy from GitLab #TODO: Set branch to 467-no-mpi run: | - git clone https://gitlab.mpcdf.mpg.de/struphy/struphy.git@467-no-mpi $STRUPHY_DIR + git clone https://gitlab.mpcdf.mpg.de/struphy/struphy.git $STRUPHY_DIR - name: Install struphy without mpi working-directory: ${{ env.STRUPHY_DIR }} @@ -495,6 +495,7 @@ jobs: echo "Psydac location for this branch" pip show psydac pip uninstall psydac -y + git checkout 467-no-mpi python -m pip install ".[phys]" --no-cache-dir echo "Psydac location after installing struphy" pip show psydac From 5115551105e1301b98a2977a1731c0d5986902ea Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 13:37:16 +0200 Subject: [PATCH 09/13] correct TODO to devel --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 85d80a312..331824207 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -485,11 +485,11 @@ jobs: echo "PSYDAC_DIR=$GITHUB_WORKSPACE" >> $GITHUB_ENV echo "STRUPHY_DIR=$GITHUB_WORKSPACE/struphy" >> $GITHUB_ENV - - name: Clone struphy from GitLab #TODO: Set branch to 467-no-mpi + - name: Clone struphy from GitLab run: | git clone https://gitlab.mpcdf.mpg.de/struphy/struphy.git $STRUPHY_DIR - - name: Install struphy without mpi + - name: Install struphy without mpi #TODO: Set branch to devel working-directory: ${{ env.STRUPHY_DIR }} run: | echo "Psydac location for this branch" From 34f223f377459c6b5d4c76c79e3c70b4daa8a362 Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Fri, 17 Oct 2025 13:44:49 +0200 Subject: [PATCH 10/13] remove the unneccessary if TYPE_CHECKING thing from all files, except mpi.py --- mpi_tester.py | 15 ++------------- psydac/ddm/blocking_data_exchanger.py | 7 +------ psydac/ddm/cart.py | 7 +------ psydac/ddm/interface_data_exchanger.py | 7 +------ psydac/ddm/mpi.py | 4 +--- psydac/ddm/nonblocking_data_exchanger.py | 7 +------ psydac/ddm/tests/test_cart_1d.py | 8 +------- psydac/ddm/tests/test_cart_2d.py | 8 +------- psydac/ddm/tests/test_cart_3d.py | 8 +------- psydac/ddm/tests/test_multicart_2d.py | 9 ++------- psydac/fem/partitioning.py | 6 ------ psydac/fem/tensor.py | 7 +------ psydac/fem/tests/test_spline_interpolation.py | 7 +------ psydac/fem/tests/test_splines_par.py | 7 +------ psydac/linalg/block.py | 8 +------- psydac/linalg/stencil.py | 7 +------ psydac/linalg/tests/test_block.py | 7 +------ psydac/linalg/tests/test_fft.py | 7 +------ .../linalg/tests/test_stencil_interface_matrix.py | 8 +------- psydac/linalg/tests/test_stencil_vector.py | 7 +------ psydac/linalg/tests/test_stencil_vector_space.py | 7 +------ 21 files changed, 22 insertions(+), 136 deletions(-) diff --git a/mpi_tester.py b/mpi_tester.py index c6eb32a8f..e7f718a69 100644 --- a/mpi_tester.py +++ b/mpi_tester.py @@ -101,12 +101,7 @@ def MPITest(commsize): def test_stuff(comm): pass """ - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI + from psydac.ddm.mpi import mpi as MPI if not isinstance(commsize, (tuple, list)): commsize = (commsize,) @@ -188,13 +183,7 @@ def __init__(self): #--------------------------------------------------------------------------- @property def comm(self): - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + from psydac.ddm.mpi import mpi as MPI return MPI.COMM_WORLD #--------------------------------------------------------------------------- diff --git a/psydac/ddm/blocking_data_exchanger.py b/psydac/ddm/blocking_data_exchanger.py index df9df0c3e..0a8c4759a 100644 --- a/psydac/ddm/blocking_data_exchanger.py +++ b/psydac/ddm/blocking_data_exchanger.py @@ -1,12 +1,7 @@ # coding: utf-8 import numpy as np -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from .cart import CartDecomposition, find_mpi_type from .basic import CartDataExchanger diff --git a/psydac/ddm/cart.py b/psydac/ddm/cart.py index b4c00de01..229f4fb0d 100644 --- a/psydac/ddm/cart.py +++ b/psydac/ddm/cart.py @@ -3,13 +3,8 @@ import os import numpy as np from itertools import product -from typing import TYPE_CHECKING -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI - +from psydac.ddm.mpi import mpi as MPI from psydac.ddm.mpi import MockMPI from psydac.ddm.partition import compute_dims, partition_procs_per_patch diff --git a/psydac/ddm/interface_data_exchanger.py b/psydac/ddm/interface_data_exchanger.py index fb74ab4f7..ef3a209c8 100644 --- a/psydac/ddm/interface_data_exchanger.py +++ b/psydac/ddm/interface_data_exchanger.py @@ -1,11 +1,6 @@ # coding: utf-8 -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from .cart import InterfaceCartDecomposition, find_mpi_type diff --git a/psydac/ddm/mpi.py b/psydac/ddm/mpi.py index dc2161083..7c9abf240 100644 --- a/psydac/ddm/mpi.py +++ b/psydac/ddm/mpi.py @@ -97,6 +97,4 @@ def COMM_WORLD(self): mpi = MPI else: - mpi = mpi_wrapper.MPI - -print(f"{mpi = }") \ No newline at end of file + mpi = mpi_wrapper.MPI \ No newline at end of file diff --git a/psydac/ddm/nonblocking_data_exchanger.py b/psydac/ddm/nonblocking_data_exchanger.py index 88a6ae334..ecfc15730 100644 --- a/psydac/ddm/nonblocking_data_exchanger.py +++ b/psydac/ddm/nonblocking_data_exchanger.py @@ -2,13 +2,8 @@ import numpy as np from itertools import product -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from .cart import CartDecomposition, find_mpi_type from .basic import CartDataExchanger diff --git a/psydac/ddm/tests/test_cart_1d.py b/psydac/ddm/tests/test_cart_1d.py index 55d7b7011..ea5446da2 100644 --- a/psydac/ddm/tests/test_cart_1d.py +++ b/psydac/ddm/tests/test_cart_1d.py @@ -11,13 +11,7 @@ def run_cart_1d( data_exchanger_type, verbose=False ): import numpy as np - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import DomainDecomposition, CartDecomposition #--------------------------------------------------------------------------- diff --git a/psydac/ddm/tests/test_cart_2d.py b/psydac/ddm/tests/test_cart_2d.py index f2c24260b..3f21af8ad 100644 --- a/psydac/ddm/tests/test_cart_2d.py +++ b/psydac/ddm/tests/test_cart_2d.py @@ -9,13 +9,7 @@ def run_cart_2d( data_exchanger_type, verbose=False , nprocs=None, reverse_axis=None): import numpy as np - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import DomainDecomposition, CartDecomposition #--------------------------------------------------------------------------- diff --git a/psydac/ddm/tests/test_cart_3d.py b/psydac/ddm/tests/test_cart_3d.py index 00ba32b88..7f86a32f2 100644 --- a/psydac/ddm/tests/test_cart_3d.py +++ b/psydac/ddm/tests/test_cart_3d.py @@ -9,13 +9,7 @@ def run_cart_3d( data_exchanger_type, verbose=False ): import numpy as np - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import DomainDecomposition, CartDecomposition #--------------------------------------------------------------------------- diff --git a/psydac/ddm/tests/test_multicart_2d.py b/psydac/ddm/tests/test_multicart_2d.py index 062749430..4d8f57917 100644 --- a/psydac/ddm/tests/test_multicart_2d.py +++ b/psydac/ddm/tests/test_multicart_2d.py @@ -36,13 +36,8 @@ def get_plus_starts_ends(minus_starts, minus_ends, minus_npts, plus_npts, minus_ #=============================================================================== def run_carts_2d(): import numpy as np - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + + from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import MultiPatchDomainDecomposition, CartDecomposition, create_interfaces_cart from psydac.ddm.blocking_data_exchanger import BlockingCartDataExchanger from psydac.ddm.interface_data_exchanger import InterfaceCartDataExchanger diff --git a/psydac/fem/partitioning.py b/psydac/fem/partitioning.py index 804cf87e2..de3a3acaf 100644 --- a/psydac/fem/partitioning.py +++ b/psydac/fem/partitioning.py @@ -2,12 +2,6 @@ import os import numpy as np -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import CartDecomposition, InterfaceCartDecomposition, create_interfaces_cart from psydac.core.bsplines import elements_spans diff --git a/psydac/fem/tensor.py b/psydac/fem/tensor.py index 02203922c..70f849c69 100644 --- a/psydac/fem/tensor.py +++ b/psydac/fem/tensor.py @@ -5,12 +5,7 @@ of compact support """ -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI import numpy as np import itertools diff --git a/psydac/fem/tests/test_spline_interpolation.py b/psydac/fem/tests/test_spline_interpolation.py index b2777a46b..b572e45b8 100644 --- a/psydac/fem/tests/test_spline_interpolation.py +++ b/psydac/fem/tests/test_spline_interpolation.py @@ -1,12 +1,7 @@ # coding: utf-8 # Copyright 2018 Yaman Güçlü -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI import numpy as np import pytest diff --git a/psydac/fem/tests/test_splines_par.py b/psydac/fem/tests/test_splines_par.py index 4c62b7734..081d26074 100644 --- a/psydac/fem/tests/test_splines_par.py +++ b/psydac/fem/tests/test_splines_par.py @@ -7,14 +7,9 @@ from psydac.fem.tensor import TensorFemSpace from psydac.fem.vector import VectorFemSpace from psydac.ddm.cart import DomainDecomposition +from psydac.ddm.mpi import mpi as MPI from numpy import linspace -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI def test_2d_1(): diff --git a/psydac/linalg/block.py b/psydac/linalg/block.py index 8e9ce7a48..7db84a9f4 100644 --- a/psydac/linalg/block.py +++ b/psydac/linalg/block.py @@ -1064,13 +1064,7 @@ def compute_interface_matrices_transpose(self): if not self.codomain.parallel: return blocks, blocks_T - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilInterfaceMatrix if not isinstance(self.codomain, BlockVectorSpace): diff --git a/psydac/linalg/stencil.py b/psydac/linalg/stencil.py index c8fac007b..85b03c4e4 100644 --- a/psydac/linalg/stencil.py +++ b/psydac/linalg/stencil.py @@ -9,13 +9,8 @@ from types import MappingProxyType from scipy.sparse import coo_matrix, diags as sp_diags -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from psydac.linalg.basic import VectorSpace, Vector, LinearOperator from psydac.ddm.cart import find_mpi_type, CartDecomposition, InterfaceCartDecomposition from psydac.ddm.utilities import get_data_exchanger diff --git a/psydac/linalg/tests/test_block.py b/psydac/linalg/tests/test_block.py index 880f316a6..00badb580 100644 --- a/psydac/linalg/tests/test_block.py +++ b/psydac/linalg/tests/test_block.py @@ -4,13 +4,8 @@ import numpy as np from scipy.sparse import csr_matrix from random import random, seed -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from psydac.linalg.direct_solvers import SparseSolver from psydac.linalg.stencil import StencilVectorSpace, StencilVector, StencilMatrix from psydac.linalg.block import BlockVectorSpace, BlockVector diff --git a/psydac/linalg/tests/test_fft.py b/psydac/linalg/tests/test_fft.py index d3fa6fed7..014ce95eb 100644 --- a/psydac/linalg/tests/test_fft.py +++ b/psydac/linalg/tests/test_fft.py @@ -1,13 +1,8 @@ import pytest import scipy.fft as scifft import numpy as np -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from psydac.linalg.fft import * from psydac.ddm.cart import DomainDecomposition, CartDecomposition from psydac.linalg.stencil import StencilVector diff --git a/psydac/linalg/tests/test_stencil_interface_matrix.py b/psydac/linalg/tests/test_stencil_interface_matrix.py index 499f3a61b..b0fa74f08 100644 --- a/psydac/linalg/tests/test_stencil_interface_matrix.py +++ b/psydac/linalg/tests/test_stencil_interface_matrix.py @@ -226,13 +226,7 @@ def test_stencil_interface_matrix_3d_serial_init(dtype, n1, n2, n3, p1, p2, p3, @pytest.mark.parallel def test_stencil_interface_matrix_2d_parallel_dot(n1, n2, p1, p2, expected): - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from mpi4py import MPI - else: - from psydac.ddm.mpi import mpi as MPI - + from psydac.ddm.mpi import mpi as MPI from psydac.ddm.cart import MultiPatchDomainDecomposition, CartDecomposition, create_interfaces_cart from psydac.linalg.block import BlockVectorSpace, BlockVector, BlockLinearOperator diff --git a/psydac/linalg/tests/test_stencil_vector.py b/psydac/linalg/tests/test_stencil_vector.py index 2f3a78ac8..3b95419bd 100644 --- a/psydac/linalg/tests/test_stencil_vector.py +++ b/psydac/linalg/tests/test_stencil_vector.py @@ -2,13 +2,8 @@ import pytest import numpy as np -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilVectorSpace, StencilVector, StencilMatrix from psydac.linalg.utilities import array_to_psydac, petsc_to_psydac from psydac.ddm.cart import DomainDecomposition, CartDecomposition diff --git a/psydac/linalg/tests/test_stencil_vector_space.py b/psydac/linalg/tests/test_stencil_vector_space.py index 31388fe2e..7ada7ca50 100644 --- a/psydac/linalg/tests/test_stencil_vector_space.py +++ b/psydac/linalg/tests/test_stencil_vector_space.py @@ -1,12 +1,7 @@ import pytest import numpy as np -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from mpi4py import MPI -else: - from psydac.ddm.mpi import mpi as MPI +from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilVectorSpace, StencilVector from psydac.ddm.cart import DomainDecomposition, CartDecomposition, find_mpi_type From 8a7326330712ea4108566843029785a1054af6d3 Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Mon, 20 Oct 2025 08:14:19 +0200 Subject: [PATCH 11/13] set mpi_enabled to True if mpi4py is installed, TODO: check if it runs under mpirun --- psydac/ddm/mpi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psydac/ddm/mpi.py b/psydac/ddm/mpi.py index 7c9abf240..40f29ef06 100644 --- a/psydac/ddm/mpi.py +++ b/psydac/ddm/mpi.py @@ -80,7 +80,7 @@ def COMM_WORLD(self): _comm = MPI.COMM_WORLD rank = _comm.Get_rank() size = _comm.Get_size() - mpi_enabled = size > 1 + mpi_enabled = True except ImportError: # mpi4py not installed mpi_enabled = False From 6f632dc34d426ea2bc8e6872ef449d179b642f1d Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Mon, 20 Oct 2025 08:48:50 +0200 Subject: [PATCH 12/13] test with updated struphy branch From 9a4ea9a02600d7b046620866826a9e6c77685e6c Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Mon, 20 Oct 2025 09:53:28 +0200 Subject: [PATCH 13/13] test with updated struphy branch