Skip to content

Commit

Permalink
Merge pull request #207 from pyiron/universal_executor
Browse files Browse the repository at this point in the history
Universal executor
  • Loading branch information
jan-janssen authored Nov 8, 2023
2 parents 0a4b1a6 + e401b41 commit a81412d
Showing 1 changed file with 43 additions and 0 deletions.
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,
)

0 comments on commit a81412d

Please sign in to comment.