Coder Social home page Coder Social logo

doganulus / python-monitors Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 5.0 44.97 MB

A pure Python package to monitor formal specifications over temporal sequences

License: GNU General Public License v3.0

Python 97.74% ANTLR 2.26%
regular-expressions temporal-logic runtime-verification monitoring

python-monitors's Introduction

About python-monitors

python-monitors is a pure Python package to monitor formal specifications over temporal sequences. It supports several specification languages such as regular expressions and variants of temporal logic. The usage is fairly easy thanks to Python and allows fast prototyping of applications that monitor temporal sequences using these specifications.

WARNING: This repository is depreciated in favor of the project Reelay but will remain as a pure Python solution albeit limited in functionatity and speed. Reelay implements the same runtime monitors and more in C++, which are accessible from Python via bindings.

Install

The latest release of the package can be installed via pip such that

pip install python-monitors

This command will also install dependencies python-intervals and antlr4-python3-runtime. Alternatively, you can install directly from this repository by running the command

pip install git+https://github.com/doganulus/python-monitors.git 

Use

MTL over propositions

First generate a monitor from past Metric Temporal Logic (MTL) formula:

from monitors import mtl
 
my_mtl_monitor = mtl.monitor("always(q -> once[2,4](p))")

Then process a data sequence (over propositions) by updating the monitor and collecting the output at each step:

data = dict(
	p = [False, True,  False, False, False, False, False, True,  False, False, False, False, False, False, False], 
	q = [False, False, False, False, False, True,  False, False, False, False, False, False, False, False, True ]
)
 
for p, q in zip(data['p'], data['q']):
 
	output = my_mtl_monitor.update(p = p, q = q)
 
	print(my_mtl_monitor.time, output, my_mtl_monitor.states)

MTL over predicates (also known as STL)

Any Boolean-valued Python function can be used as a predicate in MTL formulas. They are passed to monitor construction via a dictionary as follows:

def my_predicate(x):
    return x < 5

# Named parameters should share the same strings in the expression 
my_mtl_monitor = mtl.monitor("always[0,5](p(x))", p=my_predicate)
 
for n in [9, 13, 4, 1, 2, 3,1,1,1,2]:
    output = my_mtl_monitor.update(x = n)
    print(my_mtl_monitor.time, my_predicate(n), output, my_mtl_monitor.states)

Regular expressions over propositions and predicates

Regular expressions over propositions and predicates are available in a similar fashion:

from monitors import regexp
 
def pred1(x):
    return x < 5
 
def pred2(x):
    return x > 12
 
# Named parameters should share the same strings in the expression 
my_reg_monitor = regexp.monitor("True*; p1(x); p2(x)+; p1(x)+", p1=pred1, p2=pred2)
 
for n in [1, 1, 1, 1, 13, 13, 14, 1, 1, 2]:
    output = my_reg_monitor.update(x = n)
    print(output, my_reg_monitor.states)

Cite

For MTL monitoring algorithm, please cite Online Monitoring of Metric Temporal Logic using Sequential Networks. For RE monitoring algorithm, please cite Sequential Circuits from Regular Expressions Revisited.

python-monitors's People

Contributors

doganulus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-monitors's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.