FESTIM
FESTIM copied to clipboard
Script testing in series and parallel
Saw this in the FEniCSx repo, a nice little way to test the demo scripts both in series and in parallel. Could be useful to incooperate something similar in FESTIM in the future:
import subprocess
import sys
import pytest
# Get directory of this file
path = pathlib.Path(__file__).resolve().parent
# Build list of demo programs
demos = []
demo_files = list(path.glob('**/*.py'))
for f in demo_files:
demos.append((f.parent, f.name))
@pytest.mark.serial
@pytest.mark.parametrize("path,name", demos)
def test_demos(path, name):
ret = subprocess.run([sys.executable, name], cwd=str(path), check=True)
assert ret.returncode == 0
@pytest.mark.mpi
@pytest.mark.parametrize("path,name", demos)
def test_demos_mpi(num_proc, mpiexec, path, name):
cmd = [mpiexec, "-np", str(num_proc), sys.executable, name]
print(cmd)
ret = subprocess.run(cmd, cwd=str(path), check=True)
assert ret.returncode == 0```
Why not!
hi ! I proposed what I think could be a solution. Thank you for your time and feedback, I hope to make it functional for the project!
@jorgensd has the solution for testing in parallel: using IPyParallel it allows you to start a cluster on n processes in a script/notebook
We can use https://github.com/jorgensd/adios4dolfinx/blob/main/tests/conftest.py#L1-L19 that @minrk helped me set up.