Esempio n. 1
0
def refine_trace_based(A, error_paths, system_params):

    # ##!!##logger.debug('executing trace based refinement')

    traversed_state_set = set()
    sap = A.states_along_paths(error_paths)
    for path in sap:
        traversed_state_set.update(path)

    param_dict = refine_param_dict(A)

    RA = AA.abstraction_factory(
        param_dict,
        A.T,
        A.num_dims,
        A.controller_sym_path_obj,
        A.min_smt_sample_dist,
        A.plant_abstraction_type,
        A.controller_abstraction_type
        )

    # split the traversed states

    # construct a list of sets and then flatten
    #refined_ts_list = U.flatten( [refine_state(A, RA, ts) for ts in traversed_state_set])

    #abs2rch_abs_state_dict = get_reachable_abs_states(RA, system_params, refined_ts_list)

    return RA
Esempio n. 2
0
def refine_init_based(A, promising_initial_abs_states,
                      original_plant_cons_list):#, pi_ref, ci_ref):

    # ##!!##logger.debug('executing init based refinement')

    # checks if the given constraint has a non empty intersection with the
    # given plant initial states. These are the actual initial plant sets
    # specified in the tst file.

    def in_origianl_initial_plant_cons(ic):
        for oic in original_plant_cons_list:
            if oic & ic:
                return True
        assert('Should never happen. Should be caught by SS.filter_invalid_abs_states')
        return False

    init_cons_list = []

    # ignore cells which have no overlap with the initial state

    for init_state in promising_initial_abs_states:
        ic = A.plant_abs.get_ival_cons_abs_state(init_state.plant_state)
        if in_origianl_initial_plant_cons(ic):
            init_cons_list.append(ic)

    param_dict = refine_param_dict(A)

#    AA.AbstractState.clear()

    refined_abs = AA.abstraction_factory(
        param_dict,
        A.T,
        A.num_dims,
        A.controller_sym_path_obj,
        #A.ci_grid_eps/2,
        A.min_smt_sample_dist,
        A.plant_abstraction_type,
        A.controller_abstraction_type,
        A.graph_lib
        )

    # TODO: what a hack!
    #pi_ref = A.plant_abs.pi_ref
#     pi_ref.refine()
#     ci_ref.refine()
#     refined_abs.plant_abs.pi_ref = pi_ref
#     refined_abs.controller_abs.ci_ref = ci_ref

#    refined_abs = AA.GridBasedAbstraction(param_dict,
#                                          A.plant_sim,
#                                          A.T,
#                                          A.sample,
#                                          init_cons_list,
#                                          A.final_cons,
#                                          A.controller_sim,
#                                          A.num_dims,
#                                          prog_bar=True)

    return (refined_abs, init_cons_list)
Esempio n. 3
0
def refine_init_based(A, promising_initial_abs_states,
                      original_plant_cons_list):#, pi_ref, ci_ref):

    # ##!!##logger.debug('executing init based refinement')

    # checks if the given constraint has a non empty intersection with the
    # given plant initial states. These are the actual initial plant sets
    # specified in the tst file.

    def in_origianl_initial_plant_cons(ic):
        for oic in original_plant_cons_list:
            if oic & ic:
                return True
        assert('Should never happen. Should be caught by SS.filter_invalid_abs_states')
        return False

    init_cons_list = []

    # ignore cells which have no overlap with the initial state

    for init_state in promising_initial_abs_states:
        ic = A.plant_abs.get_ival_cons_abs_state(init_state.plant_state)
        if in_origianl_initial_plant_cons(ic):
            init_cons_list.append(ic)

    param_dict = refine_param_dict(A)

#    AA.AbstractState.clear()

    refined_abs = AA.abstraction_factory(
        param_dict,
        A.T,
        A.num_dims,
        A.controller_sym_path_obj,
        #A.ci_grid_eps/2,
        A.min_smt_sample_dist,
        A.plant_abstraction_type,
        A.controller_abstraction_type,
        )

    # TODO: what a hack!
    #pi_ref = A.plant_abs.pi_ref
#     pi_ref.refine()
#     ci_ref.refine()
#     refined_abs.plant_abs.pi_ref = pi_ref
#     refined_abs.controller_abs.ci_ref = ci_ref

#    refined_abs = AA.GridBasedAbstraction(param_dict,
#                                          A.plant_sim,
#                                          A.T,
#                                          A.sample,
#                                          init_cons_list,
#                                          A.final_cons,
#                                          A.controller_sim,
#                                          A.num_dims,
#                                          prog_bar=True)

    return (refined_abs, init_cons_list)
Esempio n. 4
0
def create_abstraction(sys, prop, opts):
    num_dims = sys.num_dims
    plant_config_dict = sys.plant_config_dict
    controller_path_dir_path = sys.controller_path_dir_path
    controller_object_str = sys.controller_object_str

    T = prop.T

    METHOD = opts.METHOD

    plant_abstraction_type = 'cell'
    if METHOD == 'concolic':
        controller_abstraction_type = 'concolic'

        # Initialize concolic engine

        var_type = {}

        # state_arr is not symbolic in concolic exec,
        # with concrete controller states

        var_type['state_arr'] = 'int_arr'
        var_type['x_arr'] = 'int_arr'
        var_type['input_arr'] = 'int_arr'
        concolic_engine = CE.concolic_engine_factory(var_type, num_dims,
                                                     controller_object_str)

        # sampler = sample.Concolic(concolic_engine)

        sampler = sample.IntervalConcolic(concolic_engine)
    elif METHOD == 'concrete':
        sampler = sample.IntervalSampler()
        controller_abstraction_type = 'concrete'
        controller_sym_path_obj = None

        # TODO: manual contruction of paths!!!!
        # use OS independant APIs from fileOps
    elif METHOD == 'symbolic':
        sampler = None
        if opts.symbolic_analyzer == 'klee':
            controller_abstraction_type = 'symbolic_klee'
            if opts.cntrl_rep == 'smt2':
                controller_path_dir_path += '/klee/'
            else:
                raise err.Fatal('KLEE supports only smt2 files!')
        elif opts.symbolic_analyzer == 'pathcrawler':
            controller_abstraction_type = 'symbolic_pathcrawler'
            if opts.cntrl_rep == 'smt2':
                controller_path_dir_path += '/pathcrawler/'
            elif opts.cntrl_rep == 'trace':
                controller_path_dir_path += '/controller'
            else:
                raise err.Fatal('argparse should have caught this!')

            # TAG:PCH_IND
            # Parse PC Trace
            import CSymLoader as CSL
            controller_sym_path_obj = CSL.load_sym_obj(
                (opts.cntrl_rep, opts.trace_struct), controller_path_dir_path)
        else:
            raise err.Fatal('unknown symbolic analyzer requested:{}'.format(
                opts.symbolic_analyzer))

    else:
        raise NotImplementedError

    # TODO: parameters like controller_sym_path_obj are absraction dependant
    # and should not be passed directly to abstraction_factory. Instead a
    # flexible structure should be created which can be filled by the
    # CAsymbolic abstraction module and supplied as a substructure. I guess the
    # idea is that an abstraction module should be 'pluggable'.
    current_abs = abstraction.abstraction_factory(
        plant_config_dict,
        T,
        num_dims,
        controller_sym_path_obj,
        sys.min_smt_sample_dist,
        plant_abstraction_type,
        controller_abstraction_type,
    )
    return current_abs, sampler
Esempio n. 5
0
def create_abstraction(sys, prop, opts):
    num_dims = sys.num_dims
    plant_config_dict = sys.plant_config_dict
    controller_path_dir_path = sys.controller_path_dir_path
    controller_object_str = sys.controller_object_str

    T = prop.T

    METHOD = opts.METHOD

    plant_abstraction_type = 'cell'
    if METHOD == 'concolic':
        controller_abstraction_type = 'concolic'

        # Initialize concolic engine

        var_type = {}

        # state_arr is not symbolic in concolic exec,
        # with concrete controller states

        var_type['state_arr'] = 'int_arr'
        var_type['x_arr'] = 'int_arr'
        var_type['input_arr'] = 'int_arr'
        concolic_engine = CE.concolic_engine_factory(
            var_type,
            num_dims,
            controller_object_str)

        # sampler = sample.Concolic(concolic_engine)

        sampler = sample.IntervalConcolic(concolic_engine)
    elif METHOD == 'concrete':
        sampler = sample.IntervalSampler()
        controller_abstraction_type = 'concrete'
        controller_sym_path_obj = None

    elif METHOD == 'concrete_no_controller':
        sampler = sample.IntervalSampler()
        controller_abstraction_type = 'concrete_no_controller'
        controller_sym_path_obj = None

        # TODO: manual contruction of paths!!!!
        # use OS independant APIs from fileOps
    elif METHOD == 'symbolic':
        sampler = None
        if opts.symbolic_analyzer == 'klee':
            controller_abstraction_type = 'symbolic_klee'
            if opts.cntrl_rep == 'smt2':
                controller_path_dir_path += '/klee/'
            else:
                raise err.Fatal('KLEE supports only smt2 files!')
        elif opts.symbolic_analyzer == 'pathcrawler':
            controller_abstraction_type = 'symbolic_pathcrawler'
            if opts.cntrl_rep == 'smt2':
                controller_path_dir_path += '/pathcrawler/'
            elif opts.cntrl_rep == 'trace':
                controller_path_dir_path += '/controller'
            else:
                raise err.Fatal('argparse should have caught this!')

            # TAG:PCH_IND
            # Parse PC Trace
            import CSymLoader as CSL
            controller_sym_path_obj = CSL.load_sym_obj((opts.cntrl_rep, opts.trace_struct), controller_path_dir_path)
        else:
            raise err.Fatal('unknown symbolic analyzer requested:{}'.format(opts.symbolic_analyzer))

    else:
        raise NotImplementedError

    # TODO: parameters like controller_sym_path_obj are absraction dependant
    # and should not be passed directly to abstraction_factory. Instead a
    # flexible structure should be created which can be filled by the
    # CAsymbolic abstraction module and supplied as a substructure. I guess the
    # idea is that an abstraction module should be 'pluggable'.
    current_abs = abstraction.abstraction_factory(
        plant_config_dict,
        T,
        num_dims,
        controller_sym_path_obj,
        sys.min_smt_sample_dist,
        plant_abstraction_type,
        controller_abstraction_type,
        opts.graph_lib,
        )
    return current_abs, sampler