A simple and lightweight package for parallel computing
Project description
Ampeg
Ampeg is a simple and lightweight package for parallel computation. It provides
simple functions for scheduling and execution of a set of dependent or
independent computational tasks over multiple processes using the
multiprocessing
package.
Requirements
Python 2.7 or later
Python 3.4 or later
Installation
pip install ampeg
Usage
Ampeg exposes a scheduling function earliest_finish_time
, an execution
function execute_task_lists
and a Dependency
class. The former takes a
directed acyclic graph (DAG) and a number of processes and produces a set of
task lists for each process and a corresponding set of task IDs for translating
the execution result. These two form the input to execute_task_lists
, which
returns a dict with the result of each task in the original graph.
The DAG is represented by a python dict of vertices where each key is the ID of
a task and each value is a triple of (function, args or kwargs, computation
cost). Edges are implicitly defined by instances of the Dependency
class in
the args or kwargs.
A simple usage example computing (3^2 + 4^2) - (3^2 * 10/2):
>>> import ampeg as ag
>>> n_processes = 3
>>> my_graph = {0: (lambda x: x**2, 3, 10.8),
1: (lambda x: x**2, 4, 10.8),
2: (lambda x: x/2, 10, 11),
3: (lambda x, y: x + y, (ag.Dependency(0, None, 1),
ag.Dependency(1, None, 1), 10.7),
4: (lambda x, y: x*y, (ag.Dependency(0, None, 1),
ag.Dependency(2, None, 1)), 10.8),
5: (lambda x, y: x - y, (ag.Dependency(3, None, 1),
ag.Dependency(4, None, 1)), 10.9)}
>>> task_lists, task_ids = ag.earliest_finish_time(my_graph, n_processes)
>>> ag.execute_task_lists(task_lists, task_ids)
{0: 9, 1: 16, 2: 5, 3: 25, 4: 45, 5: -20}
The Dependency class
A dependency is a triple of (task ID or index, key (if any) and communication
cost). The key may be a single key, index or slice, or it may be an iterable of
such values to be applied in sequence. For example, the key ('values', 2)
extracts the value 5 from the dict {'values': [1, 3, 5]}
. Dependency
instances are created by ampeg.Dependency(task, key, cost)
where cost is
optional and defaults to 0.
Exceptions
Ampeg catches exceptions raised by individual tasks, returning them as results
encapsulated in the Err
class. When an Err
instance is found among the
dependencies for a task, the result for this task will be an Err
instance
encapsulating a DependencyError
.
Windows
Note that under Windows, the functions and their arguments must all be picklable.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ampeg-0.2.0.tar.gz
.
File metadata
- Download URL: ampeg-0.2.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d565f66e48a35379366d57844c38f2a53646ed03ca978cf5ca5399a85b99df19 |
|
MD5 | 3a83b401d60a55e060bc76949a1fc746 |
|
BLAKE2b-256 | 54b9a5a642a6baa76620f6bc447894ea438a2ff6851bede7169880c65184b7fc |
File details
Details for the file ampeg-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: ampeg-0.2.0-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b905b236f13b0e3fbe6bffca27c14f1cb318b3726fcd1caace3a9f138bce5d6b |
|
MD5 | 3a30fc8731a25be22399df0d22e4f2c1 |
|
BLAKE2b-256 | da8a50686905d8766793528f8ab392a7e3985c2b2aae96ca19269ae4d1020f95 |