Skip to main content

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 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()

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


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.2.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

bppy-0.0.2-py3-none-any.whl (10.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page