-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from pyiron/universal_executor
Universal executor
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |