Skip to main content

A simple Python model checking package

Project description

pyModelChecking

pyModelChecking is a small Python model checking package. Currently, it is able to represent Kripke structures, CTL, LTL, and CTL* formulas and it provides model checking methods for LTL, CTL, and CTL*. In future, it will hopefully support symbolic model checking.

Usage

First of all, import all the functions and all the classes in the package.

>>> from pyModelChecking import *

In order to represent a Kripke structure use the Kripke class.

>>> K=Kripke(R=[(0,0),(0,1),(1,2),(2,2),(3,3)],
...          L={0: set(['p']), 1:set(['p','q']),3:set(['p'])})

CTL can be represented by importing the CTL module.

>>> from pyModelChecking.CTL import *

>>> phi=AU(True,Or('q',Not(EX('p'))))

>>> print(phi)

A(True U (q or not (EX p)))

Whenever a non-CTL formula is built, an exception is thrown.

>>> psi=A(F(G('p')))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyModelChecking/CTL/language.py", line 42, in __init__
    self.wrap_subformulas(phi,StateFormula)
  File "pyModelChecking/CTLS/language.py", line 59, in wrap_subformulas
    phi.__desc__,phi))
TypeError: expected a CTL state formula, got the CTL path formula G p

The function modelcheck in module CTL finds the states of Kripke structure that model a given CTL formula.

>>>  modelcheck(K,phi)

set([1, 2])

The formula AFG p, which we tried to build above, is a LTL formula. The LTL module can be used to represent and model check it over any Kripke structure.

>>> from pyModelChecking.LTL import *

>>> psi=A(F(G('p')))

>>> print(psi)

A(G(F(p))

>>> modelcheck(K,psi)

set([3])

The module CTLS is meant to deal with CTL* formulas. It can also combine and model checks CTL and LTL formulas.

>>> from pyModelChecking.CTLS import *

>>> eta=A(F(E(U(True,Imply('p',Not('q'))))))

>>> print(eta,eta.__class__)

(A(F(E((True U (p --> not q))))), <class 'pyModelChecking.CTLS.language.A'>)

>>> rho=A(G(And(X('p'),'p')))

>>> print(rho,rho.__class__)

(A(G((X(p) and p))), <class 'pyModelChecking.CTLS.language.A'>)

>>> gamma=And(phi, psi)

>>> print(gamma,gamma.__class__)

(A(True U (q or not (EX p))) and A(G(F(p)))), <class 'pyModelChecking.CTLS.language.And'>)

>>> modelcheck(K,eta)

set([0, 1, 2, 3])

>>> modelcheck(K, psi)

set([3])

>>> modelcheck(K, gamma)

set([])

Whenever a CTL* formula is a CTL formula (LTL formula), CTL (LTL) model checking can be applied to it.

>>> import pyModelChecking.CTL as CTL

>>> CTL.modelcheck(K,eta)

set([0, 1, 2, 3])

>>> CTL.modelcheck(K,rho)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyModelChecking/CTL/model_checking.py", line 183, in modelcheck
    raise RuntimeError('%s is not a CTL formula' % (formula))
RuntimeError: A(G((X(p) and p))) is not a CTL formula

>>> import pyModelChecking.LTL as LTL

>>> LTL.modelcheck(K,rho)

set([3])

Copyright and license

pyModelChecking Copyright (C) 2015-2018 Alberto Casagrande acasagrande@units.it

pyModelChecking is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

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

pyModelChecking-0.1.5.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyModelChecking-0.1.5-py2-none-any.whl (36.1 kB view details)

Uploaded Python 2

File details

Details for the file pyModelChecking-0.1.5.tar.gz.

File metadata

  • Download URL: pyModelChecking-0.1.5.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

File hashes

Hashes for pyModelChecking-0.1.5.tar.gz
Algorithm Hash digest
SHA256 41f8f07473e74d53bf30fcf5d3962011011cfab0fc083d2553098087205b075a
MD5 c8c449650ec050cf6bebfe873b851cdd
BLAKE2b-256 c4caeb56d43ffd67db81a2e09578dc0df383d12bff5a47fd11402a8bf28ed002

See more details on using hashes here.

File details

Details for the file pyModelChecking-0.1.5-py2-none-any.whl.

File metadata

  • Download URL: pyModelChecking-0.1.5-py2-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

File hashes

Hashes for pyModelChecking-0.1.5-py2-none-any.whl
Algorithm Hash digest
SHA256 7509a6b806a2eb808cddfac605f39a3e7ad7a110d23da3b14bd30c1f08399c2c
MD5 db0b14c5f395c1bbb7edc19760c842ed
BLAKE2b-256 8e73c20e1a361fcd3a9ecd95902b4d41c1ae2a17fa803bff0aad63828a7dea33

See more details on using hashes here.

Supported by

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