-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mpi4py as optional dependency #343
Changes from 2 commits
e99a01b
4749fa6
f92bff2
50e6a3e
2675ced
430f4f6
e760db2
4e9478a
7e0f84d
db99498
7792f3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python | ||
- numpy | ||
- cloudpickle =3.0.0 | ||
- tqdm =4.66.4 | ||
- pyzmq =26.0.3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This workflow is used to run the unittest of pyiron | ||
|
||
name: Unittests-minimal | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: conda-incubator/[email protected] | ||
with: | ||
python-version: "3.12" | ||
mamba-version: "*" | ||
channels: conda-forge | ||
miniforge-variant: Mambaforge | ||
channel-priority: strict | ||
auto-update-conda: true | ||
environment-file: .ci_support/environment-mini.yml | ||
- name: Test | ||
shell: bash -l {0} | ||
timeout-minutes: 5 | ||
run: | | ||
pip install versioneer[toml]==0.29 | ||
pip install . --no-deps --no-build-isolation | ||
cd tests | ||
python -m unittest discover . |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,13 @@ | |||||||||||||||||
from pympipool import Executor | ||||||||||||||||||
from pympipool.shared.executorbase import cloudpickle_register | ||||||||||||||||||
|
||||||||||||||||||
try: | ||||||||||||||||||
import mpi4py | ||||||||||||||||||
|
||||||||||||||||||
mpi4py_installed = True | ||||||||||||||||||
except ImportError: | ||||||||||||||||||
mpi4py_installed = False | ||||||||||||||||||
|
||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using - try:
- import mpi4py
- mpi4py_installed = True
- except ImportError:
- mpi4py_installed = False
+ import importlib.util
+ mpi4py_installed = importlib.util.find_spec('mpi4py') is not None Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
def calc(i): | ||||||||||||||||||
return i | ||||||||||||||||||
|
@@ -19,7 +26,7 @@ def mpi_funct(i): | |||||||||||||||||
class TestExecutorBackend(unittest.TestCase): | ||||||||||||||||||
def test_meta_executor_serial(self): | ||||||||||||||||||
with Executor( | ||||||||||||||||||
max_cores=2, hostname_localhost=True, backend="mpi", block_allocation=True | ||||||||||||||||||
max_cores=2, hostname_localhost=True, backend="local", block_allocation=True | ||||||||||||||||||
) as exe: | ||||||||||||||||||
cloudpickle_register(ind=1) | ||||||||||||||||||
fs_1 = exe.submit(calc, 1) | ||||||||||||||||||
|
@@ -31,7 +38,7 @@ def test_meta_executor_serial(self): | |||||||||||||||||
|
||||||||||||||||||
def test_meta_executor_single(self): | ||||||||||||||||||
with Executor( | ||||||||||||||||||
max_cores=1, hostname_localhost=True, backend="mpi", block_allocation=True | ||||||||||||||||||
max_cores=1, hostname_localhost=True, backend="local", block_allocation=True | ||||||||||||||||||
) as exe: | ||||||||||||||||||
cloudpickle_register(ind=1) | ||||||||||||||||||
fs_1 = exe.submit(calc, 1) | ||||||||||||||||||
|
@@ -41,12 +48,15 @@ def test_meta_executor_single(self): | |||||||||||||||||
self.assertTrue(fs_1.done()) | ||||||||||||||||||
self.assertTrue(fs_2.done()) | ||||||||||||||||||
|
||||||||||||||||||
@unittest.skipIf( | ||||||||||||||||||
mpi4py_installed, "mpi4py is not installed, so the mpi4py tests are skipped." | ||||||||||||||||||
) | ||||||||||||||||||
def test_meta_executor_parallel(self): | ||||||||||||||||||
with Executor( | ||||||||||||||||||
max_workers=2, | ||||||||||||||||||
cores_per_worker=2, | ||||||||||||||||||
hostname_localhost=True, | ||||||||||||||||||
backend="mpi", | ||||||||||||||||||
backend="local", | ||||||||||||||||||
block_allocation=True, | ||||||||||||||||||
) as exe: | ||||||||||||||||||
cloudpickle_register(ind=1) | ||||||||||||||||||
|
@@ -61,13 +71,13 @@ def test_errors(self): | |||||||||||||||||
cores_per_worker=1, | ||||||||||||||||||
threads_per_core=2, | ||||||||||||||||||
hostname_localhost=True, | ||||||||||||||||||
backend="mpi", | ||||||||||||||||||
backend="local", | ||||||||||||||||||
) | ||||||||||||||||||
with self.assertRaises(TypeError): | ||||||||||||||||||
Executor( | ||||||||||||||||||
max_cores=1, | ||||||||||||||||||
cores_per_worker=1, | ||||||||||||||||||
gpus_per_worker=1, | ||||||||||||||||||
hostname_localhost=True, | ||||||||||||||||||
backend="mpi", | ||||||||||||||||||
backend="local", | ||||||||||||||||||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,6 +13,13 @@ | |||||||||||||||||||
ExecutorBase, | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
try: | ||||||||||||||||||||
import mpi4py | ||||||||||||||||||||
|
||||||||||||||||||||
mpi4py_installed = True | ||||||||||||||||||||
except ImportError: | ||||||||||||||||||||
mpi4py_installed = False | ||||||||||||||||||||
|
||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using - try:
- import mpi4py
- mpi4py_installed = True
- except ImportError:
- mpi4py_installed = False
+ from importlib.util import find_spec
+ mpi4py_installed = find_spec("mpi4py") is not None Committable suggestion
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
def calc(i): | ||||||||||||||||||||
return i | ||||||||||||||||||||
|
@@ -127,6 +134,9 @@ def test_pympiexecutor_errors(self): | |||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
@unittest.skipIf( | ||||||||||||||||||||
mpi4py_installed, "mpi4py is not installed, so the mpi4py tests are skipped." | ||||||||||||||||||||
) | ||||||||||||||||||||
class TestPyMpiExecutorMPI(unittest.TestCase): | ||||||||||||||||||||
def test_pympiexecutor_one_worker_with_mpi(self): | ||||||||||||||||||||
with PyMPIExecutor( | ||||||||||||||||||||
|
@@ -164,6 +174,9 @@ def test_pympiexecutor_one_worker_with_mpi_echo(self): | |||||||||||||||||||
self.assertEqual(output, [2, 2]) | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
@unittest.skipIf( | ||||||||||||||||||||
mpi4py_installed, "mpi4py is not installed, so the mpi4py tests are skipped." | ||||||||||||||||||||
) | ||||||||||||||||||||
class TestPyMpiStepExecutorMPI(unittest.TestCase): | ||||||||||||||||||||
def test_pympiexecutor_one_worker_with_mpi(self): | ||||||||||||||||||||
with PyMPIStepExecutor( | ||||||||||||||||||||
|
@@ -339,6 +352,9 @@ def test_meta_step(self): | |||||||||||||||||||
else: | ||||||||||||||||||||
self.assertEqual(str(exe.info[k]), v) | ||||||||||||||||||||
|
||||||||||||||||||||
@unittest.skipIf( | ||||||||||||||||||||
mpi4py_installed, "mpi4py is not installed, so the mpi4py tests are skipped." | ||||||||||||||||||||
) | ||||||||||||||||||||
def test_pool_multi_core(self): | ||||||||||||||||||||
with PyMPIExecutor( | ||||||||||||||||||||
max_workers=1, cores_per_worker=2, hostname_localhost=True | ||||||||||||||||||||
|
@@ -352,6 +368,9 @@ def test_pool_multi_core(self): | |||||||||||||||||||
self.assertEqual(len(p), 0) | ||||||||||||||||||||
self.assertEqual(output.result(), [(2, 2, 0), (2, 2, 1)]) | ||||||||||||||||||||
|
||||||||||||||||||||
@unittest.skipIf( | ||||||||||||||||||||
mpi4py_installed, "mpi4py is not installed, so the mpi4py tests are skipped." | ||||||||||||||||||||
) | ||||||||||||||||||||
def test_pool_multi_core_map(self): | ||||||||||||||||||||
with PyMPIExecutor( | ||||||||||||||||||||
max_workers=1, cores_per_worker=2, hostname_localhost=True | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using
importlib.util.find_spec
instead of a try-except block to check formpi4py
availability. This approach is more explicit and avoids importing the module unnecessarily.Committable suggestion