Skip to content
Edi Muškardin edited this page Mar 19, 2021 · 26 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 want to learn models of reactive systems, AALpy supports a wide range of modelling 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 want to learn shows non-deterministic or stochastic behavior, you can use AALpy to learn observable nondeterministic finite-state machines, Markov decision processes, or stochastic transducers.

AALpy enables efficient learning by providing a large array of equivalence oracles, implementing various conformance testing strategies. Learning is mostly based on Angluin's L* algorithm, for which AALpy supports a selection of optimizations, including efficient counterexample processing. Finally, support for learning abstracted nondeterministic Mealy machines enables efficient learning of system models with large input space.

If AALpy misses a feature that you need, you can easily extend it or request a feature. In case of any questions, start a discussion or open a pull request.

Usage

All automata learning procedures follow this high-level approach:

  • Define input alphabet
  • Define system under learning (SUL)
  • Define equivalence oracle
  • Run learning algorithm with input alphabet

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

from aalpy.utils import load_automaton_from_file, save_automaton_to_file, visualize_automaton, 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')
# or randomly generate one
random_dfa = generate_random_dfa(alphabet=[1,2,3,4,5],num_states=2000, num_accepting_states=200)
# get input alphabet of the automaton
alphabet = random_dfa.get_input_alphabet()
# create a SUL instance for the automaton/system under learning
sul = DfaSUL(automaton)

# 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
save_automaton_to_file(learned_dfa, path='Learned_Automaton', file_type='dot')
visualize_automaton(learned_dfa)