def diagram(self): if self.parent != None and self.g.parent_state != None: self.checkpoint() g = self.g ## print "g.constraints: %s" % g.constraints if hasattr(g, 'reverse_result'): # "print reverse diagram" dgm = ivy_interp.diagram(self.g.parent_state, self.g.reverse_result[1], extra_axioms=self.g.reverse_result[0]) else: dgm = ivy_interp.diagram(self.g.parent_state, self.g.state) if dgm != None: goal = lu.reskolemize_clauses( dgm, self.g.parent_state.domain.skolemizer()) g.constraints = goal g.set_state(goal) self.update() else: dlg = Toplevel(self) Label(dlg, text="The current state is vacuous.").pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg)
def try_remembered_graph(self, node): dlg = Toplevel(self) lbl = "Choose a remembered goal:" Label(dlg, text=lbl).pack() S = Scrollbar(dlg) T = Listbox(dlg, height=8, width=50, selectmode=SINGLE) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) if not hasattr(self, 'remembered_graphs'): self.remembered_graphs = {} names = [n for n in self.remembered_graphs] for name in names: T.insert(END, name) b = Button( dlg, text="Try", command=functools.partial(self.do_try_remembered_graph, node, T, dlg, names)) b.pack(padx=5, side=TOP) b = Button(dlg, text="Cancel", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg)
def one_step_reach(self, state, clauses): with RunContext(self): rs = reach_state_from_pred_no_abduction(state, clauses) if rs != None: self.reachable_tree.add(rs) t = self.g.transition_to(state) if t: pre, action, label, post = t self.reachable_tree.transitions.append( (rs.pred, action, label, rs)) f = filter_conjectures(state, rs.clauses) if f: dlg = Toplevel(self) Label( dlg, text="The following conjectures have been eliminated:" ).pack() S = Scrollbar(dlg) T = Listbox(dlg, height=8, width=50, selectmode=SINGLE) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) for conj in f: T.insert(END, repr(clauses_to_formula(conj))) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg) return rs
def reach(self): if self.parent != None and self.g.parent_state != None: # self.checkpoint() g = self.g ## print "g.constraints: %s" % g.constraints rs = self.parent.one_step_reach(g.parent_state, g.constraints) if rs != None: clauses = rs.clauses # print "reach clauses: {}".format(clauses) dlg = Toplevel(self) Label(dlg, text="Goal reached! A reachable state has been added.").pack() b = Button(dlg, text="View state", command=functools.partial(self.view_reached,clauses,dlg)) b.pack(padx=5,side=TOP) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg) # g.constraints = [] # g.set_state(clauses) # self.update() else: dlg = Toplevel(self) Label(dlg, text="Cannot reach this state in on step from any known reachable state. Try \"reverse\".").pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg)
def one_step_reach(self,state,clauses): with RunContext(self): rs = reach_state_from_pred_no_abduction(state,clauses) if rs != None: self.reachable_tree.add(rs) t = self.g.transition_to(state) if t: pre,action,label,post = t self.reachable_tree.transitions.append((rs.pred,action,label,rs)) f = filter_conjectures(state,rs.clauses) if f: dlg = Toplevel(self) Label(dlg, text="The following conjectures have been eliminated:").pack() S = Scrollbar(dlg) T = Listbox(dlg, height=8, width=50, selectmode=SINGLE) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) for conj in f: T.insert(END, repr(clauses_to_formula(conj))) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg) return rs
def reverse_update_concrete_clauses(self, state, clauses): with RunContext(self): try: if state.pred != None: print "reverse from %s to %s: post_state = %s" % ( state.id, state.pred.id, clauses) next_state = state.pred clauses = reverse_update_concrete_clauses(state, clauses) return (clauses, state.pred) elif hasattr(state, 'join_of') and state.join_of: next_state = state return reverse_join_concrete_clauses( state, state.join_of, clauses) return None except UnsatCoreWithInterpolant as ici: # print "core: %s" % ici.core # print "interp: %s" % ici.interp if ici.interp != None: used_names = used_symbols_clauses( Clauses([[Literal(0, a)] for a, d in self.g.domain.concept_spaces])) name = unused_name_with_base( 'itp', set(s.name for s in used_names)) concept = clauses_to_concept(name, ici.interp) dlg = Toplevel(self) Label( dlg, text= "The pre-state is vacuous. The following concept can be used to prove your goal in the post-state:" ).pack() S = Scrollbar(dlg) T = Text(dlg, height=4, width=100) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) T.insert( END, 'concept ' + repr(concept[0]) + ' = ' + repr( concept[1])) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) b = Button( dlg, text="Refine", command=functools.partial(self.refine, concept, dlg)) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg) return (false_clauses(), next_state) raise IvyError(None, "UNSAT, but interpolant could not be computed") return ([[]], next_state)
def reverse_update_concrete_clauses(self, state, clauses): with RunContext(self): try: if state.pred != None: print "reverse from %s to %s: post_state = %s" % ( state.id, state.pred.id, clauses) next_state = state.pred clauses = reverse_update_concrete_clauses(state, clauses) return (clauses, state.pred) elif hasattr(state, 'join_of') and state.join_of: next_state = state return reverse_join_concrete_clauses( state, state.join_of, clauses) return None except UnsatCoreWithInterpolant as ici: # print "core: %s" % ici.core # print "interp: %s" % ici.interp if ici.interp != None: used_names = used_symbols_clauses( Clauses([[Literal(0, a)] for a, d in self.g.domain.concept_spaces])) name = unused_name_with_base( 'itp', set(s.name for s in used_names)) concept = clauses_to_concept(name, ici.interp) dlg = Toplevel(self) Label( dlg, text= "The pre-state is vacuous. The following concept can be used to prove your goal in the post-state:" ).pack() S = Scrollbar(dlg) T = Text(dlg, height=4, width=100) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) T.insert( END, 'concept ' + repr(concept[0]) + ' = ' + repr(concept[1])) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) b = Button(dlg, text="Refine", command=functools.partial( self.refine, concept, dlg)) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg) return (false_clauses(), next_state) raise IvyError(None, "UNSAT, but interpolant could not be computed") return ([[]], next_state)
def bmc(self,state,err_cond): res = self.g.bmc(state,err_cond) if res == None: dlg = Toplevel(self) Label(dlg, text="The condition is unreachable along the given path").pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg) return ui_create(res,self.tk,Toplevel(self.tk))
def __exit__(self, exc_type, exc_val, exc_tb): self.parent.ready() if exc_type == IvyError: dlg = Toplevel(self.parent) Label(dlg, text=repr(exc_val)).pack(side=TOP) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.parent.root) self.parent.tk.wait_window(dlg) return True return False # don't block any exceptions
def __exit__(self,exc_type, exc_val, exc_tb): self.parent.ready() if exc_type == IvyError: dlg = Toplevel(self.parent) Label(dlg, text=repr(exc_val)).pack(side=TOP) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.parent.root) self.parent.tk.wait_window(dlg) return True return False # don't block any exceptions
def add_relation(self): dlg = Toplevel(self) Label(dlg, text="Add a relation [example: p(X,a,Y)]:").pack() e = Entry(dlg) e.focus() e.pack() action = functools.partial(self.add_rel_lit,dlg,e) e.bind('<Return>', lambda q,action=action: action()) Button(dlg, text="Add",command=action).pack(padx=5,side=TOP) b = Button(dlg, text="Cancel", command=dlg.destroy).pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg)
def remember(self): dlg = Toplevel(self) Label(dlg, text="Enter a name for this goal:").pack() e = Entry(dlg) e.focus() e.pack() action = functools.partial(self.remember_aux,dlg,e) e.bind('<Return>', action) Button(dlg, text="Remember",command=action).pack(padx=5,side=TOP) b = Button(dlg, text="Cancel", command=dlg.destroy).pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg)
def bmc(self, state, err_cond): res = self.g.bmc(state, err_cond) if res == None: dlg = Toplevel(self) Label(dlg, text="The condition is unreachable along the given path" ).pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg) return ui_create(res)
def conjecture(self): if self.parent != None and self.g.parent_state != None: self.checkpoint() g = self.g # print "g.constraints: %s" % g.constraints # print "g.state: %s" % g.state # print "g.constraints.is_true: %s" % g.constraints.is_true() s = g.state if g.constraints.is_true() else g.constraints # print "s: {}".format(s) ri = self.parent.conjecture(g.parent_state, s) if ri != None: core, interp = ri dlg = Toplevel(self) Label( dlg, text= "Based on this goal and the known reached states, we can conjecture the following invariant:" ).pack() S = Scrollbar(dlg) T = Text(dlg, height=4, width=100) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) T.insert(END, repr(clauses_to_formula(interp))) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg) # goal = dual_clauses(interp,skolemizer=self.g.parent_state.domain.skolemizer()) goal = lu.reskolemize_clauses( core, self.g.parent_state.domain.skolemizer()) g.constraints = goal g.set_state(goal) self.update() else: dlg = Toplevel(self) Label( dlg, text= "Cannot form a conjecture based in the known reached states and this goal. Suggest manually materializing a goal pattern." ).pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg)
def try_conjecture(self,node): dlg = Toplevel(self) lbl = "Choose a conjecture to prove:" Label(dlg, text=lbl).pack() S = Scrollbar(dlg) T = Listbox(dlg, height=8, width=50, selectmode=SINGLE) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) udc = undecided_conjectures(node) for conj in udc: T.insert(END, repr(clauses_to_formula(conj))) b = Button(dlg, text="Prove", command=functools.partial(self.do_try_conjecture,node,T,dlg,udc)) b.pack(padx=5,side=TOP) b = Button(dlg, text="Cancel", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg)
def try_conjecture(self, node): dlg = Toplevel(self) lbl = "Choose a conjecture to prove:" Label(dlg, text=lbl).pack() S = Scrollbar(dlg) T = Listbox(dlg, height=8, width=50, selectmode=SINGLE) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) udc = undecided_conjectures(node) for conj in udc: T.insert(END, repr(clauses_to_formula(conj))) b = Button(dlg, text="Prove", command=functools.partial(self.do_try_conjecture, node, T, dlg, udc)) b.pack(padx=5, side=TOP) b = Button(dlg, text="Cancel", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg)
def diagram(self): if self.parent != None and self.g.parent_state != None: self.checkpoint() g = self.g ## print "g.constraints: %s" % g.constraints if hasattr(g,'reverse_result'): # "print reverse diagram" dgm = ivy_interp.diagram(self.g.parent_state,self.g.reverse_result[1],extra_axioms = self.g.reverse_result[0]) else: dgm = ivy_interp.diagram(self.g.parent_state,self.g.state) if dgm != None: goal = lu.reskolemize_clauses(dgm,self.g.parent_state.domain.skolemizer()) g.constraints = goal g.set_state(goal) self.update() else: dlg = Toplevel(self) Label(dlg, text="The current state is vacuous.").pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg)
def reverse(self): if self.parent != None and self.g.parent_state != None: self.g.attributes.append("backtrack_point") self.checkpoint() g = self.g ## print "g.constraints: %s" % g.constraints p = self.parent.reverse_update_concrete_clauses(g.parent_state, g.constraints) if p == None: dlg = Toplevel(self) Label(dlg, text="Cannot reverse.").pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg) return clauses, parent_state = p g.constraints = true_clauses() g.parent_state = parent_state g.set_state(and_clauses(parent_state.clauses,clauses)) print "reverse: state = {}".format(g.state) g.reverse_result = (parent_state.clauses,clauses) self.update()
def conjecture(self): if self.parent != None and self.g.parent_state != None: self.checkpoint() g = self.g # print "g.constraints: %s" % g.constraints # print "g.state: %s" % g.state # print "g.constraints.is_true: %s" % g.constraints.is_true() s = g.state if g.constraints.is_true() else g.constraints # print "s: {}".format(s) ri = self.parent.conjecture(g.parent_state, s) if ri != None: core,interp = ri dlg = Toplevel(self) Label(dlg, text="Based on this goal and the known reached states, we can conjecture the following invariant:").pack() S = Scrollbar(dlg) T = Text(dlg, height=4, width=100) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) T.insert(END, repr(clauses_to_formula(interp))) b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg) # goal = dual_clauses(interp,skolemizer=self.g.parent_state.domain.skolemizer()) goal = lu.reskolemize_clauses(core,self.g.parent_state.domain.skolemizer()) g.constraints = goal g.set_state(goal) self.update() else: dlg = Toplevel(self) Label(dlg, text="Cannot form a conjecture based in the known reached states and this goal. Suggest manually materializing a goal pattern.").pack() b = Button(dlg, text="OK", command=dlg.destroy) b.pack(padx=5,side=TOP) uu.center_window_on_window(dlg,self.root) self.tk.wait_window(dlg)
def try_remembered_graph(self, node): dlg = Toplevel(self) lbl = "Choose a remembered goal:" Label(dlg, text=lbl).pack() S = Scrollbar(dlg) T = Listbox(dlg, height=8, width=50, selectmode=SINGLE) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) if not hasattr(self, 'remembered_graphs'): self.remembered_graphs = {} names = [n for n in self.remembered_graphs] for name in names: T.insert(END, name) b = Button(dlg, text="Try", command=functools.partial(self.do_try_remembered_graph, node, T, dlg, names)) b.pack(padx=5, side=TOP) b = Button(dlg, text="Cancel", command=dlg.destroy) b.pack(padx=5, side=TOP) uu.center_window_on_window(dlg, self.root) self.tk.wait_window(dlg)