Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info property to executor #283

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pympipool/shared/executorbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ def __init__(self):
self._future_queue = queue.Queue()
self._process = None

@property
def info(self):
if self._process is not None and isinstance(self._process, list):
meta_data_dict = self._process[0]._kwargs.copy()
if "future_queue" in meta_data_dict.keys():
del meta_data_dict["future_queue"]
meta_data_dict["max_workers"] = len(self._process)
return meta_data_dict
elif self._process is not None:
meta_data_dict = self._process._kwargs.copy()
if "future_queue" in meta_data_dict.keys():
del meta_data_dict["future_queue"]
return meta_data_dict
else:
return None

@property
def future_queue(self):
return self._future_queue
Expand Down
24 changes: 23 additions & 1 deletion tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from time import sleep
from concurrent.futures import CancelledError
from pympipool.mpi.executor import PyMPIExecutor, MpiExecInterface
from pympipool.shared.executorbase import cloudpickle_register, execute_parallel_tasks
from pympipool.shared.executorbase import cloudpickle_register, execute_parallel_tasks, ExecutorBase
from pympipool.shell import ShellExecutor
from concurrent.futures import Future


Expand Down Expand Up @@ -78,6 +79,27 @@ def test_executor_exception_future(self):
fs = p.submit(raise_error)
fs.result()

def test_meta(self):
meta_data_exe_dict = {
'cores': 2,
'interface_class': "<class 'pympipool.shared.interface.MpiExecInterface'>",
'hostname_localhost': True,
'init_function': None,
'cwd': None,
'oversubscribe': False,
'max_workers': 1
}
with PyMPIExecutor(max_workers=1, cores_per_worker=2, hostname_localhost=True) as exe:
for k, v in meta_data_exe_dict.items():
if k != 'interface_class':
self.assertEqual(exe.info[k], v)
else:
self.assertEqual(str(exe.info[k]), v)
with ExecutorBase() as exe:
self.assertIsNone(exe.info)
with ShellExecutor(["sleep"]) as exe:
self.assertEqual(exe.info, {})

def test_pool_multi_core(self):
with PyMPIExecutor(max_workers=1, cores_per_worker=2, hostname_localhost=True) as p:
output = p.submit(mpi_funct, i=2)
Expand Down
Loading