Skip to content

Commit 8f421c4

Browse files
authored
Do not use Makefile for firedrake-check (#4391)
* Fix firedrake-check for some systems where running the parallel tests would fail. * Move firedrake-check outside firedrake package This should avoid CI failures due to forking mpiexec after importing Firedrake.
1 parent 11d377d commit 8f421c4

File tree

6 files changed

+94
-49
lines changed

6 files changed

+94
-49
lines changed

Makefile

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,6 @@ clean:
8888
@echo " RM tinyasm/*.so"
8989
-@rm -f tinyasm/*.so > /dev/null 2>&1
9090

91-
# Do verbose checking if running on CI and always set no:cacheprovider because
92-
# we don't want to generate any cache files in $VIRTUAL_ENV/lib/.../firedrake/_check
93-
check_flags =
94-
ifeq ($(FIREDRAKE_CI), 1)
95-
check_flags = --verbose -p no:cacheprovider
96-
else
97-
check_flags = --quiet -p no:cacheprovider
98-
endif
99-
100-
CHECK_PYTEST_ARGS =
101-
102-
.PHONY: check
103-
check:
104-
@echo " Running serial smoke tests"
105-
@python3 -m pytest $(check_flags) $(CHECK_PYTEST_ARGS) \
106-
tests/firedrake/regression/test_stokes_mini.py::test_stokes_mini \
107-
tests/firedrake/regression/test_locate_cell.py `# spatialindex` \
108-
tests/firedrake/supermesh/test_assemble_mixed_mass_matrix.py::test_assemble_mixed_mass_matrix[2-CG-CG-0-0] `# supermesh` \
109-
tests/firedrake/regression/test_matrix_free.py::test_fieldsplitting[parameters3-cofunc_rhs-variational] `# fieldsplit` \
110-
tests/firedrake/regression/test_nullspace.py::test_near_nullspace `# near nullspace`
111-
@echo " Serial tests passed"
112-
@echo " Running parallel smoke tests"
113-
@mpiexec -n 3 python3 -m pytest $(check_flags) $(CHECK_PYTEST_ARGS) -m parallel[3] \
114-
tests/firedrake/regression/test_dg_advection.py::test_dg_advection_icosahedral_sphere \
115-
tests/firedrake/regression/test_interpolate_cross_mesh.py::test_interpolate_cross_mesh_parallel[extrudedcube] `# vertex-only mesh`
116-
@echo " Parallel tests passed"
117-
11891
.PHONY: durations
11992
durations:
12093
@echo " Generate timings to optimise pytest-split"

firedrake/_check/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
"""Run the Firedrake smoke tests."""
2-
3-
import pathlib
4-
import subprocess
5-
6-
7-
def main() -> None:
8-
dir = pathlib.Path(__file__).parent
9-
subprocess.run(f"make -C {dir} check".split(), errors=True)

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Repository = "https://github.com/firedrakeproject/firedrake"
5656
Issues = "https://github.com/firedrakeproject/firedrake/issues/new/choose"
5757

5858
[project.scripts]
59-
firedrake-check = "firedrake._check:main"
6059
firedrake-clean = "firedrake.scripts.firedrake_clean:main"
6160
firedrake-preprocess-bibtex = "firedrake.scripts.firedrake_preprocess_bibtex:main"
6261
firedrake-status = "firedrake.scripts.firedrake_status:main"
@@ -65,7 +64,7 @@ pyop2-clean = "pyop2.compilation:clear_compiler_disk_cache"
6564

6665
[project.optional-dependencies]
6766
check = [
68-
"mpi-pytest",
67+
"mpi-pytest>=2025.7",
6968
"pytest",
7069
]
7170
docs = [
@@ -103,7 +102,7 @@ ci = [
103102
"ipympl", # needed for notebook testing
104103
"jax",
105104
"matplotlib",
106-
"mpi-pytest",
105+
"mpi-pytest>=2025.7",
107106
"nbval",
108107
"ngsPETSc",
109108
"pylit",
@@ -118,7 +117,7 @@ ci = [
118117
docker = [ # Used in firedrake-vanilla container
119118
"ipympl", # needed for notebook testing
120119
"matplotlib",
121-
"mpi-pytest",
120+
"mpi-pytest>=2025.7",
122121
"nbval",
123122
"pylit",
124123
"pytest",
@@ -147,6 +146,7 @@ build-backend = "setuptools.build_meta"
147146
[tool.setuptools]
148147
script-files = [
149148
"firedrake/scripts/firedrake-zenodo",
149+
"scripts/firedrake-check",
150150
"scripts/firedrake-run-split-tests",
151151
"pyop2/scripts/spydump",
152152
]

scripts/firedrake-check

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
3+
"""Run the Firedrake smoke tests."""
4+
5+
import argparse
6+
import logging
7+
import importlib
8+
import os
9+
import pathlib
10+
import subprocess
11+
import sys
12+
13+
14+
# smoke tests grouped by number of processors
15+
TESTS = {
16+
1: (
17+
"tests/firedrake/regression/test_stokes_mini.py::test_stokes_mini",
18+
# spatialindex
19+
"tests/firedrake/regression/test_locate_cell.py",
20+
# supermesh
21+
"tests/firedrake/supermesh/test_assemble_mixed_mass_matrix.py::test_assemble_mixed_mass_matrix[2-CG-CG-0-0]",
22+
# fieldsplit
23+
"tests/firedrake/regression/test_matrix_free.py::test_fieldsplitting[parameters3-cofunc_rhs-variational]",
24+
# near nullspace
25+
"tests/firedrake/regression/test_nullspace.py::test_near_nullspace",
26+
),
27+
3: (
28+
"tests/firedrake/regression/test_dg_advection.py::test_dg_advection_icosahedral_sphere[nprocs=3]",
29+
# vertex-only mesh
30+
"tests/firedrake/regression/test_interpolate_cross_mesh.py::test_interpolate_cross_mesh_parallel[extrudedcube]",
31+
),
32+
}
33+
34+
35+
# log to terminal at INFO level
36+
logging.basicConfig(format="%(message)s", level=logging.INFO)
37+
38+
39+
def main() -> None:
40+
args = parse_args()
41+
42+
for nprocs, tests in TESTS.items():
43+
if nprocs == 1:
44+
logging.info(" Running serial smoke tests")
45+
else:
46+
logging.info(f" Running parallel smoke tests (nprocs={nprocs})")
47+
run_tests(tests, nprocs, args.mpiexec)
48+
logging.info(" Tests passed")
49+
50+
51+
def parse_args() -> argparse.Namespace:
52+
parser = argparse.ArgumentParser()
53+
parser.add_argument(
54+
"--mpiexec",
55+
type=str,
56+
default="mpiexec -n",
57+
help=(
58+
"Command used to launch MPI. The command must end with the flag "
59+
"taking the number of processors, e.g. '-n' for mpiexec."
60+
),
61+
)
62+
return parser.parse_args()
63+
64+
65+
def run_tests(tests: tuple[str], nprocs: int, mpiexec: str) -> None:
66+
# Find the path to firedrake._check. Don't actually import Firedrake here
67+
# because that will initialise MPI and can prevent us calling 'mpiexec'
68+
# below. This only causes issues on some systems.
69+
firedrake_dir = pathlib.Path(
70+
importlib.util.find_spec("firedrake").origin
71+
).parent
72+
test_dir = firedrake_dir / "_check"
73+
74+
# Do verbose checking if running on CI and always set no:cacheprovider because
75+
# we don't want to generate any cache files in $VIRTUAL_ENV/lib/.../firedrake/_check
76+
if "FIREDRAKE_CI" in os.environ:
77+
check_flags = "--verbose -p no:cacheprovider"
78+
else:
79+
check_flags = "--quiet -p no:cacheprovider"
80+
81+
cmd = f"{mpiexec} {nprocs} {sys.executable} -m pytest {check_flags} -m parallel[{nprocs}]".split()
82+
cmd.extend(tests)
83+
84+
subprocess.run(cmd, cwd=test_dir, check=True)
85+
86+
87+
if __name__ == "__main__":
88+
main()

scripts/firedrake-run-split-tests

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ extra_args=${@:3}
3535
cache_cmd="PYOP2_CACHE_DIR=\$VIRTUAL_ENV/.cache/pyop2/job{#} \
3636
FIREDRAKE_TSFC_KERNEL_CACHE_DIR=\$VIRTUAL_ENV/.cache/tsfc/job{#}"
3737

38-
if [ $num_procs = 1 ]; then
39-
pytest_exec="python3 -m pytest"
40-
marker_spec="\"parallel[1] or not parallel\""
41-
else
42-
pytest_exec="mpiexec -n ${num_procs} python3 -m pytest"
43-
marker_spec="parallel[${num_procs}]"
44-
fi
38+
pytest_exec="mpiexec -n ${num_procs} python -m pytest"
39+
marker_spec="parallel[${num_procs}]"
4540

4641
pytest_cmd="${pytest_exec} -v \
4742
--splits ${num_jobs} --group {#} \

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def extensions():
237237
return cythonize(cython_list) + pybind11_list
238238

239239

240-
# TODO: It would be good to have a single source of truth for these files
241240
FIREDRAKE_CHECK_FILES = (
242-
"Makefile",
243241
"tests/firedrake/conftest.py",
244242
"tests/firedrake/regression/test_stokes_mini.py",
245243
"tests/firedrake/regression/test_locate_cell.py",

0 commit comments

Comments
 (0)