2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
2 changes: 2 additions & 0 deletions executorlib/api.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
functionality is considered internal and might change during minor releases.
"""

from executorlib.executor.single import TestClusterExecutor
from executorlib.standalone.command import get_command_path
from executorlib.standalone.interactive.communication import (
SocketInterface,
Expand All@@ -19,6 +20,7 @@
from executorlib.standalone.serialize import cloudpickle_register

__all__: list[str] = [
"TestClusterExecutor",
"cancel_items_in_queue",
"cloudpickle_register",
"get_command_path",
Expand Down
168 changes: 168 additions & 0 deletions executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,174 @@ def __init__(
)


class TestClusterExecutor(BaseExecutor):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use the
SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the number of
cores which can be used in parallel - just like the max_cores parameter. Using max_cores is
recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same resource
requirements, executorlib supports block allocation. In this case all resources have
to be defined on the executor, rather than during the submission of the individual
function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
```
>>> import numpy as np
>>> from executorlib.api import TestClusterExecutor
>>>
>>> def calc(i, j, k):
>>> from mpi4py import MPI
>>> size = MPI.COMM_WORLD.Get_size()
>>> rank = MPI.COMM_WORLD.Get_rank()
>>> return np.array([i, j, k]), size, rank
>>>
>>> def init_k():
>>> return {"k": 3}
>>>
>>> with TestClusterExecutor(max_workers=2, init_function=init_k) as p:
>>> fs = p.submit(calc, 2, j=4)
>>> print(fs.result())
[(array([2, 4, 3]), 2, 0), (array([2, 4, 3]), 2, 1)]
```
"""

def __init__(
self,
max_workers: Optional[int] = None,
cache_directory: Optional[str] = None,
max_cores: Optional[int] = None,
resource_dict: Optional[dict] = None,
hostname_localhost: Optional[bool] = None,
block_allocation: bool = False,
init_function: Optional[Callable] = None,
disable_dependencies: bool = False,
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
The executorlib.api.TestClusterExecutor is designed to test the file based communication used in the
SlurmClusterExecutor and the FluxClusterExecutor locally. It is not recommended for production use, rather use
the SingleNodeExecutor.

Args:
max_workers (int): for backwards compatibility with the standard library, max_workers also defines the
number of cores which can be used in parallel - just like the max_cores parameter. Using
max_cores is recommended, as computers have a limited number of compute cores.
cache_directory (str, optional): The directory to store cache files. Defaults to "executorlib_cache".
max_cores (int): defines the number cores which can be used in parallel
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
- cores (int): number of MPI cores to be used for each function call
- threads_per_core (int): number of OpenMP threads to be used for each function call
- gpus_per_core (int): number of GPUs per worker - defaults to 0
- cwd (str/None): current working directory where the parallel python task is executed
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
in principle any computer should be able to resolve that their own hostname
points to the same address as localhost. Still MacOS >= 12 seems to disable
this look up for security reasons. So on MacOS it is required to set this
option to true
block_allocation (boolean): To accelerate the submission of a series of python functions with the same
resource requirements, executorlib supports block allocation. In this case all
resources have to be defined on the executor, rather than during the submission
of the individual function.
init_function (None): optional function to preset arguments for functions which are submitted later
disable_dependencies (boolean): Disable resolving future objects during the submission.
refresh_rate (float): Set the refresh rate in seconds, how frequently the input queue is checked.
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
default_resource_dict: dict = {
"cores": 1,
"threads_per_core": 1,
"gpus_per_core": 0,
"cwd": None,
"openmpi_oversubscribe": False,
}
if resource_dict is None:
resource_dict = {}
resource_dict.update(
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
)
if not plot_dependency_graph:
from executorlib.task_scheduler.file.subprocess_spawner import (
execute_in_subprocess,
)
from executorlib.task_scheduler.file.task_scheduler import (
create_file_executor,
)

super().__init__(
executor=create_file_executor(
max_workers=max_workers,
backend=None,
max_cores=max_cores,
cache_directory=cache_directory,
resource_dict=resource_dict,
flux_executor=None,
flux_executor_pmi_mode=None,
flux_executor_nesting=False,
flux_log_files=False,
pysqa_config_directory=None,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
disable_dependencies=disable_dependencies,
execute_function=execute_in_subprocess,
)
)
else:
super().__init__(
executor=DependencyTaskScheduler(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
log_obj_size=log_obj_size,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)


def create_single_node_executor(
max_workers: Optional[int] = None,
max_cores: Optional[int] = None,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_testclusterexecutor.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
import os
import shutil
import unittest

from executorlib import get_cache_data
from executorlib.api import TestClusterExecutor
from executorlib.standalone.plot import generate_nodes_and_edges
from executorlib.standalone.serialize import cloudpickle_register

try:
import h5py

skip_h5py_test = False
except ImportError:
skip_h5py_test = True


def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2


def foo(x):
return x + 1


@unittest.skipIf(
skip_h5py_test, "h5py is not installed, so the h5io tests are skipped."
)
class TestTestClusterExecutor(unittest.TestCase):
def test_cache_dir(self):
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)
with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe:
cloudpickle_register(ind=1)
future = exe.submit(
foo,
1,
resource_dict={
"cache_directory": "rather_this_dir",
"cache_key": "foo",
},
)
self.assertEqual(future.result(), 2)
self.assertFalse(os.path.exists("not_this_dir"))
cache_lst = get_cache_data(cache_directory="not_this_dir")
self.assertEqual(len(cache_lst), 0)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_empty(self):
with TestClusterExecutor(cache_directory="rather_this_dir") as exe:
cloudpickle_register(ind=1)
future = exe.submit(foo,1)
self.assertEqual(future.result(), 2)
self.assertTrue(os.path.exists("rather_this_dir"))
cache_lst = get_cache_data(cache_directory="rather_this_dir")
self.assertEqual(len(cache_lst), 1)

def test_executor_dependency_plot(self):
with TestClusterExecutor(
plot_dependency_graph=True,
) as exe:
cloudpickle_register(ind=1)
future_1 = exe.submit(add_function, 1, parameter_2=2)
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
self.assertTrue(future_1.done())
self.assertTrue(future_2.done())
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
)
self.assertEqual(len(nodes), 5)
self.assertEqual(len(edges), 4)

def tearDown(self):
shutil.rmtree("rather_this_dir", ignore_errors=True)