from teachers.teacher import Teacher from util.dotloader import load_mealy_dot path = "/home/tom/projects/lstar/rers/industrial/m54.dot" mm = load_mealy_dot(path) mm.render_graph(tempfile.mktemp('.gv'), render_options={'ignore_self_edges': ['error', 'invalid']},) # Use the W method equivalence checker eqc = SmartWmethodEquivalenceChecker(mm, m=len(mm.get_states()) + 1, stop_on={'error'}) eqc.onCounterexample(lambda x: print('Counterexample:', x)) teacher = Teacher(mm, eqc) # We are learning a mealy machine learner = MealyLearner(teacher) hyp = learner.run( show_intermediate=False, render_options={'ignore_self_edges': ['error', 'invalid']}, ) hyp.render_graph(tempfile.mktemp('.gv')) assert len(hyp.get_states()) == len(mm.get_states())
if __name__ == "__main__": sul = ArithmeticTest() #sul.process_input(['add', 'exec', 'show']) ct = CounterexampleTracker() eqc = SmartWmethodEquivalenceChecker(sul, horizon=3) eqc = StackedChecker( GeneticEquivalenceChecker(sul, ct, pop_n=100000), SmartWmethodEquivalenceChecker(sul, horizon=3, order_type='ce count')) eqc.onCounterexample(lambda ce: ct.add(ce)) teacher = Teacher(sul, eqc) # We are learning a mealy machine learner = MealyLearner(teacher) def print_stats(hyp=None): print("Member queries:", teacher.member_query_counter) print("Equivalence queries:", teacher.equivalence_query_counter) print("Test queries:", teacher.test_query_counter) hyp = learner.run(show_intermediate=False, on_hypothesis=print_stats) hyp.render_graph()