Skip to content

Commit

Permalink
Fixing missing coverage during parallel runs
Browse files Browse the repository at this point in the history
  • Loading branch information
pancetta committed Dec 23, 2022
1 parent 4205d75 commit 729cb69
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ jobs:
- name: Run pytest for CPU stuff
run: |
coverage run --data-file=coverage_${{ matrix.env }}_${{ matrix.python }}.dat -m pytest --continue-on-collection-errors -v --durations=0 pySDC/tests -m ${{ matrix.env }}
coverage run -m pytest --continue-on-collection-errors -v --durations=0 pySDC/tests -m ${{ matrix.env }}
mv data data_${{ matrix.python }}
coverage combine
mv .coverage coverage_${{ matrix.env }}_${{ matrix.python }}.dat
- name: Uploading artifacts
uses: actions/upload-artifact@v3
Expand Down
5 changes: 5 additions & 0 deletions pySDC/projects/parallelSDC/AllenCahn_parallel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
import os

import numpy as np
from mpi4py import MPI
Expand Down Expand Up @@ -172,6 +173,10 @@ def main():
run_variant(variant='ml_serial')
print()

my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'

cmd = (
"mpirun -np 3 python -c \"from pySDC.projects.parallelSDC.AllenCahn_parallel import *; "
"run_variant(\'sl_parallel\');\""
Expand Down
9 changes: 7 additions & 2 deletions pySDC/tests/test_projects/test_AC/test_simple_forcing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import subprocess
import os


@pytest.mark.mpi4py
Expand All @@ -17,18 +18,22 @@ def test_main_parallel():
# try to import MPI here, will fail if things go wrong (and not later on in the subprocess part)
import mpi4py

my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'

nprocs = 2
cmd = f"export PYTHONPATH=$PYTHONPATH:$(pwd); export HWLOC_HIDE_ERRORS=2; mpirun -np {nprocs} python pySDC/projects/AllenCahn_Bayreuth/run_simple_forcing_benchmark.py -n {nprocs}"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
p.wait()
(output, err) = p.communicate()
print(output)
assert err == ''
assert err == '', err

nprocs = 4
cmd = f"export PYTHONPATH=$PYTHONPATH:$(pwd); export HWLOC_HIDE_ERRORS=2; mpirun -np {nprocs} python pySDC/projects/AllenCahn_Bayreuth/run_simple_forcing_benchmark.py -n {nprocs}"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
p.wait()
(output, err) = p.communicate()
print(output)
assert err == ''
assert err == '', err
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_preconditioner_playground_MPI_5():
# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'
cwd = '.'
num_procs = 5
cmd = (
Expand All @@ -29,6 +30,7 @@ def test_preconditioner_playground_MPI_3():
# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'
cwd = '.'
num_procs = 3
cmd = (
Expand Down
3 changes: 2 additions & 1 deletion pySDC/tests/test_projects/test_resilience/test_vdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def test_main():

# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../../..:.'
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'

# set list of number of parallel steps (even)
num_procs_list = [1, 2, 5, 8]
Expand Down
3 changes: 3 additions & 0 deletions pySDC/tests/test_tutorials/test_step_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_C_1x1():
# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
# my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'
fname = 'step_7_C_out_1x1.txt'
cwd = '.'
num_procs = 1
Expand Down Expand Up @@ -54,6 +55,7 @@ def test_C_1x2():
# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'
cwd = '.'
fname = 'step_7_C_out_1x2.txt'
num_procs = 2
Expand Down Expand Up @@ -83,6 +85,7 @@ def test_C_2x2():
# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'
cwd = '.'
fname = 'step_7_C_out_2x2.txt'
num_procs = 4
Expand Down
1 change: 1 addition & 0 deletions pySDC/tutorial/step_6/C_MPI_parallelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def main(cwd):
# Set python path once
my_env = os.environ.copy()
my_env['PYTHONPATH'] = '../../..:.'
my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml'

# set list of number of parallel steps (even)
num_procs_list = [1, 2, 4, 8]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ exclude = '''playgrounds/'''
[tool.coverage.run]
omit = ['*/pySDC/tests/*', '*/data/*', '*/pySDC/playgrounds/*', '*/pySDC/projects/deprecated/*']
relative_files = true
concurrency = ['multiprocessing']

[tool.coverage.report]
skip_empty = true
Expand Down
2 changes: 2 additions & 0 deletions sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import coverage
coverage.process_startup()

0 comments on commit 729cb69

Please sign in to comment.