Python Bindings Plug-In

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:

  • Although the build system allows for multiple bindings plug-ins, we recommend to either use Lua bindings or Python bindings, but not both for the same build.
  • 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.SupCon(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 minimum number of plug-ins. This is done in the main Makefile. The test cases for python cover the synthesis plug-in. If you have used other pluhg-ins, please submit your test cases.
  • The build system is best supported on Linux and OS X. For Windows, we have test pybindings within the MSYS2 enviroment and it works just fine. We did not yet test with MSVC compilers and/or plain cmd.exe terminal.
  • 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 (.pyd on Windows) to reside in the same directory as your Python project. Test your settings by starting a Python command promt
    within your project directory. Try , e.g., import faudes and print 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 - 2025 Thomas Moor.

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen