FESTIM icon indicating copy to clipboard operation
FESTIM copied to clipboard

Script testing in series and parallel

Open jhdark opened this issue 2 years ago • 2 comments

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```

jhdark avatar Jun 26 '23 12:06 jhdark

Why not!

RemDelaporteMathurin avatar Jun 26 '23 12:06 RemDelaporteMathurin

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!

tadash10 avatar Dec 01 '23 21:12 tadash10

@jorgensd has the solution for testing in parallel: using IPyParallel it allows you to start a cluster on n processes in a script/notebook

RemDelaporteMathurin avatar Oct 25 '24 18:10 RemDelaporteMathurin

We can use https://github.com/jorgensd/adios4dolfinx/blob/main/tests/conftest.py#L1-L19 that @minrk helped me set up.

jorgensd avatar Oct 25 '24 18:10 jorgensd