Skip to content
Edi Muškardin edited this page Dec 20, 2023 · 25 revisions

Welcome to the AALpy Wiki!

AALpy is a light-weight active automata learning library written in pure Python. By implementing a single method and a few lines of configuration, you can start learning automata.

Whether you work with regular languages or you would like to learn models of reactive systems, AALpy supports a wide range of modeling formalisms, including deterministic, non-deterministic, and stochastic automata. You can use it to learn deterministic finite automata, Moore machines, and Mealy machines of deterministic systems. If the system that you would like to learn shows non-deterministic or stochastic behavior, AALpy allows you to learn observable nondeterministic finite-state machines, Markov decision processes, or stochastic Mealy machines. AALpy enables efficient learning by providing a large set of equivalence oracles, implementing various conformance testing strategies.

Installation

Use the package manager pip to install AALpy.

pip install aalpy

The minimum required version of Python is 3.6.
Ensure that you have Graphviz installed and added to your path if you want to visualize models.

For manual installation, clone the master and install the following dependency.

pip install pydot
# and to install the library
python setup.py install

Documentation and Wiki

If you are interested in automata learning or would like to understand the automata learning process in more detail, please check out our Wiki. On Wiki, you will find more detailed examples on how to use AALpy.

Examples.py contains many examples demonstrating all AALpy functionality are presented.

Usage

All automata learning procedures follow this high-level approach:

The following snippet demonstrates a short example in which an automaton is either loaded or randomly generated and then learned.

from aalpy.utils import load_automaton_from_file, generate_random_dfa
from aalpy.SULs import DfaSUL
from aalpy.oracles import RandomWalkEqOracle, StatePrefixEqOracle
from aalpy.learning_algs import run_Lstar

# load an automaton
# automaton = load_automaton_from_file('path_to_the_file.dot', automaton_type='')

# or randomly generate one
random_dfa = generate_random_dfa(alphabet=[1,2,3,4,5], num_states=10, num_accepting_states=2)

# get input alphabet of the automaton
alphabet = random_dfa.get_input_alphabet()

# create a SUL instance for the automaton/system under learning
sul = DfaSUL(random_dfa)

# define the equivalence oracle
eq_oracle = RandomWalkEqOracle(alphabet, sul, num_steps=5000, reset_prob=0.09)
eq_oracle_2 = StatePrefixEqOracle(alphabet, sul, walks_per_state=20, walk_len=10)

# start learning
learned_dfa = run_Lstar(alphabet, sul, eq_oracle, automaton_type='dfa')

# save automaton to file and visualize it
learned_dfa.save()
learned_dfa.visualize()

Another example shows how easy it is to learn a regular expression with AALpy. For more details on this example, take a look at - How to learn Regex with AALpy

from aalpy.oracles import StatePrefixEqOracle
from aalpy.SULs import RegexSUL
from aalpy.learning_algs import run_Lstar

regex = 'abc(b|c)+(ab|c)*'
alphabet = ['a', 'b', 'c']

regex_sul = RegexSUL(regex)

eq_oracle = StatePrefixEqOracle(alphabet, regex_sul, walks_per_state=100,
                                walk_len=20)

learned_regex = run_Lstar(alphabet, regex_sul, eq_oracle, automaton_type='dfa', print_level=2)


or learned_regex.visualize()

This code snippet results in:

Hypothesis 1 has 1 states.
Hypothesis 2 has 7 states.
Hypothesis 3 has 8 states.
-----------------------------------
Learning Finished.
Learning Rounds:  3
Number of states: 8
Time (in seconds)
  Total                : 0.05
  Learning algorithm   : 0.0
  Conformance checking : 0.05
Learning Algorithm
 # Membership Queries  : 85
 # MQ Saved by Caching : 120
 # Steps               : 582
Equivalence Query
 # Membership Queries  : 800
 # Steps               : 18173
-----------------------------------

and