diff --git a/pyproject.toml b/pyproject.toml index 0ab34a1..abb0a1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,9 +73,11 @@ exec_sequential = "fluidimage.executors.exec_sequential" exec_async = "fluidimage.executors.exec_async" exec_async_sequential = "fluidimage.executors.exec_async_sequential" exec_async_seq_for_multi = "fluidimage.executors.exec_async_seq_for_multi" +exec_seq_for_multi = "fluidimage.executors.exec_seq_for_multi" multi_exec_async = "fluidimage.executors.multi_exec_async" multi_exec_sync = "fluidimage.executors.multi_exec_sync" multi_exec_subproc = "fluidimage.executors.multi_exec_subproc" +multi_exec_subproc_sync = "fluidimage.executors.multi_exec_subproc_sync" exec_async_multi = "fluidimage.executors.exec_async_multiproc" exec_async_servers = "fluidimage.executors.exec_async_servers" exec_async_servers_threading = "fluidimage.executors.exec_async_servers_threading" diff --git a/src/fluidimage/executors/__init__.py b/src/fluidimage/executors/__init__.py index 6ad6757..be61320 100644 --- a/src/fluidimage/executors/__init__.py +++ b/src/fluidimage/executors/__init__.py @@ -19,8 +19,11 @@ exec_async exec_async_sequential multi_exec_async + multi_exec_sync multi_exec_subproc + multi_exec_subproc_sync exec_async_seq_for_multi + exec_seq_for_multi exec_async_multiproc exec_async_servers servers @@ -58,7 +61,7 @@ def afterfork(): # because the OS does not support forks (or not fully) and # multiprocessing works differently than on Linux # see https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods -supported_multi_executors = ["multi_exec_subproc"] +supported_multi_executors = ["multi_exec_subproc", "multi_exec_subproc_sync"] if sys.platform == "linux": supported_multi_executors.insert(0, "multi_exec_sync") supported_multi_executors.insert(0, "multi_exec_async") diff --git a/src/fluidimage/executors/exec_seq_for_multi.py b/src/fluidimage/executors/exec_seq_for_multi.py index e5c00ed..16f777b 100644 --- a/src/fluidimage/executors/exec_seq_for_multi.py +++ b/src/fluidimage/executors/exec_seq_for_multi.py @@ -1,6 +1,17 @@ +"""Sequential executor for multi executor + +.. autoclass:: ExecutorSeqForMulti + :members: + :private-members: + +""" + from fluidimage.executors.exec_async_seq_for_multi import ExecutorAsyncSeqForMulti from fluidimage.executors.exec_sequential import ExecutorSequential class ExecutorSeqForMulti(ExecutorSequential, ExecutorAsyncSeqForMulti): """Sequential executor modified for multi executors""" + + +Executor = ExecutorSeqForMulti diff --git a/src/fluidimage/executors/meson.build b/src/fluidimage/executors/meson.build index fdb6371..cbe267f 100644 --- a/src/fluidimage/executors/meson.build +++ b/src/fluidimage/executors/meson.build @@ -13,6 +13,7 @@ python_sources = [ 'multi_exec_async.py', 'multi_exec_sync.py', 'multi_exec_subproc.py', + 'multi_exec_subproc_sync.py', 'servers.py', ] diff --git a/src/fluidimage/executors/multi_exec_subproc.py b/src/fluidimage/executors/multi_exec_subproc.py index d8836f1..75ad013 100644 --- a/src/fluidimage/executors/multi_exec_subproc.py +++ b/src/fluidimage/executors/multi_exec_subproc.py @@ -22,6 +22,7 @@ class MultiExecutorSubproc(MultiExecutorBase): """Multi executor based on subprocesses and splitters""" splitter: Splitter + executor_for_multi = "exec_async_seq_for_multi" def _init_num_expected_results(self): @@ -29,7 +30,7 @@ def _init_num_expected_results(self): splitter_cls = self.topology.Splitter except AttributeError as error: raise ValueError( - "MultiExecutorSubproc can only execute " + f"{type(self).__name__} can only execute " "topologies with a Splitter." ) from error @@ -39,12 +40,12 @@ def _init_num_expected_results(self): params._set_child( "compute_kwargs", attribs={ - "executor": "exec_async_seq_for_multi", + "executor": self.executor_for_multi, "nb_max_workers": 1, }, ) except ValueError: - params.compute_kwargs.executor = "exec_async_seq_for_multi" + params.compute_kwargs.executor = self.executor_for_multi params.compute_kwargs.nb_max_workers = 1 try: diff --git a/src/fluidimage/executors/multi_exec_subproc_sync.py b/src/fluidimage/executors/multi_exec_subproc_sync.py new file mode 100644 index 0000000..041fd6a --- /dev/null +++ b/src/fluidimage/executors/multi_exec_subproc_sync.py @@ -0,0 +1,16 @@ +"""Multi executor based on subprocesses using exec_seq_for_multi + +.. autoclass:: MultiExecutorSubprocSync + :members: + :private-members: + +""" + +from fluidimage.executors.multi_exec_subproc import MultiExecutorSubproc + + +class MultiExecutorSubprocSync(MultiExecutorSubproc): + executor_for_multi = "exec_seq_for_multi" + + +Executor = MultiExecutorSubprocSync diff --git a/src/fluidimage/executors/multi_exec_sync.py b/src/fluidimage/executors/multi_exec_sync.py index 37f32ba..4c40282 100644 --- a/src/fluidimage/executors/multi_exec_sync.py +++ b/src/fluidimage/executors/multi_exec_sync.py @@ -1,3 +1,13 @@ +""" +Multi executors sync +===================== + +.. autoclass:: MultiExecutorSync + :members: + :private-members: + +""" + from fluidimage.executors.exec_seq_for_multi import ExecutorSeqForMulti from fluidimage.executors.multi_exec_async import MultiExecutorAsync diff --git a/src/fluidimage/topologies/test_example.py b/src/fluidimage/topologies/test_example.py index c51114e..f1b0a00 100644 --- a/src/fluidimage/topologies/test_example.py +++ b/src/fluidimage/topologies/test_example.py @@ -16,8 +16,10 @@ # tmp: TopologyExample doesn't have a Splitter executors.remove("multi_exec_subproc") +executors.remove("multi_exec_subproc_sync") +@pytest.mark.usefixtures("close_plt_figs") @pytest.mark.parametrize("executor", executors) def test_topo_example(tmp_path_karman, executor):