pckit
This is a simple package for parallel computing with Python.
Usage
Multiprocessing
If you want to use any solver from the package you have to wrap your functions into a model.
Here the example with square of 2 and 3 are evaluated by 2 workers.
MyModel is a subclass of the package Model. The method results is required.
import pckit
class MyModel(pckit.Model):
def results(self, x: int) -> int:
# Solve here problem f(x) = x^2
return x ** 2
if __name__ == '__main__':
model = MyModel()
worker = pckit.MultiprocessingWorker(model)
with pckit.get_solver(worker, workers_num=2) as solver:
# Create tasks to solve
tasks = [2, 3]
results = solver.solve(tasks)
print(results)
# >>> [4, 9]
Workers number can be controlled by workers_num argument.
MPI
You can easily run scripts on the cluster with mpi4py implementation on MPI (See mpi4py installation docs).
Simply change MultiprocessingWorker to MPIWorker in the previous example and start the script with MPI mpiexec -np <n> python -m mpi4py your_script.py, where <n> is a number of workers.
worker = pckit.MPIWorker(model)
By default, zero rank process is also used as a worker.
It can be controlled by zero_rank_usage argument of get_solver function.
Single thread
Single threaded execution is also available with Worker
worker = pckit.Worker(model)
Examples
Features
Cache
Dict based cache is available by caching argument in get_solver().
Tasks are required to be hashable.
with pckit.get_solver(worker, caching=True) as solver:
tasks = [2, 2]
The second task's solution will be reused from the cache.
You can create your own cache by implementing __contains__, __getitem__, __setitem__ of the BaseCache class.
See example for more details.
Custom iterators
You can send emails or print anything during evaluation with custom iterator. tqdm is also supported.
import tqdm
results = solver.solve(tasks, iterator=tqdm.tqdm)
See example to create your own iterator.
Logging with MPI
See example
Comsol Models, Solvers, Workers
Based on MPh package.
TBDocumented
Metadata
Release files for pckit 0.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pckit-0.5.3.tar.gz | 11.7 kB | Without provenance | Details for pckit-0.5.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pckit-0.5.3-py3-none-any.whl | Python 3 | none | any | Details for pckit-0.5.3-py3-none-any.whl |
Total release size: 26.6 kB
Release files / pckit-0.5.3.tar.gz
| Download URL | pckit-0.5.3.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b24bb18961c6cf5857e7b255da7427f4abb19d76c112c8a373ccd271b369b50
|
|
BLAKE2b-256 checksum How to use checksums |
bdca650b81a9be7f184bd62df97857728718d61033007a5ae18bd1da3eac661e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.9.18 Linux/6.5.0-1016-azure
|
Release files / pckit-0.5.3-py3-none-any.whl
| Download URL | pckit-0.5.3-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
74b72860bd24c5bdaa19111432bb2edccfde0a954a6cf29a7c0e48d9637270e1
|
|
BLAKE2b-256 checksum How to use checksums |
f3ab3e8354603ba4930fe2ffff91bd48816bdbbefaad1f79a7b6569dc59f57ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.9.18 Linux/6.5.0-1016-azure
|
Security for pckit 0.5.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.