Python Bindings PlugIn

This plug-in generates libFAUDES bindings for the scripting language Python; see http://www.python.org. With this plug-in, the most essential libFAUDES data types and functions can be accesed from the Python interpreter.

Disclaimer: the primary scripting laguage for libFAUDES is Lua; see the Lua bindings plug-in. Specifically, Lua bindings provide a more comprehensive interface, which is systematically tested on a more regular basis. If you experience short commings of libFAUDES Python bindings, please do not hesitate to report back to us.

Restrictions:

  • The build system allows for either Lua bindings or Python bindings; building both simultaneously is not supported.
  • For most plug-ins, bindings are automatically generated via SWIG based on so called interface files (residing in libfaudes/plugins/*/registry/*.i); regarding Python, only the plug-ins Synthesis and Observer have been tested.

Example Script

In large, libFAUDES Python bindings follow the same conventions as the Lua bindingins. Thus, you may want to inspect the documentation of the latter. For further inspiration, tutorials can be found at pybindings/tutorial.

For the following example, run Python in/from a directoty in which the libFAUDES bindings reside (files _faudes.so and faudes.py).

# load libFAUDES bindings
import faudes
# test
faudes.Version()
# machine 1
gL1=faudes.Generator()
gL1.InsInitState("Idle")
gL1.SetMarkedState("Idle")
gL1.InsState("Busy")
gL1.InsEvent("alpha1")
gL1.InsEvent("beta1")
gL1.SetTransition("Idle","alpha1","Busy")
gL1.SetTransition("Busy","beta1","Idle")
# machine 2
gL2=faudes.Generator()
gL2.InsInitState("Idle")
gL2.SetMarkedState("Idle")
gL2.InsState("Busy")
gL2.InsEvent("alpha2")
gL2.InsEvent("beta2")
gL2.SetTransition("Idle","alpha2","Busy")
gL2.SetTransition("Busy","beta2","Idle")
# overall plant
gL=faudes.Generator()
faudes.Parallel(gL1,gL2,gL)
# controllable events
sCtrl=faudes.EventSet()
sCtrl.Insert("alpha1")
sCtrl.Insert("alpha2")
# specification aka buffer
gE=faudes.Generator()
gE.InsInitState("Empty")
gE.SetMarkedState("Empty")
gE.InsState("Full")
gE.InsEvent("beta1")
gE.InsEvent("alpha2")
gE.SetTransition("Empty","beta1","Full")
gE.SetTransition("Full","alpha2","Empty")
# lift specification to overall eventset
sAll=faudes.EventSet()
sAll=gL.Alphabet()
faudes.InvProject(gE,sAll)
# supremal closed loop
gK=faudes.Generator()
faudes.SupConNB(gL,sCtrl,gE,gK)
# show result on console
gK.Write()
# save result as graphics
gK.GraphWrite("K.png")

Note: for graphics output you must have installed dot from the GraphViz package. If dot is not in the systems path, you may direct libfaudes via faudes.DocExecPath("/wherever_dot_is/dot").

Build System

To use python bindings, you will need to configure and recompile libFAUDES; see also build-system documentation for an overview.

Notes:

  • You should configure libFAUDES to use no further plug-ins than Synthesis and Observer. This is done in the main Makefile. If you require Python bindings other plug-ins, please let us know.
  • The build system is best supported on Linux and OS X. For Windows we recommend to MSYS2 or equivalents.
  • The build process relies on the developer package of your Python distribution. It needs to be pointed to the paths of Python.h and the Python shared object libpython.so. There is an attempt to figure those paths automatically, however, your milage may vary; see pybindings/Makefile.plugin for manual configuration.
  • After building libFAUDES as a shared object, copy the files pybindings/tutorial/faudes.py and pybindings/tutorial/_faudes.so to reside in the same directory as your Python project. Test your settings by starting a Python command promt within your project directory and try, e.g. import faudes and faudes.Version().
  • After re-compiling libFAUDES and importing to Python, make shure to clear all caches; i.e., start with a clean directory after each iteration of re-compilation.

License

The Python bindings plug-in is distributed with libFAUDES. All code is provided under terms of the LGPL.

Copyright (c) 2023, 2024 Thomas Moor.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen