Exemple #1
0
def refine_init(current_abs, init_cons_list, final_cons,
                initial_discrete_state, initial_controller_state, plant_sim,
                controller_sim, ci, pi, sampler, plot, init_cons,
                original_plant_cons_list, MAX_ITER, sample_ci, pi_ref, ci_ref,
                opts):

    i = 1
    while i <= MAX_ITER:
        print('iteration:', i)
        # TODO: temp function ss.init()

        (initial_state_set, final_state_set, is_final) = \
            SS.init(current_abs, init_cons_list, final_cons,
                    initial_discrete_state, initial_controller_state)

        system_params = SystemParams(initial_state_set, final_state_set,
                                     is_final, plant_sim, controller_sim, ci,
                                     pi, sampler, final_cons, pi_ref, ci_ref)
        SS.discover(current_abs, system_params)

        if plot:
            #plt.autoscale()
            #ph.figure_for_paper(plt.gca(), plot_hack.LINE_LIST)
            #plot_hack.LINE_LIST = []
            plt.show()

        if not system_params.final_state_set:
            print('did not find any abstract counter example!',
                  file=SYS.stderr)
            return False

        print('analyzing graph...')
        pi_ref.cleanup()
        if ci_ref is not None:
            ci_ref.cleanup()
        # creates a new pi_ref, ci_ref
        (promising_initial_states, ci_seq_list,
         pi_seq_list) = current_abs.get_initial_states_from_error_paths(
             initial_state_set, final_state_set, pi_ref, ci_ref, pi, ci)

        # ##!!##logger.debug('promising initial states: {}'.format(promising_initial_states))

        print('begin random testing!')
        if plot:
            f2 = plt.figure()
            f2.suptitle('random testing')

        print(len(promising_initial_states), len(ci_seq_list),
              len(pi_seq_list))
        #U.pause()
        # TODO: ugly...should it be another function?
        # Read the TODO above the function definition for more details
        (valid_promising_initial_state_list, pi_seq_list,
         ci_seq_list) = SS.filter_invalid_abs_states(promising_initial_states,
                                                     pi_seq_list, ci_seq_list,
                                                     current_abs, init_cons)
        print(len(valid_promising_initial_state_list), len(ci_seq_list),
              len(pi_seq_list))
        #U.pause()
        if valid_promising_initial_state_list == []:
            print('no valid sample found during random testing. STOP',
                  file=SYS.stderr)
            return False
        res = SS.random_test(current_abs, system_params,
                             valid_promising_initial_state_list, ci_seq_list,
                             pi_seq_list, init_cons, initial_discrete_state,
                             initial_controller_state, sample_ci)
        if plot:
            #ph.figure_for_paper(plt.gca(), plot_hack.LINE_LIST)
            plt.show()
        if res:
            print('Concretized', file=SYS.stderr)
            fp.append_data(
                opts.op_fname,
                '{0} Concrete Traces({2}) for: {1} {0}\n'.format(
                    '=' * 20, opts.sys_path, len(res)))
            fp.append_data(opts.op_fname, '{}\n'.format(res))
            return True

        (current_abs, init_cons_list) = SS.refine_init_based(
            current_abs,
            promising_initial_states,  # should it not be valid_promising_initial_state_list?
            original_plant_cons_list)  #, pi_ref, ci_ref)
        pi_ref.refine()
        if ci_ref is not None:
            ci_ref.refine()
        i += 1
    print('Failed: MAX iterations {} exceeded'.format(MAX_ITER),
          file=SYS.stderr)
Exemple #2
0
def refine_trace(current_abs, init_cons_list, final_cons,
                 initial_discrete_state, initial_controller_state, plant_sim,
                 controller_sim, ci, pi, sampler, plot, init_cons,
                 original_plant_cons_list):

    (initial_state_set, final_state_set, is_final) = \
        SS.init(current_abs, init_cons_list, final_cons,
                initial_discrete_state, initial_controller_state)

    system_params = SystemParams(
        initial_state_set,
        final_state_set,
        is_final,
        plant_sim,
        controller_sim,
        ci,
        pi,
        sampler,
        final_cons,
    )

    SS.discover(current_abs, system_params)

    if plot:
        plt.autoscale()
        plt.show()

    while True:

        if not system_params.final_state_set:
            print('did not find any abstract counter example!',
                  file=SYS.stderr)
            return True
        else:
            print('analyzing graph...')
        (promising_initial_states, ci_seq_list) = \
            current_abs.get_initial_states_from_error_paths(initial_state_set, final_state_set)

        # ##!!##logger.debug('promising initial states: {}'.format(promising_initial_states))

        print('begin random testing!')
        if plot:
            f2 = plt.figure()
            f2.suptitle('random testing')

        # TODO: ugly...should it be another function?
        # Read the TODO above the function definition for more details
        valid_promising_initial_state_list = SS.filter_invalid_abs_states(
            promising_initial_states, current_abs, init_cons)
        if valid_promising_initial_state_list == []:
            print('no valid sample found during random testing. STOP',
                  file=SYS.stderr)
            return True

        done = SS.random_test(
            current_abs,
            system_params,
            valid_promising_initial_state_list,
            ci_seq_list,
            init_cons,
            initial_discrete_state,
            initial_controller_state,
        )
        if plot:
            plt.show()
        if done:
            print('Concretized', file=SYS.stderr)
            return True
        current_abs = SS.refine_trace_based(
            current_abs,
            current_abs.compute_error_paths(initial_state_set,
                                            final_state_set), system_params)
Exemple #3
0
def falsify_using_model(
        current_abs,
        init_cons_list,
        final_cons,
        initial_discrete_state,
        initial_controller_state,
        plant_sim,
        controller_sim,
        ci,
        pi,
        sampler,
        #plot,
        init_cons,
        original_plant_cons_list,
        MAX_ITER,
        sample_ci,
        pi_ref,
        ci_ref,
        opts,
        sys_sim,
        sys,
        prop):

    # TODO: temp function ss.init()

    (initial_state_set, final_state_set, is_final) = \
        SS.init(current_abs, init_cons_list, final_cons,
                initial_discrete_state, initial_controller_state)

    system_params = SystemParams(
        initial_state_set,
        final_state_set,
        is_final,
        plant_sim,
        controller_sim,
        ci,
        pi,
        sampler,
        init_cons,
        final_cons,
        pi_ref,
        ci_ref
        )

    SS.discover(current_abs, system_params)

    opts.plotting.show()

    if not system_params.final_state_set:
        print('did not find any abstract counter example!', file=SYS.stderr)
        return False

    print('analyzing graph...')
    # creates a new pi_ref, ci_ref
    (error_paths,
     ci_seq_list,
     pi_seq_list) = current_abs.get_error_paths(initial_state_set,
                                                final_state_set,
                                                pi_ref,
                                                ci_ref,
                                                pi,
                                                ci,
                                                opts.max_paths)
    print('Refining...')
    if opts.refine == 'model-dft':
        import modelrefine as MR
        MR.refine_dft_model_based(current_abs,
                                  error_paths,
                                  pi_seq_list,
                                  system_params,
                                  sys_sim,
                                  opts,
                                  sys,
                                  prop)
    elif opts.refine == 'model-dmt':
        import modelrefine as MR
        MR.refine_dmt_model_based(current_abs,
                                  error_paths,
                                  pi_seq_list,
                                  system_params,
                                  sys_sim,
                                  opts,
                                  sys,
                                  prop)
    elif opts.refine == 'model-dct':
        import modelrefine as MR
        raise NotImplementedError
    elif opts.refine == 'model-rel':
        import modelrefine as MR
        MR.refine_rel_model_based(current_abs,
                                  error_paths,
                                  pi_seq_list,
                                  system_params,
                                  sys_sim,
                                  opts,
                                  sys,
                                  prop)
    else:
        assert(False)

    exit()


    print('begin random testing!')

    print(len(promising_initial_states), len(ci_seq_list), len(pi_seq_list))

    (valid_promising_initial_state_list,
     pi_seq_list, ci_seq_list) = SS.filter_invalid_abs_states(promising_initial_states,
                                                              pi_seq_list,
                                                              ci_seq_list,
                                                              current_abs,
                                                              init_cons)

    print(len(valid_promising_initial_state_list), len(ci_seq_list), len(pi_seq_list))

    if valid_promising_initial_state_list == []:
        print('no valid sample found for random testing. STOP', file=SYS.stderr)
        return False

    res = RT.random_test(
        current_abs,
        system_params,
        valid_promising_initial_state_list,
        ci_seq_list,
        pi_seq_list,
        init_cons,
        initial_discrete_state,
        initial_controller_state,
        sample_ci
        )

    if res:
        print('Concretized', file=SYS.stderr)
        fp.append_data(opts.op_fname,
                       '{0} Concrete Traces({2}) for: {1} {0}\n'.
                       format('='*20, opts.sys_path, len(res)))
        fp.append_data(opts.op_fname, '{}\n'.format(res))
        return True
Exemple #4
0
def refine_init(
        current_abs,
        init_cons_list,
        final_cons,
        initial_discrete_state,
        initial_controller_state,
        plant_sim,
        controller_sim,
        ci,
        pi,
        sampler,
        #plot,
        init_cons,
        original_plant_cons_list,
        MAX_ITER,
        sample_ci,
        pi_ref,
        ci_ref,
        opts):

    i = 1
    while i <= MAX_ITER:
        print('iteration:', i)
        # TODO: temp function ss.init()

        (initial_state_set, final_state_set, is_final) = \
            SS.init(current_abs, init_cons_list, final_cons,
                    initial_discrete_state, initial_controller_state)

        system_params = SystemParams(
            initial_state_set,
            final_state_set,
            is_final,
            plant_sim,
            controller_sim,
            ci,
            pi,
            sampler,
            init_cons,
            final_cons,
            pi_ref,
            ci_ref
            )
        SS.discover(current_abs, system_params)

        opts.plotting.show()

        if not system_params.final_state_set:
            print('did not find any abstract counter example!', file=SYS.stderr)
            return False

        print('analyzing graph...')
        pi_ref.cleanup()
        if ci_ref is not None:
            ci_ref.cleanup()
        # creates a new pi_ref, ci_ref
        (promising_initial_states,
            ci_seq_list,
            pi_seq_list) = current_abs.get_initial_states_from_error_paths(initial_state_set,
                                                                           final_state_set,
                                                                           pi_ref,
                                                                           ci_ref,
                                                                           pi,
                                                                           ci,
                                                                           opts.max_paths)

        # ##!!##logger.debug('promising initial states: {}'.format(promising_initial_states))

        print('begin random testing!')
        #POFF
#         if plot:
#             f2 = plt.figure()
#             f2.suptitle('random testing')

        print(len(promising_initial_states), len(ci_seq_list), len(pi_seq_list))
        #U.pause()
        # TODO: ugly...should it be another function?
        # Read the TODO above the function definition for more details
        (valid_promising_initial_state_list,
            pi_seq_list, ci_seq_list) = SS.filter_invalid_abs_states(
                        promising_initial_states,
                        pi_seq_list,
                        ci_seq_list,
                        current_abs,
                        init_cons)
        print(len(valid_promising_initial_state_list), len(ci_seq_list), len(pi_seq_list))
        #U.pause()
        if valid_promising_initial_state_list == []:
            print('no valid sample found during random testing. STOP', file=SYS.stderr)
            return False
        res = RT.random_test(
            current_abs,
            system_params,
            valid_promising_initial_state_list,
            ci_seq_list,
            pi_seq_list,
            init_cons,
            initial_discrete_state,
            initial_controller_state,
            sample_ci
            )

        opts.plotting.show()

        if res:
            print('Concretized', file=SYS.stderr)
            fp.append_data(opts.op_fname,
                           '{0} Concrete Traces({2}) for: {1} {0}\n'.
                           format('='*20, opts.sys_path, len(res)))
            fp.append_data(opts.op_fname, '{}\n'.format(res))
            return True

        (current_abs, init_cons_list) = SS.refine_init_based(
                current_abs,
                promising_initial_states, # should it not be valid_promising_initial_state_list?
                original_plant_cons_list)#, pi_ref, ci_ref)
        pi_ref.refine()
        if ci_ref is not None:
            ci_ref.refine()
        i += 1
    print('Failed: MAX iterations {} exceeded'.format(MAX_ITER), file=SYS.stderr)
Exemple #5
0
def refine_trace(
        current_abs,
        init_cons_list,
        final_cons,
        initial_discrete_state,
        initial_controller_state,
        plant_sim,
        controller_sim,
        ci,
        pi,
        sampler,
        #plot,
        init_cons,
        original_plant_cons_list):

    (initial_state_set, final_state_set, is_final) = \
        SS.init(current_abs, init_cons_list, final_cons,
                initial_discrete_state, initial_controller_state)

    system_params = SystemParams(
        initial_state_set,
        final_state_set,
        is_final,
        plant_sim,
        controller_sim,
        ci,
        pi,
        sampler,
        init_cons,
        final_cons,
        )

    SS.discover(current_abs, system_params)

    #POFF
#     if plot:
#         plt.autoscale()
#         plt.show()

    while True:

        if not system_params.final_state_set:
            print('did not find any abstract counter example!', file=SYS.stderr)
            return True
        else:
            print('analyzing graph...')
        (promising_initial_states, ci_seq_list) = \
            current_abs.get_initial_states_from_error_paths(initial_state_set, final_state_set)

        # ##!!##logger.debug('promising initial states: {}'.format(promising_initial_states))

        print('begin random testing!')
        #POFF
#         if plot:
#             f2 = plt.figure()
#             f2.suptitle('random testing')


        # TODO: ugly...should it be another function?
        # Read the TODO above the function definition for more details
        valid_promising_initial_state_list = SS.filter_invalid_abs_states(
                promising_initial_states,
                current_abs,
                init_cons)
        if valid_promising_initial_state_list == []:
            print('no valid sample found during random testing. STOP', file=SYS.stderr)
            return True

        done = RT.random_test(
            current_abs,
            system_params,
            valid_promising_initial_state_list,
            ci_seq_list,
            init_cons,
            initial_discrete_state,
            initial_controller_state,
            )
        #POFF
#         if plot:
#             plt.show()
        if done:
            print('Concretized', file=SYS.stderr)
            return True
        current_abs = SS.refine_trace_based(
                current_abs,
                current_abs.compute_error_paths(initial_state_set, final_state_set),
                system_params)