1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
# fmt: off
import sys
from subprocess import run
import pytest
from ase.parallel import world
def test_mpi():
x = 42.0
with pytest.warns(FutureWarning):
x = world.sum(x)
x = world.sum_scalar(x)
assert x == 42 * world.size
@pytest.mark.skip(reason='Does not work and no time to investigate.')
def test_mpi_unused_on_import():
"""Try to import all ASE modules and check that ase.parallel.world has not
been used. We want to delay use of world until after MPI4PY has been
imported.
We run the test in a subprocess so that we have a clean Python
interpreter."""
# Should cover most of ASE:
modules = ['ase.optimize',
'ase.db',
'ase.gui']
imports = 'import ' + ', '.join(modules)
run([sys.executable,
'-c',
'{imports}; from ase.parallel import world; assert world.comm is None'
.format(imports=imports)],
check=True)
|