|
| 1 | +# learnlib-py4j-example |
| 2 | + |
| 3 | +This example shows how to learn a python-based system under learning (SUL) using [LearnLib][learnlib]. |
| 4 | + |
| 5 | +This example is a *python-first* example, meaning the core of our setup is written in Python and we use [Py4J][py4j] in order to use the Java based LearnLib from our Python program. |
| 6 | + |
| 7 | +If you want a *java-first* approach, you may look into technologies such as [Jython][jython] which allows you to run Python programs on the JVM. If you want to go deeper down that rabbit hole, [GraalVM][graal] may be worth a look as well. |
| 8 | + |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +In order to run the Java side of the example you need to have a working [JDK][jdk] 8+ installation. |
| 13 | +OpenJDK should work just as well as OracleJDK. |
| 14 | +Furthermore, we use [Maven][maven] in order to build our LearnLib-Py4J connector. |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +For the Python side of this example you need to have a working [Python][python] installation. |
| 19 | +The example has only been tested with Python3 - Python2 may or may not work. |
| 20 | +We strongly suggest to install the [`virtualenv`][venv] tool in order setup the Python side of Py4J without affecting your global Python installation - although technically you only need to have the `python-py4j` libraries installed somewhere. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +In order to show the learned hypothesis automata, we suggest to install [GraphVIZ][graphviz]. |
| 25 | +However, if GraphVIZ (more specifically, `DOT`) is not installed, LearnLib will fallback to the [JUNG][jung] library, which is a fully Java-based visualization approach. |
| 26 | + |
| 27 | + |
| 28 | +## Preparing the example |
| 29 | + |
| 30 | + |
| 31 | +First, we will build the Java side of this example, which will leave us with an executable JAR containing the LearnLib and Py4J code. |
| 32 | + |
| 33 | +``` |
| 34 | +cd java |
| 35 | +mvn package |
| 36 | +cd .. |
| 37 | +``` |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +Then, we setup our virtual python environment and install the py4j libraries |
| 42 | + |
| 43 | +``` |
| 44 | +virtualenv python/venv |
| 45 | +source python/venv/bin/activate |
| 46 | +pip install py4j==0.10.8.1 |
| 47 | +``` |
| 48 | + |
| 49 | +## Running the example |
| 50 | + |
| 51 | +To run the example, we first start our JVM process that listens for any calls performed by our Python programm (via the Py4J framework): |
| 52 | + |
| 53 | +`java -jar java/target/learnlib-py4j-example-1.0-SNAPSHOT.jar` |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +Then, we simply run our Python program: |
| 58 | + |
| 59 | +`python python/Main.py` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +Once we are finished, the JVM process can be terminated by pressing <kbd>Ctrl</kbd> + <kbd>C</kbd> |
| 64 | + |
| 65 | + |
| 66 | +[learnlib]: https://github.com/LearnLib/learnlib |
| 67 | +[py4j]: https://www.py4j.org/ |
| 68 | +[jython]: http://www.jython.org/ |
| 69 | +[graal]: https://www.graalvm.org/ |
| 70 | +[jdk]: https://www.oracle.com/technetwork/java/javase/overview/index.html |
| 71 | +[maven]: https://maven.apache.org/ |
| 72 | +[python]: https://www.python.org/ |
| 73 | +[venv]: https://virtualenv.pypa.io |
| 74 | +[graphviz]: http://www.graphviz.org/ |
| 75 | +[jung]: http://jung.sourceforge.net/ |
0 commit comments