Open drew-parsons opened 2 years ago
I note the github dolfinx CI tests here use pytest 7.1.2 and do not use pytest-mpi. The github test is python3 -m pytest -m mpi --num-proc=2 python/demo/test.py
.
If I run that in verbose on my system, it tells me --with-mpi
needs to be specified
/projects/fenics-dolfinx$ python3 -m pytest -m mpi -v --num-proc=2 python/demo/test.py
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.5, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/projects/fenics-dolfinx/.hypothesis/examples')
rootdir: /projects/fenics-dolfinx/python/demo, configfile: pytest.ini
plugins: xvfb-2.0.0, arraydiff-0.5.0, cov-3.0.0, mock-3.7.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, asyncio-0.18.3, mpi-0.6, openfiles-0.5.0, astropy-0.10.0
asyncio: mode=auto
collected 26 items / 13 deselected / 13 selected
python/demo/test.py::test_demos_mpi[path0-demo_elasticity.py] SKIPPED (need --with-mpi option to run) [ 7%]
python/demo/test.py::test_demos_mpi[path1-demo_gmsh.py] SKIPPED (need --with-mpi option to run) [ 15%]
python/demo/test.py::test_demos_mpi[path2-demo_lagrange_variants.py] SKIPPED (need --with-mpi option to run) [ 23%]
python/demo/test.py::test_demos_mpi[path3-demo_types.py] SKIPPED (need --with-mpi option to run) [ 30%]
python/demo/test.py::test_demos_mpi[path4-demo_pyvista.py] SKIPPED (need --with-mpi option to run) [ 38%]
python/demo/test.py::test_demos_mpi[path5-demo_interpolation-io.py] SKIPPED (need --with-mpi option to run) [ 46%]
python/demo/test.py::test_demos_mpi[path6-demo_static-condensation.py] SKIPPED (need --with-mpi option to run) [ 53%]
python/demo/test.py::test_demos_mpi[path7-demo_cahn-hilliard.py] SKIPPED (need --with-mpi option to run) [ 61%]
python/demo/test.py::test_demos_mpi[path8-test.py] SKIPPED (need --with-mpi option to run) [ 69%]
python/demo/test.py::test_demos_mpi[path9-demo_poisson.py] SKIPPED (need --with-mpi option to run) [ 76%]
python/demo/test.py::test_demos_mpi[path10-demo_helmholtz.py] SKIPPED (need --with-mpi option to run) [ 84%]
python/demo/test.py::test_demos_mpi[path11-conftest.py] SKIPPED (need --with-mpi option to run) [ 92%]
python/demo/test.py::test_demos_mpi[path12-demo_stokes.py] SKIPPED (need --with-mpi option to run) [100%]
======================================================================================= 13 skipped, 13 deselected in 0.28s ========================================================================================
So there is a discrepancy between the github test environment and the debian environment, with pytest-mpi being the obvious discrepancy. It's not used in github CI, and if I remove it from my system then the MPI python demo tests proceed (and pass) in the same way as github CI.
So one solution is not to have pytest-mpi installed. It's a bigger (and known) problem with pytest that it loads all available plugins regardless or whether they're wanted, unless -p no:mpi is used. But I can't see any changes in pytest 7 that would cause pytest-mpi to start failing, but clearly there's a problem somewhere.
So the problem is the interaction between the dolfinx python demo tests, pytest (v7 or otherwise) and the pytest-mpi plugin. I'll updating the title to identify pytest-mpi as the core problem.
In my case, I need pytest-mpi installed for the purpose of testing h5py, and the dolfinx test failure is collateral damage. So for me a sufficient work-around is to explicitly apply -p no:mpi
to switch off the plugin, running tests with something like
python3 -m pytest -p no:mpi -m mpi --num-proc=2 python/demo/test.py
That combination "-p no:mpi -m mpi" looks a bit weird, the left hand is removing what the right hand is putting in place. But to run the dolfinx python demos in MPI mode it seems to be the only way to do it if the pytest-mpi plugin is installed.
dolfinx/python/demo/test.py creates its own custom marker mpi, i.e. the -m mpi
in python3 -m pytest -m mpi
is a pytest marker not a python module (the pytest API is confusing!).
Could it be useful for dolfinx to switch to using the pytest-mpi plugin instead?
I'm not familiar with pytest-mpi
. If it works well and is maintained we could use it. It would allow us to remove some custom pytest
decorators.
I'll look into it further and see if it's easy to adapt to it
@drew-parsons is this still an issue?
Dolfinx (0.4.1) provides python demos in python/demo, together with test.py to run the tests with pytest.
On a debian build the demos run successfully on their own, e.g.
mpiexec -np 3 python3 demo_poisson.py
generates poisson.xdmf as expected in the out_poisson dir. We don't have pyvista, but the try: except block prevents that from triggering an error.Running demo/test.py in serial mode succeeds. But trying to run the demos with pytest and mpi fails, e.g. (testing only the poisson demo for simplicity)
A full debian CI test log showing the same problem can be seen at https://ci.debian.net/data/autopkgtest/unstable/amd64/f/fenics-dolfinx/23085308/log.gz
So pytest says the subprocess is failing. But the command in question,
mpiexec -np 3 /usr/bin/python3 demo_poisson.py
runs perfectly fine on its own.The problem must lie in the way pytest handles mpi jobs as subprocesses. But the pytest-mpi plugin is supposed to faciltate MPI tests.
Worth noting that the tests previously passed fine, https://ci.debian.net/data/autopkgtest/unstable/amd64/f/fenics-dolfinx/22512767/log.gz At that point the debian system had
Now in the failing case the updated packages are
Since the dolfinx demo runs fine outside pytest, we can point the finger at the pytest upgrade. Maybe it means pytest-mpi needs to be patched to match the new pytest.
Does anyone know how to fix the problem?