Generic computation implementation on COINSTAC.
Project description
COINSTAC computations development made easy.
Express development(see examples/basic folder for a simple use case):
Commands:
mkdir -p examples/basic/dist --- Needed only once -------
chmod u+x deploy.sh --- Needed only once -------
./deploy.sh examples/basic/dist --- Needed everytime you make some changes -------
Deployment:
pip install coinstac-computation (or add to requirements.txt file)
Coinstac base computation framework that supports:
- Multiple computation phases.
- Multiple iterations per phase.
- Automatic phase transition.
Example: Gather max even numbers from each site
A full working use case is in the example directory where
- Local sites filters out even numbers and sends to the remote.
- Remote finds the max across sites and returns the final result to each of the sites.
- Sites save final result.
inputspec.json data:
[
{
"data": {
"value": [10, 3, 5, 6, 7, 8, 12, 38, 32, 789, 776, 441]
}
},
{
"data": {
"value": [12, 33, 88, 61, 37, 58, 103, 3386, 312, 9, 77, 41]
}
}
]
Local node pipeline:
import os
from coinstac_computation import COINSTACPyNode, ComputationPhase
class PhaseLoadData(ComputationPhase):
def compute(self):
data = []
for d in self.input['data']:
if d % 2 == 0:
data.append(d)
return {'filtered_data': data}
class PhaseSaveResult(ComputationPhase):
def compute(self):
with open(f"{self.state['outputDirectory'] + os.sep + 'results.txt'}", 'w') as out:
out.write(f"{self.input['aggregated_data']}")
local = COINSTACPyNode(mode='local', debug=True)
local.add_phase(PhaseLoadData)
local.add_phase(PhaseSaveResult)
Remote node pipeline:
from coinstac_computation import COINSTACPyNode, ComputationPhase, PhaseEndWithSuccess
class PhaseCollectMaxEvenData(ComputationPhase):
def compute(self):
data = []
for site, site_vars in self.input.items():
site_max = max(site_vars['filtered_data'])
data.append(site_max)
return {'aggregated_data': data}
remote = COINSTACPyNode(mode='remote', debug=True)
remote.add_phase(PhaseCollectMaxEvenData)
remote.add_phase(PhaseEndWithSuccess)
Entry point:
import coinstac
from local_pipeline import local
from remote_pipeline import remote
coinstac.start(local.compute, remote.compute)
Run:
cd example
docker build -t base . && coinstac-simulator
Development note:
- Must set
debug=False
while deploying. - Backward compatible to the older library(compspecVersion=1):
- Add the following snippet at the end of local and remote pipeline scripts.
if __name__ == "__main__": local.to_stdout()
- Use version 1.0 compspec format.
- Comment out line
CMD ["python", "entry.py"]
in theDockerfile
. - You can also use a remote debugger in pycharm as here.
Advanced use case: Phases with multiple iterations example
- Where each site cast a vote for multiple(default=51) times.
- Remote gathers the votes and returns the final voting result at the end.
- Sites save the final result.
Thanks!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file coinstac-computation-0.4.tar.gz
.
File metadata
- Download URL: coinstac-computation-0.4.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3a6c49ea702c1f29d09a97b722fcc1e40b3415a8f113c838a01b8979e4a31e8 |
|
MD5 | 3d8ccc1955fedf01fddbd2952e4b439c |
|
BLAKE2b-256 | e25e0f1a25d60bcb92e135a8d9e822c090fb55f0bda355fc4ee189f8bcb89b02 |