Skip to content

Commit

Permalink
Raise error when resource_dict is used in function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Apr 22, 2024
1 parent 89bdac1 commit 780005c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pympipool/shared/executorbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def submit(self, fn: callable, *args, resource_dict: dict = {}, **kwargs):
raise ValueError(
"When block_allocation is enabled, the resource requirements have to be defined on the executor level."
)
if "resource_dict" in inspect.signature(fn).parameters.keys():
raise ValueError("The parameter resource_dict is used internally in pympipool, so it cannot be used as parameter in the submitted functions.")
f = Future()
self._future_queue.put({"fn": fn, "args": args, "kwargs": kwargs, "future": f})
return f
Expand Down Expand Up @@ -171,6 +173,8 @@ def submit(self, fn: callable, *args, resource_dict: dict = {}, **kwargs):
Returns:
A Future representing the given call.
"""
if "resource_dict" in inspect.signature(fn).parameters.keys():
raise ValueError("The parameter resource_dict is used internally in pympipool, so it cannot be used as parameter in the submitted functions.")
f = Future()
self._future_queue.put(
{
Expand Down
14 changes: 14 additions & 0 deletions tests/test_executor_backend_mpi_noblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def mpi_funct(i):
return i, size, rank


def resource_dict(resource_dict):
return resource_dict


class TestExecutorBackend(unittest.TestCase):
def test_meta_executor_serial(self):
with Executor(
Expand Down Expand Up @@ -58,3 +62,13 @@ def test_errors(self):
hostname_localhost=True,
backend="mpi",
)
with self.assertRaises(ValueError):
with Executor(
max_cores=1, hostname_localhost=True, backend="mpi", block_allocation=False
) as exe:
exe.submit(resource_dict, resource_dict={})
with self.assertRaises(ValueError):
with Executor(
max_cores=1, hostname_localhost=True, backend="mpi", block_allocation=True
) as exe:
exe.submit(resource_dict, resource_dict={})

0 comments on commit 780005c

Please sign in to comment.