Skip to content

Commit 5393653

Browse files
Only test MPI if installed
1 parent 0669172 commit 5393653

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

hendrics/parallel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from multiprocessing import Pool
33

44
import numpy as np
5-
from mpi4py import MPI
65
from stingray import AveragedPowerspectrum, EventList
76
from stingray.fourier import positive_fft_bins
87
from stingray.gti import time_intervals_from_gtis
@@ -169,6 +168,8 @@ def main_mpi(fname, sample_time, segment_size):
169168
and dependencies are available.
170169
- Only the rank responsible for the final reduction returns the results; other ranks return None.
171170
"""
171+
from mpi4py import MPI
172+
172173
tsreader = FITSTimeseriesReader(fname, output_class=EventList)
173174

174175
def data_lookup():

hendrics/tests/test_parallel.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
import subprocess as sp
23
import tempfile
34

@@ -8,6 +9,12 @@
89
from hendrics.fake import main as main_fake
910
from hendrics.parallel import main as main_parallel
1011

12+
HAS_MPI = importlib.util.find_spec("mpi4py") is not None
13+
14+
test_cases = ["none", "multiprocessing"]
15+
if HAS_MPI:
16+
test_cases.append("mpi")
17+
1118

1219
class TestParallel:
1320
def setup_class(cls):
@@ -21,7 +28,7 @@ def setup_class(cls):
2128
cls.events, dt=0.1, segment_size=10.0, use_common_mean=False, norm="leahy"
2229
)
2330

24-
@pytest.mark.parametrize("method", ["none", "multiprocessing", "mpi"])
31+
@pytest.mark.parametrize("method", test_cases)
2532
@pytest.mark.parametrize("norm", ["leahy", "frac", "abs"])
2633
def test_parallel_versions(self, method, norm):
2734
out_file = tempfile.NamedTemporaryFile(suffix=".hdf5", delete=False)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ test_all = [
5858
"numba",
5959
"netcdf4==1.7.0",
6060
"scikit-image",
61-
"statsmodels"
61+
"statsmodels",
62+
"mpi4py",
6263
]
6364
recommended = [
6465
"numba",

0 commit comments

Comments
 (0)