示例#1
0
文件: tactics.py 项目: asyaf/ivy
    def apply(self):
        frames = ta._ivy_ag.states
        bad_states = negate_clauses(get_safety_property())
        action = get_big_action()
        ta._ivy_ag.actions[repr(action)] = action

        init_frame = last_frame = frames[0]

        # TODO: test conjecture in initial

        with InterruptContext() as ic:
            while not ic.interrupted:

                # the property is true in all frames and all "clauses" are pushed
                # the goal stack is empty

                # check if we found an infuctive invariant
                for i in range(len(frames) - 1):
                    if check_cover(frames[i + 1], frames[i]):
                        return True

                # add new frame

                last_frame = ta.arg_add_action_node(last_frame, action, None)
                push_goal(goal_at_arg_node(bad_states, last_frame))
                self.step(label='new frame')

                # push facts to last frame
                recalculate_facts(last_frame, ta.arg_get_conjuncts(arg_get_pred(last_frame)))

                while not ic.interrupted:
                    current_goal = top_goal()
                    if current_goal is None:
                        # goal stack is empty
                        break

                    if remove_if_refuted(current_goal):
                        continue

                    if current_goal.node == init_frame:
                        # no invariant
                        print "No Invariant!"
                        return False

                    push_diagram(current_goal, False)

                    dg = top_goal()

                    if refine_or_reverse(dg, False):
                        pass
                        # dg is proved,

                        # # propagate phase
                        # for i in range(1, len(frames)):
                        #     facts_to_check = (set(arg_get_conjuncts(frames[i-1])) -
                        #                       set(arg_get_conjuncts(frames[i])))
                        #     recalculate_facts(frames[i], facts_to_check)

                    else:
                        # new goal pushed
                        pass

                # propagate phase
                for i in range(1, len(frames)):
                    facts_to_check = (set(arg_get_conjuncts(frames[i-1])) -
                                      set(arg_get_conjuncts(frames[i])))
                    recalculate_facts(frames[i], list(facts_to_check))

            assert ic.interrupted
            print "UPDR Interrupted by SIGINT"
            return None
    def apply(self):
        frames = ta._ivy_ag.states
        bad_states = negate_clauses(get_safety_property())
        action = get_big_action()
        ta._ivy_ag.actions[repr(action)] = action

        init_frame = last_frame = frames[0]

        # TODO: test conjecture in initial

        with InterruptContext() as ic:
            while not ic.interrupted:

                # the property is true in all frames and all "clauses" are pushed
                # the goal stack is empty

                # check if we found an infuctive invariant
                for i in range(len(frames) - 1):
                    if check_cover(frames[i + 1], frames[i]):
                        return True

                # add new frame

                last_frame = ta.arg_add_action_node(last_frame, action, None)
                push_goal(goal_at_arg_node(bad_states, last_frame))
                self.step(label='new frame')

                # push facts to last frame
                recalculate_facts(
                    last_frame, ta.arg_get_conjuncts(arg_get_pred(last_frame)))

                while not ic.interrupted:
                    current_goal = top_goal()
                    if current_goal is None:
                        # goal stack is empty
                        break

                    if remove_if_refuted(current_goal):
                        continue

                    if current_goal.node == init_frame:
                        # no invariant
                        print "No Invariant!"
                        return False

                    push_diagram(current_goal, False)

                    dg = top_goal()

                    if refine_or_reverse(dg, False):
                        pass
                        # dg is proved,

                        # # propagate phase
                        # for i in range(1, len(frames)):
                        #     facts_to_check = (set(arg_get_conjuncts(frames[i-1])) -
                        #                       set(arg_get_conjuncts(frames[i])))
                        #     recalculate_facts(frames[i], facts_to_check)

                    else:
                        # new goal pushed
                        pass

                # propagate phase
                for i in range(1, len(frames)):
                    facts_to_check = (set(arg_get_conjuncts(frames[i - 1])) -
                                      set(arg_get_conjuncts(frames[i])))
                    recalculate_facts(frames[i], list(facts_to_check))

            assert ic.interrupted
            print "UPDR Interrupted by SIGINT"
            return None
示例#3
0
def interactive_updr():
    frames = ta._ivy_ag.states
    if len(frames) != 1:
        raise InteractionError(
            "Interactive UPDR can only be started when the ARG " +
            "contains nothing but the initial state.")

    bad_states = negate_clauses(ta.get_safety_property())
    action = ta.get_big_action()
    ta._ivy_ag.actions[repr(action)] = action

    init_frame = last_frame = frames[0]

    # TODO: test conjecture in initial

    while True:

        # the property is true in all frames and all "clauses" are pushed
        # the goal stack is empty

        # check if we found an infuctive invariant
        for i in range(len(frames) - 1):
            if t.check_cover(frames[i + 1], frames[i]):
                ta.step(msg="Inductive invariant found at frame {}".format(i),
                        i=i)
                # return True

        # add new frame

        last_frame = ta.arg_add_action_node(last_frame, action, None)
        ta.push_goal(ta.goal_at_arg_node(bad_states, last_frame))
        ta.step(msg="Added new frame")

        # push facts to last frame
        t.recalculate_facts(last_frame,
                            ta.arg_get_conjuncts(ta.arg_get_pred(last_frame)))

        while True:
            current_goal = ta.top_goal()
            if current_goal is None:
                # goal stack is empty
                break

            if t.remove_if_refuted(current_goal):
                continue

            if current_goal.node == init_frame:
                # no invariant
                print "No Invariant!"
                # return False

            dg = ta.get_diagram(current_goal, False)
            options = OrderedDict()
            for c in simplify_clauses(dg.formula).conjuncts():
                options[str(c)] = c
            user_selection = (yield UserSelectMultiple(
                options=options,
                title="Generalize Diagram",
                prompt="Choose which literals to take as the refutation goal",
                default=options.values()))
            assert user_selection is not None
            ug = ta.goal_at_arg_node(Clauses(list(user_selection)),
                                     current_goal.node)
            ta.push_goal(ug)
            ta.step(msg='Pushed user selected goal', ug=ug)

            goal = ta.top_goal()
            preds, action = ta.arg_get_preds_action(goal.node)
            assert action != 'join'
            assert len(preds) == 1
            pred = preds[0]
            axioms = ta._ivy_interp.background_theory()
            theory = and_clauses(
                ivy_transrel.forward_image(pred.clauses, axioms,
                                           action.update(ta._ivy_interp,
                                                         None)), axioms)
            goal_clauses = simplify_clauses(goal.formula)
            assert len(goal_clauses.defs) == 0

            s = z3.Solver()
            s.add(clauses_to_z3(theory))
            s.add(clauses_to_z3(goal_clauses))
            is_sat = s.check()
            if is_sat == z3.sat:
                bi = ta.backward_image(goal.formula, action)
                x, y = False, ta.goal_at_arg_node(bi, pred)
            elif is_sat == z3.unsat:
                user_selection, user_is_sat = yield UserSelectCore(
                    theory=theory,
                    constrains=goal_clauses.fmlas,
                    title="Refinement",
                    prompt="Choose the literals to use",
                )
                assert user_is_sat is False
                core = Clauses(user_selection)
                x, y = True, ivy_transrel.interp_from_unsat_core(
                    goal_clauses, theory, core, None)
            else:
                assert False, is_sat

            t.custom_refine_or_reverse(goal, x, y, False)

        # propagate phase
        for i in range(1, len(frames)):
            facts_to_check = (set(ta.arg_get_conjuncts(frames[i - 1])) -
                              set(ta.arg_get_conjuncts(frames[i])))
            t.recalculate_facts(frames[i], list(facts_to_check))
示例#4
0
文件: iupdr.py 项目: simudream/ivy
def interactive_updr():
    frames = ta._ivy_ag.states
    if len(frames) != 1:
        raise InteractionError(
            "Interactive UPDR can only be started when the ARG " + "contains nothing but the initial state."
        )

    bad_states = negate_clauses(ta.get_safety_property())
    action = ta.get_big_action()
    ta._ivy_ag.actions[repr(action)] = action

    init_frame = last_frame = frames[0]

    # TODO: test conjecture in initial

    while True:

        # the property is true in all frames and all "clauses" are pushed
        # the goal stack is empty

        # check if we found an infuctive invariant
        for i in range(len(frames) - 1):
            if t.check_cover(frames[i + 1], frames[i]):
                ta.step(msg="Inductive invariant found at frame {}".format(i), i=i)
                # return True

        # add new frame

        last_frame = ta.arg_add_action_node(last_frame, action, None)
        ta.push_goal(ta.goal_at_arg_node(bad_states, last_frame))
        ta.step(msg="Added new frame")

        # push facts to last frame
        t.recalculate_facts(last_frame, ta.arg_get_conjuncts(ta.arg_get_pred(last_frame)))

        while True:
            current_goal = ta.top_goal()
            if current_goal is None:
                # goal stack is empty
                break

            if t.remove_if_refuted(current_goal):
                continue

            if current_goal.node == init_frame:
                # no invariant
                print "No Invariant!"
                # return False

            dg = ta.get_diagram(current_goal, False)
            options = OrderedDict()
            for c in simplify_clauses(dg.formula).conjuncts():
                options[str(c)] = c
            user_selection = (
                yield UserSelectMultiple(
                    options=options,
                    title="Generalize Diagram",
                    prompt="Choose which literals to take as the refutation goal",
                    default=options.values(),
                )
            )
            assert user_selection is not None
            ug = ta.goal_at_arg_node(Clauses(list(user_selection)), current_goal.node)
            ta.push_goal(ug)
            ta.step(msg="Pushed user selected goal", ug=ug)

            goal = ta.top_goal()
            preds, action = ta.arg_get_preds_action(goal.node)
            assert action != "join"
            assert len(preds) == 1
            pred = preds[0]
            axioms = ta._ivy_interp.background_theory()
            theory = and_clauses(
                ivy_transrel.forward_image(pred.clauses, axioms, action.update(ta._ivy_interp, None)), axioms
            )
            goal_clauses = simplify_clauses(goal.formula)
            assert len(goal_clauses.defs) == 0

            s = z3.Solver()
            s.add(clauses_to_z3(theory))
            s.add(clauses_to_z3(goal_clauses))
            is_sat = s.check()
            if is_sat == z3.sat:
                bi = ta.backward_image(goal.formula, action)
                x, y = False, ta.goal_at_arg_node(bi, pred)
            elif is_sat == z3.unsat:
                user_selection, user_is_sat = yield UserSelectCore(
                    theory=theory,
                    constrains=goal_clauses.fmlas,
                    title="Refinement",
                    prompt="Choose the literals to use",
                )
                assert user_is_sat is False
                core = Clauses(user_selection)
                x, y = True, ivy_transrel.interp_from_unsat_core(goal_clauses, theory, core, None)
            else:
                assert False, is_sat

            t.custom_refine_or_reverse(goal, x, y, False)

        # propagate phase
        for i in range(1, len(frames)):
            facts_to_check = set(ta.arg_get_conjuncts(frames[i - 1])) - set(ta.arg_get_conjuncts(frames[i]))
            t.recalculate_facts(frames[i], list(facts_to_check))