Skip to content

Commit 093d1fd

Browse files
Provide additional functions for import (#639)
* Provide additional functions for import * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add cloudpickle_register to API * add socket functions * Separate user interface and developer interface * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add documentation * add links in readme * add explanation --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 83691dd commit 093d1fd

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@ as hierarchical job scheduler within the allocations.
158158
* [Modules](https://executorlib.readthedocs.io/en/latest/4-developer.html#modules)
159159
* [Interface Class Hierarchy](https://executorlib.readthedocs.io/en/latest/4-developer.html#interface-class-hierarchy)
160160
* [Communication](https://executorlib.readthedocs.io/en/latest/4-developer.html#communication)
161+
* [External Libraries](https://executorlib.readthedocs.io/en/latest/4-developer.html#external-libraries)
161162
* [External Executables](https://executorlib.readthedocs.io/en/latest/4-developer.html#external-executables)
162163
* [Interface](https://executorlib.readthedocs.io/en/latest/api.html)

executorlib/standalone/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""
22
Submodules in the executorlib.standalone module do not depend on other modules of the executorlib package. This strict
3-
separation simplifies the development, testing and debugging.
3+
separation simplifies the development, testing and debugging. The functionality in executorlib.standalone is designed
4+
to be used independently in other libraries.
45
"""
56

7+
from executorlib.standalone.command import get_command_path
68
from executorlib.standalone.interactive.communication import (
79
SocketInterface,
810
interface_bootup,
@@ -11,14 +13,20 @@
1113
interface_send,
1214
interface_shutdown,
1315
)
14-
from executorlib.standalone.interactive.spawner import MpiExecSpawner
16+
from executorlib.standalone.interactive.spawner import MpiExecSpawner, SubprocessSpawner
17+
from executorlib.standalone.queue import cancel_items_in_queue
18+
from executorlib.standalone.serialize import cloudpickle_register
1519

16-
__all__ = [
17-
"SocketInterface",
20+
__all__: list[str] = [
21+
"cancel_items_in_queue",
22+
"cloudpickle_register",
23+
"get_command_path",
1824
"interface_bootup",
1925
"interface_connect",
26+
"interface_receive",
2027
"interface_send",
2128
"interface_shutdown",
22-
"interface_receive",
2329
"MpiExecSpawner",
30+
"SocketInterface",
31+
"SubprocessSpawner",
2432
]

notebooks/4-developer.ipynb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,37 @@
109109
{
110110
"id": "7bc073aa-6036-48e7-9696-37af050d438a",
111111
"cell_type": "markdown",
112-
"source": "## Communication\nThe key functionality of the `executorlib` package is the up-scaling of python functions with thread based parallelism, MPI based parallelism or by assigning GPUs to individual python functions. In the background this is realized using a combination of the [zero message queue](https://zeromq.org) and [cloudpickle](https://github.com/cloudpipe/cloudpickle) \nto communicate binary python objects. The `executorlib.standalone.interactive.communication.SocketInterface` is an abstraction of this \ninterface, which is used in the other classes inside `executorlib` and might also be helpful for other projects. It comes with a series of utility functions:\n\n* `executorlib.standalone.interactive.communication.interface_bootup()`: To initialize the interface\n* `executorlib.standalone.interactive.communication.interface_connect()`: To connect the interface to another instance\n* `executorlib.standalone.interactive.communication.interface_send()`: To send messages via this interface \n* `executorlib.standalone.interactive.communication.interface_receive()`: To receive messages via this interface \n* `executorlib.standalone.interactive.communication.interface_shutdown()`: To shutdown the interface\n\nWhile `executorlib` was initially designed for up-scaling python functions for HPC, the same functionality can be \nleveraged to up-scale any executable independent of the programming language it is developed in.",
112+
"source": [
113+
"## Communication\n",
114+
"The key functionality of the executorlib package is the up-scaling of python functions with thread based parallelism, MPI based parallelism or by assigning GPUs to individual python functions. In the background this is realized using a combination of the [zero message queue](https://zeromq.org) and [cloudpickle](https://github.com/cloudpipe/cloudpickle)\n",
115+
"to communicate binary python objects. The `executorlib.standalone.interactive.communication.SocketInterface` is an abstraction of this \n",
116+
"interface, which is used in the other classes inside `executorlib` and might also be helpful for other projects. It comes with a series of utility functions:\n",
117+
"\n",
118+
"* `executorlib.standalone.interactive.communication.interface_bootup()`: To initialize the interface\n",
119+
"* `executorlib.standalone.interactive.communication.interface_connect()`: To connect the interface to another instance\n",
120+
"* `executorlib.standalone.interactive.communication.interface_send()`: To send messages via this interface \n",
121+
"* `executorlib.standalone.interactive.communication.interface_receive()`: To receive messages via this interface \n",
122+
"* `executorlib.standalone.interactive.communication.interface_shutdown()`: To shutdown the interface\n",
123+
"\n",
124+
"While executorlib was initially designed for up-scaling python functions for HPC, the same functionality can be\n",
125+
"leveraged to up-scale any executable independent of the programming language it is developed in.\n",
126+
"\n",
127+
"## External Libraries\n",
128+
"For external libraries executorlib provides a standardized interface for a subset of its internal functionality, which is designed to remain stable with minor version updates. Developers can import the following functionality from `executorlib.standalone`:\n",
129+
"* `cancel_items_in_queue()` - Cancel items which are still waiting in the Python standard library queue - `queue.queue`.\n",
130+
"* `cloudpickle_register()` - Cloudpickle can either pickle by value or pickle by reference. The functions which are communicated have to be pickled by value rather than by reference, so the module which calls the map function is pickled by value.\n",
131+
"* `get_command_path()` - Get path of the backend executable script `executorlib.backend`.\n",
132+
"* `interface_bootup()` - Start interface for ZMQ communication.\n",
133+
"* `interface_connect()` - Connect to an existing `SocketInterface` instance by providing the hostname and the port as strings.\n",
134+
"* `interface_receive()` - Receive instructions from a `SocketInterface` instance.\n",
135+
"* `interface_send()` - Send results to a `SocketInterface` instance.\n",
136+
"* `interface_shutdown()` - Close the connection to a `SocketInterface` instance.\n",
137+
"* `MpiExecSpawner` - Subprocess interface to start `mpi4py` parallel process.\n",
138+
"* `SocketInterface` - The `SocketInterface` is an abstraction layer on top of the zero message queue.\n",
139+
"* `SubprocessSpawner` - Subprocess interface to start serial Python process.\n",
140+
"\n",
141+
"It is not recommended to import components from other parts of executorlib in other libraries, only the interfaces in `executorlib` and `executorlib.standalone` are designed to be stable. All other classes and functions are considered for internal use only."
142+
],
113143
"metadata": {}
114144
},
115145
{

0 commit comments

Comments
 (0)