BPpy: Behavioral Programming In Python
Project description
BPpy: Behavioral Programming In Python
A Python implementation for the Behavioral Programming paradigm
Install
You can install bppy
with pip:
pip install bppy
Running the Hot-Cold Example
python bppy/examples/hot_cold_all.py
Writing a BPpy program
bppy/examples/hot_cold_all.py:
from bppy import *
@b_thread
def add_hot():
yield {request: BEvent("HOT")}
yield {request: BEvent("HOT")}
yield {request: BEvent("HOT")}
@b_thread
def add_cold():
yield {request: BEvent("COLD")}
yield {request: BEvent("COLD")}
yield {request: BEvent("COLD")}
@b_thread
def control_temp():
e = BEvent("Dummy")
while True:
e = yield {waitFor: All(), block: e}
if __name__ == "__main__":
b_program = BProgram(bthreads=[add_hot(), add_cold(), control_temp()],
event_selection_strategy=SimpleEventSelectionStrategy(),
listener=PrintBProgramRunnerListener())
b_program.run()
Using Z3-Solver SMT
bppy/examples/hot_cold_smt.py:
from bppy import *
hot = Bool('hot')
cold = Bool('cold')
@b_thread
def three_hot():
for i in range(3):
while (yield {request: hot})[hot] == false:
pass
@b_thread
def three_cold():
for j in range(3):
m = yield {request: cold}
while m[cold] == false:
m = yield {request: cold}
@b_thread
def exclusion():
while True:
yield {block: And(hot, cold)}
@b_thread
def schedule():
yield {block: cold}
if __name__ == "__main__":
b_program = BProgram(bthreads=[three_cold(), three_hot(), exclusion(), schedule()],
event_selection_strategy=SMTEventSelectionStrategy(),
listener=PrintBProgramRunnerListener())
b_program.run()
Dynamically adding b-threads
bppy/examples/hot_cold_dynamic.py:
from bppy import *
@b_thread
def add_hot():
yield {request: BEvent("HOT")}
yield {request: BEvent("HOT")}
yield {request: BEvent("HOT")}
@b_thread
def add_cold():
yield {request: BEvent("COLD")}
yield {request: BEvent("COLD")}
yield {request: BEvent("COLD")}
@b_thread
def control_temp(block_event):
block_event = yield {waitFor: All(), block: block_event}
b_program.add_bthread(control_temp(block_event))
if __name__ == "__main__":
b_program = BProgram(bthreads=[add_hot(), add_cold(), control_temp(BEvent("HOT"))],
event_selection_strategy=SimpleEventSelectionStrategy(),
listener=PrintBProgramRunnerListener())
b_program.run()
To cite this repository in publications:
@misc{bppy,
author = {Tom Yaacov},
title = {BPpy: Behavioral Programming In Python},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/bThink-BGU/BPpy}},
}
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
bppy-0.0.3.tar.gz
(9.0 kB
view details)
Built Distribution
bppy-0.0.3-py3-none-any.whl
(10.5 kB
view details)
File details
Details for the file bppy-0.0.3.tar.gz
.
File metadata
- Download URL: bppy-0.0.3.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc87accd253c226561777fbf48413d56c7b4e7caabbf67ba3b9053247ede34e7 |
|
MD5 | 40a72f61308d8139af99f91aec580913 |
|
BLAKE2b-256 | 3fb4adc568009fe24d495207d1e7403d2aea4ae4178054a46b1d4645adb0bfa3 |
File details
Details for the file bppy-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: bppy-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38431c6fd85b06843715f71093431ed8c48894c9df497964a953c21f59d62f9c |
|
MD5 | 7045a3a95d9802f36730b378c2dba7c2 |
|
BLAKE2b-256 | 21728a7728357db944d022e1be77920b4cf3325501b66d016e6abdd4c848dac4 |