from equivalencecheckers.bruteforce import BFEquivalenceChecker from equivalencecheckers.wmethod import WmethodEquivalenceChecker, SmartWmethodEquivalenceChecker from learners.mealylearner import MealyLearner from suls.mealymachine import MealyState, MealyMachine 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']}, )
def reset(self): self.counter = 0 self.last_action = None def get_alphabet(self): return ('add', 'sub', 'exec', 'show') 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)
from equivalencecheckers.wmethod import SmartWmethodEquivalenceChecker from learners.mealylearner import MealyLearner from teachers.teacher import Teacher from util.mealygenerator import minimize, MakeRandomMealyMachine # Randomly generate a mealy machine A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] O = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] mm = MakeRandomMealyMachine(200, A, O) # It may not be minimal, so minimize it mm = minimize(mm) # Use the W method equivalence checker with early stopping eqc = SmartWmethodEquivalenceChecker(mm, m=len(mm.get_states()), stop_on={'error'}) teacher = Teacher(mm, eqc) learner = MealyLearner(teacher) hyp = learner.run(show_intermediate=False) assert len(hyp.get_states()) == len(mm.get_states()) print("done")
# mm = DictCache( # load_mealy_dot(path), # storagepath=cache # )#.load(cache) mm = load_mealy_dot(path) mm.render_graph(render_options={ 'ignore_self_edges': ['error', 'invalid'], 'ignore_edges': ['error'] }) # Use the W method equivalence checker eqc = SmartWmethodEquivalenceChecker( mm, #horizon=3, m=len(mm.get_states()), stop_on={'error'}, order_type='ce count') eqc.onCounterexample(lambda x: print('Counterexample:', x)) teacher = Teacher(mm, eqc) # We are learning a mealy machine learner = TTTMealyLearner(teacher) hyp = learner.run(show_intermediate=False #render_options={'ignore_self_edges': ['error', 'invalid']}, ) #hyp.render_graph(tempfile.mktemp('.gv'))
problem = "Problem12" # Since we are interacting with a real system, we will want to cache # the responses so we don't unnecessarily repeat expensive queries cache = f'cache/{problem}' # The query caches are implemented as wrappers around the SUL classes # they work transparently and only catch queries that have been asked previously sul = RersTrieCache(RERSConnectorV4( f'../../rers/TrainingSeqReachRers2019/{problem}/{problem}'), storagepath=cache).load(cache) # We use a specialized W-method equivalence checker which features # early stopping on invalid inputs, which speeds things up a lot #eqc = RersWmethodEquivalenceChecker(sul, False, m=15) eqc = SmartWmethodEquivalenceChecker(sul, horizon=10, stop_on={'invalid_input'}, stop_on_startswith={'error'}) # Set up the teacher, with the system under learning and the equivalence checker teacher = Teacher(sul, eqc) # Set up the learner who only talks to the teacher # We let it save checkpoints of every intermediate hypothesis learner = MealyLearner(teacher)\ .enable_checkpoints("checkpoints", problem) # Get the learners hypothesis hyp = learner.run( show_intermediate=True, render_options={'ignore_self_edges': ['error', 'invalid']}, on_hypothesis=lambda x: check_result( x,