Skip to content
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

Universal executor #207

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pympipool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
import os
from ._version import get_versions
from pympipool.mpi.executor import PyMPIExecutor

try: # The PyFluxExecutor requires flux-core to be installed.
from pympipool.flux.executor import PyFluxExecutor

flux_installed = "FLUX_URI" in os.environ
except ImportError:
flux_installed = False
pass

try: # The PySlurmExecutor requires the srun command to be available.
from pympipool.slurm.executor import PySlurmExecutor

slurm_installed = True
except ImportError:
slurm_installed = False
pass


__version__ = get_versions()["version"]
del get_versions


class Executor:
def __new__(
cls,
max_workers=1,
cores_per_worker=1,
init_function=None,
cwd=None,
sleep_interval=0.1,
):
if flux_installed:
return PyFluxExecutor(
max_workers=max_workers,
cores_per_worker=cores_per_worker,
init_function=init_function,
cwd=cwd,
sleep_interval=sleep_interval,
)
elif slurm_installed:
return PySlurmExecutor(
max_workers=max_workers,
cores_per_worker=cores_per_worker,
init_function=init_function,
cwd=cwd,
sleep_interval=sleep_interval,
)
else:
return PyMPIExecutor(
max_workers=max_workers,
cores_per_worker=cores_per_worker,
init_function=init_function,
cwd=cwd,
sleep_interval=sleep_interval,
)
Loading