test_mesh.py test_shared_entities [shared_vertex-mesh_factory8] python unit test fails with MPI

Issue #1131 new
Drew Parsons created an issue

The debian build of dolfin has started failing MPI unit tests in test_mesh.py test_shared_entities [shared_vertex-mesh_factory8]:
The error message is

>           assert num_entities_global ==  mesh.num_entities_global(shared_dim)
E           assert 56.0 == 48

The error can be reproduced manually:

$ mpirun -n 3 python3 -m pytest -v --durations=20 -k "shared_vertex-mesh_factory8" python/test/unit/
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.4, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3
=============================================================================================== test session starts ===============================================================================================
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.4, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3
platform linux -- Python 3.10.4, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/build/dolfin/.hypothesis/examples')
rootdir: /build/dolfin/python
plugins: asyncio-0.18.2, xvfb-2.0.0, arraydiff-0.5.0, cov-3.0.0, hypothesis-6.36.0, flaky-3.7.0, astropy-header-0.2.1, remotedata-0.3.3, filter-subpackage-0.1.1, doctestplus-0.12.0, mpi-0.6, openfiles-0.5.0, mock-3.6.1
asyncio: mode=legacy
collecting ... cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/build/dolfin/.hypothesis/examples')
rootdir: /build/dolfin/python
plugins: asyncio-0.18.2, xvfb-2.0.0, arraydiff-0.5.0, cov-3.0.0, hypothesis-6.36.0, flaky-3.7.0, astropy-header-0.2.1, remotedata-0.3.3, filter-subpackage-0.1.1, doctestplus-0.12.0, mpi-0.6, openfiles-0.5.0, mock-3.6.1
asyncio: mode=legacy
collecting ... cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/build/dolfin/.hypothesis/examples')
rootdir: /build/dolfin/python
plugins: asyncio-0.18.2, xvfb-2.0.0, arraydiff-0.5.0, cov-3.0.0, hypothesis-6.36.0, flaky-3.7.0, astropy-header-0.2.1, remotedata-0.3.3, filter-subpackage-0.1.1, doctestplus-0.12.0, mpi-0.6, openfiles-0.5.0, mock-3.6.1
asyncio: mode=legacy
collected 1297 items / 1294 deselected / 3 selected                                                                                                                                                               

collected 1297 items / 1294 deselected / 3 selected                                                                                                                                                               
collected 1297 items / 1294 deselected / 3 selected                                                                                                                                                               

python/test/unit/mesh/test_mesh.py::test_shared_entities[shared_vertex-mesh_factory8] 
python/test/unit/mesh/test_mesh.py::test_shared_entities[shared_vertex-mesh_factory8] FAILED                                                                                                                [ 33%]FAILED                                                                                                                [ 33%]FAILED                                                                                                                [ 33%]
python/test/unit/mesh/test_mesh.py::test_mesh_topology_against_fiat[shared_vertex-mesh_factory8] 
python/test/unit/mesh/test_mesh.py::test_mesh_topology_against_fiat[shared_vertex-mesh_factory8] 
python/test/unit/mesh/test_mesh.py::test_mesh_topology_against_fiat[shared_vertex-mesh_factory8] PASSED                                                                                                     [ 66%]PASSED                                                                                                     [ 66%]PASSED                                                                                                     [ 66%]
python/test/unit/mesh/test_mesh.py::test_mesh_ufc_ordering[shared_vertex-mesh_factory8] 
python/test/unit/mesh/test_mesh.py::test_mesh_ufc_ordering[shared_vertex-mesh_factory8] 
python/test/unit/mesh/test_mesh.py::test_mesh_ufc_ordering[shared_vertex-mesh_factory8] PASSED                                                                                                              [100%]PASSED                                                                                                              [100%]PASSED                                                                                                              [100%]





==================================================================================================== FAILURES =====================================================================================================
==================================================================================================== FAILURES =====================================================================================================
==================================================================================================== FAILURES =====================================================================================================
________________________________________________________________________________ test_shared_entities[shared_vertex-mesh_factory8] ________________________________________________________________________________
________________________________________________________________________________ test_shared_entities[shared_vertex-mesh_factory8] ________________________________________________________________________________


________________________________________________________________________________ test_shared_entities[shared_vertex-mesh_factory8] ________________________________________________________________________________

mesh_factory = (<class 'dolfin.cpp.generation.UnitCubeMesh'>, (2, 2, 2)), ghost_mode = 'shared_vertex'

mesh_factory = (<class 'dolfin.cpp.generation.UnitCubeMesh'>, (2, 2, 2)), ghost_mode = 'shared_vertex'

mesh_factory = (<class 'dolfin.cpp.generation.UnitCubeMesh'>, (2, 2, 2)), ghost_mode = 'shared_vertex'

    @pytest.mark.parametrize('mesh_factory', mesh_factories_broken_shared_entities)
    def test_shared_entities(mesh_factory, ghost_mode):
        func, args = mesh_factory
        xfail_ghosted_quads_hexes(func, ghost_mode)
        mesh = func(*args)
        dim = mesh.topology().dim()

        # FIXME: Implement a proper test
        for shared_dim in range(dim + 1):
            # Initialise global indices (if not already)
            mesh.init_global(shared_dim)

            assert isinstance(mesh.topology().shared_entities(shared_dim), dict)
            assert isinstance(mesh.topology().global_indices(shared_dim),
                              numpy.ndarray)

            if mesh.topology().have_shared_entities(shared_dim):
                for e in entities(mesh, shared_dim):
                    sharing = e.sharing_processes()
                    assert isinstance(sharing, set)
                    assert (len(sharing) > 0) == e.is_shared()

            n_entities = mesh.num_entities(shared_dim)
            n_global_entities = mesh.num_entities_global(shared_dim)
            shared_entities = mesh.topology().shared_entities(shared_dim)

            # Check that sum(local-shared) = global count
            rank = MPI.rank(mesh.mpi_comm())
            ct = sum(1 for val in shared_entities.values() if list(val)[0] < rank)
            num_entities_global = MPI.sum(mesh.mpi_comm(), mesh.num_entities(shared_dim) - ct)

>           assert num_entities_global ==  mesh.num_entities_global(shared_dim)
E           assert 56.0 == 48
E             +56.0
E             -48

python/test/unit/mesh/test_mesh.py:622: AssertionError
    @pytest.mark.parametrize('mesh_factory', mesh_factories_broken_shared_entities)
    def test_shared_entities(mesh_factory, ghost_mode):
        func, args = mesh_factory
        xfail_ghosted_quads_hexes(func, ghost_mode)
================================================================================================ warnings summary =================================================================================================
        mesh = func(*args)
        dim = mesh.topology().dim()

        # FIXME: Implement a proper test
        for shared_dim in range(dim + 1):
            # Initialise global indices (if not already)
            mesh.init_global(shared_dim)

            assert isinstance(mesh.topology().shared_entities(shared_dim), dict)
            assert isinstance(mesh.topology().global_indices(shared_dim),
                              numpy.ndarray)

            if mesh.topology().have_shared_entities(shared_dim):
                for e in entities(mesh, shared_dim):
                    sharing = e.sharing_processes()
                    assert isinstance(sharing, set)
                    assert (len(sharing) > 0) == e.is_shared()

../../../../../../usr/lib/python3/dist-packages/pytest_asyncio/plugin.py:191
            n_entities = mesh.num_entities(shared_dim)
  /usr/lib/python3/dist-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

            n_global_entities = mesh.num_entities_global(shared_dim)
            shared_entities = mesh.topology().shared_entities(shared_dim)

            # Check that sum(local-shared) = global count
            rank = MPI.rank(mesh.mpi_comm())
            ct = sum(1 for val in shared_entities.values() if list(val)[0] < rank)
            num_entities_global = MPI.sum(mesh.mpi_comm(), mesh.num_entities(shared_dim) - ct)

>           assert num_entities_global ==  mesh.num_entities_global(shared_dim)
../../../../../../usr/lib/python3/dist-packages/dolfin_utils/test/fixtures.py:96
E           assert 56.0 == 48
E             +56.0
  /usr/lib/python3/dist-packages/dolfin_utils/test/fixtures.py:96: PytestDeprecationWarning: @pytest.yield_fixture is deprecated.
  Use @pytest.fixture instead; they are the same.
    @pytest.yield_fixture(scope="function")E             -48



python/test/unit/mesh/test_mesh.py:622: AssertionError
../../../../../../usr/lib/python3/dist-packages/dolfin_utils/test/fixtures.py:230
  /usr/lib/python3/dist-packages/dolfin_utils/test/fixtures.py:230: PytestDeprecationWarning: @pytest.yield_fixture is deprecated.
  Use @pytest.fixture instead; they are the same.
    @pytest.yield_fixture(scope="function")

    @pytest.mark.parametrize('mesh_factory', mesh_factories_broken_shared_entities)
    def test_shared_entities(mesh_factory, ghost_mode):
        func, args = mesh_factory

The test passes running in a single process.