Skip to content

Commit 294965d

Browse files
Change Backend Names (#500)
* Change Backend Names * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update __init__.py * fix flux tests * fix flux submission test * fix input checks * fix notebooks * Add more tests --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c1b8b22 commit 294965d

File tree

9 files changed

+36
-28
lines changed

9 files changed

+36
-28
lines changed

executorlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __new__(
179179
resource_dict.update(
180180
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
181181
)
182-
if "pysqa_" in backend and not plot_dependency_graph:
182+
if "_submission" in backend and not plot_dependency_graph:
183183
from executorlib.cache.executor import create_file_executor
184184

185185
return create_file_executor(

executorlib/cache/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181

8282
def create_file_executor(
8383
max_workers: int = 1,
84-
backend: str = "pysqa_flux",
84+
backend: str = "flux_submission",
8585
max_cores: int = 1,
8686
cache_directory: Optional[str] = None,
8787
resource_dict: Optional[dict] = None,
@@ -113,6 +113,6 @@ def create_file_executor(
113113
cache_directory=cache_directory,
114114
resource_dict=resource_dict,
115115
pysqa_config_directory=pysqa_config_directory,
116-
backend=backend.split("pysqa_")[-1],
116+
backend=backend.split("_submission")[0],
117117
disable_dependencies=disable_dependencies,
118118
)

executorlib/interactive/executor.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ def create_executor(
198198
init_function (None): optional function to preset arguments for functions which are submitted later
199199
"""
200200
check_init_function(block_allocation=block_allocation, init_function=init_function)
201-
if flux_executor is not None and backend != "flux":
202-
backend = "flux"
201+
if flux_executor is not None and backend != "flux_allocation":
202+
backend = "flux_allocation"
203203
check_pmi(backend=backend, pmi=flux_executor_pmi_mode)
204204
cores_per_worker = resource_dict["cores"]
205205
resource_dict["cache_directory"] = cache_directory
206206
resource_dict["hostname_localhost"] = hostname_localhost
207-
if backend == "flux":
207+
if backend == "flux_allocation":
208208
check_oversubscribe(oversubscribe=resource_dict["openmpi_oversubscribe"])
209209
check_command_line_argument_lst(
210210
command_line_argument_lst=resource_dict["slurm_cmd_args"]
@@ -233,7 +233,7 @@ def create_executor(
233233
executor_kwargs=resource_dict,
234234
spawner=FluxPythonSpawner,
235235
)
236-
elif backend == "slurm":
236+
elif backend == "slurm_allocation":
237237
check_executor(executor=flux_executor)
238238
check_nested_flux_executor(nested_flux_executor=flux_executor_nesting)
239239
if block_allocation:
@@ -255,7 +255,7 @@ def create_executor(
255255
executor_kwargs=resource_dict,
256256
spawner=SrunSpawner,
257257
)
258-
else: # backend="local"
258+
elif backend == "local":
259259
check_executor(executor=flux_executor)
260260
check_nested_flux_executor(nested_flux_executor=flux_executor_nesting)
261261
check_threads_per_core(threads_per_core=resource_dict["threads_per_core"])
@@ -285,3 +285,7 @@ def create_executor(
285285
executor_kwargs=resource_dict,
286286
spawner=MpiExecSpawner,
287287
)
288+
else:
289+
raise ValueError(
290+
"The supported backends are slurm_allocation, slurm_submission, flux_allocation, flux_submission and local."
291+
)

executorlib/standalone/inputcheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ def check_pmi(backend: str, pmi: Optional[str]) -> None:
117117
"""
118118
Check if pmi is valid for the selected backend and raise a ValueError if it is not.
119119
"""
120-
if backend != "flux" and pmi is not None:
120+
if backend != "flux_allocation" and pmi is not None:
121121
raise ValueError("The pmi parameter is currently only implemented for flux.")
122-
elif backend == "flux" and pmi not in ["pmix", "pmi1", "pmi2", None]:
122+
elif backend == "flux_allocation" and pmi not in ["pmix", "pmi1", "pmi2", None]:
123123
raise ValueError(
124124
"The pmi parameter supports [pmix, pmi1, pmi2], but not: " + pmi
125125
)

notebooks/examples.ipynb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"source": [
7070
"from executorlib import Executor\n",
7171
"\n",
72-
"with Executor(max_cores=1, backend=\"flux\") as exe:\n",
72+
"with Executor(max_cores=1, backend=\"flux_allocation\") as exe:\n",
7373
" future = exe.submit(sum, [1, 1])\n",
7474
" print(future.result())"
7575
]
@@ -103,7 +103,7 @@
103103
" return sum(*args)\n",
104104
"\n",
105105
"\n",
106-
"with Executor(max_cores=2, backend=\"flux\") as exe:\n",
106+
"with Executor(max_cores=2, backend=\"flux_allocation\") as exe:\n",
107107
" fs_1 = exe.submit(calc, [2, 1])\n",
108108
" fs_2 = exe.submit(calc, [2, 2])\n",
109109
" fs_3 = exe.submit(calc, [2, 3])\n",
@@ -159,7 +159,7 @@
159159
" return sum(*args)\n",
160160
"\n",
161161
"\n",
162-
"with Executor(max_cores=2, backend=\"flux\") as exe:\n",
162+
"with Executor(max_cores=2, backend=\"flux_allocation\") as exe:\n",
163163
" print(list(exe.map(calc, [[2, 1], [2, 2], [2, 3], [2, 4]])))"
164164
]
165165
},
@@ -205,7 +205,7 @@
205205
" with Executor(\n",
206206
" # Resource definition on the executor level\n",
207207
" max_workers=2, # total number of cores available to the Executor\n",
208-
" backend=\"flux\", # optional in case the backend is not recognized\n",
208+
" backend=\"flux_allocation\", # optional in case the backend is not recognized\n",
209209
" # Optional resource definition\n",
210210
" resource_dict={\n",
211211
" \"cores\": 1,\n",
@@ -277,7 +277,7 @@
277277
" # Resource definition on the executor level\n",
278278
" max_cores=2, # total number of cores available to the Executor\n",
279279
" block_allocation=True, # reuse python processes\n",
280-
" backend=\"flux\",\n",
280+
" backend=\"flux_allocation\",\n",
281281
") as exe:\n",
282282
" future_obj = exe.submit(\n",
283283
" calc_function,\n",
@@ -332,7 +332,7 @@
332332
"with Executor(\n",
333333
" max_cores=1,\n",
334334
" init_function=init_function,\n",
335-
" backend=\"flux\",\n",
335+
" backend=\"flux_allocation\",\n",
336336
" block_allocation=True,\n",
337337
") as exe:\n",
338338
" fs = exe.submit(calc, 2, j=5)\n",
@@ -462,7 +462,7 @@
462462
"with Executor(\n",
463463
" max_cores=2,\n",
464464
" resource_dict={\"cores\": 2},\n",
465-
" backend=\"flux\",\n",
465+
" backend=\"flux_allocation\",\n",
466466
" flux_executor_pmi_mode=\"pmix\",\n",
467467
") as exe:\n",
468468
" fs = exe.submit(calc, 3)\n",
@@ -519,7 +519,7 @@
519519
"with Executor(\n",
520520
" max_workers=2, \n",
521521
" gpus_per_worker=1,\n",
522-
" backend=\"flux\",\n",
522+
" backend=\"flux_allocation\",\n",
523523
") as exe:\n",
524524
" fs_1 = exe.submit(get_available_gpus)\n",
525525
" fs_2 = exe.submit(get_available_gpus)\n",
@@ -627,7 +627,7 @@
627627
" return parameter_a + parameter_b\n",
628628
"\n",
629629
"\n",
630-
"with Executor(max_cores=2, backend=\"flux\") as exe:\n",
630+
"with Executor(max_cores=2, backend=\"flux_allocation\") as exe:\n",
631631
" future_1 = exe.submit(\n",
632632
" calc_function,\n",
633633
" 1,\n",
@@ -672,7 +672,7 @@
672672
"```\n",
673673
"from executorlib import Executor\n",
674674
"\n",
675-
"with Executor(max_cores=1, backend=\"slurm\") as exe:\n",
675+
"with Executor(max_cores=1, backend=\"slurm_allocation\") as exe:\n",
676676
" future = exe.submit(sum, [1,1])\n",
677677
" print(future.result())\n",
678678
"```"
@@ -683,7 +683,7 @@
683683
"id": "ae8dd860-f90f-47b4-b3e5-664f5c949350",
684684
"metadata": {},
685685
"source": [
686-
"The `backend=\"slurm\"` parameter is optional as `executorlib` automatically recognizes if [flux framework](https://flux-framework.org)\n",
686+
"The `backend=\"slurm_allocation\"` parameter is optional as `executorlib` automatically recognizes if [flux framework](https://flux-framework.org)\n",
687687
"or SLURM are available. \n",
688688
"\n",
689689
"In addition, the SLURM backend introduces the `command_line_argument_lst=[]` parameter, which allows the user to provide\n",

tests/test_cache_executor_pysqa_flux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def mpi_funct(i):
3333
class TestCacheExecutorPysqa(unittest.TestCase):
3434
def test_executor(self):
3535
with Executor(
36-
backend="pysqa_flux",
36+
backend="flux_submission",
3737
resource_dict={"cores": 2, "cwd": "cache"},
3838
block_allocation=False,
3939
cache_directory="cache",

tests/test_dependencies_executor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def test_executor_dependency_plot(self):
7373
self.assertEqual(len(nodes), 5)
7474
self.assertEqual(len(edges), 4)
7575

76+
def test_create_executor_error(self):
77+
with self.assertRaises(ValueError):
78+
create_executor(backend="toast", resource_dict={"cores": 1})
79+
7680
def test_dependency_steps(self):
7781
cloudpickle_register(ind=1)
7882
fs1 = Future()

tests/test_executor_backend_flux.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_flux_executor_serial(self):
4747
with Executor(
4848
max_cores=2,
4949
flux_executor=self.executor,
50-
backend="flux",
50+
backend="flux_allocation",
5151
block_allocation=True,
5252
) as exe:
5353
fs_1 = exe.submit(calc, 1)
@@ -62,7 +62,7 @@ def test_flux_executor_threads(self):
6262
max_cores=1,
6363
resource_dict={"threads_per_core": 2},
6464
flux_executor=self.executor,
65-
backend="flux",
65+
backend="flux_allocation",
6666
block_allocation=True,
6767
) as exe:
6868
fs_1 = exe.submit(calc, 1)
@@ -77,7 +77,7 @@ def test_flux_executor_parallel(self):
7777
max_cores=2,
7878
resource_dict={"cores": 2},
7979
flux_executor=self.executor,
80-
backend="flux",
80+
backend="flux_allocation",
8181
block_allocation=True,
8282
flux_executor_pmi_mode=pmi,
8383
) as exe:
@@ -90,7 +90,7 @@ def test_single_task(self):
9090
max_cores=2,
9191
resource_dict={"cores": 2},
9292
flux_executor=self.executor,
93-
backend="flux",
93+
backend="flux_allocation",
9494
block_allocation=True,
9595
flux_executor_pmi_mode=pmi,
9696
) as p:
@@ -106,7 +106,7 @@ def test_internal_memory(self):
106106
resource_dict={"cores": 1},
107107
init_function=set_global,
108108
flux_executor=self.executor,
109-
backend="flux",
109+
backend="flux_allocation",
110110
block_allocation=True,
111111
) as p:
112112
f = p.submit(get_global)

tests/test_shared_input_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_check_pmi(self):
6666
with self.assertRaises(ValueError):
6767
check_pmi(backend="test", pmi="test")
6868
with self.assertRaises(ValueError):
69-
check_pmi(backend="flux", pmi="test")
69+
check_pmi(backend="flux_allocation", pmi="test")
7070

7171
def test_check_nested_flux_executor(self):
7272
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)