Beispiel #1
0
    def __init__(self, controller_path, num_dims, plant_config_dict, delta_t,
                 controller_path_dir_path, controller_object_str, path,
                 plant_pvt_init_data):
        self.num_dims = num_dims
        self.controller_path = controller_path
        self.controller_object_str = controller_object_str
        self.plant_pvt_init_data = plant_pvt_init_data
        self.plant_config_dict = plant_config_dict

        self.delta_t = delta_t
        self.controller_path_dir_path = controller_path_dir_path
        self.path = path

        self.sanity_check = U.assert_no_Nones

        try:
            sim_type = self.plant_config_dict['plant_description']
            if sim_type == 'python':
                logger.info('creating Native Python simulator')

                # get the file path

                python_file_path = plant_config_dict['plant_path']
                #(module_name, file_ext) = python_file_path.split('.')
                (module_name,
                 file_ext) = fp.split_filename_ext(python_file_path)
                if file_ext != 'py':
                    raise err.Fatal(
                        'Python file extension py expected, found: {}'.format(
                            file_ext))
                module_path = fp.construct_path(python_file_path, self.path)
                if fp.validate_file_names([module_path]):

                    sim_module = imp.load_source(module_name, module_path)
                    self.sim_obj = sim_module.SIM(self.plant_pvt_init_data)
                    self.sim = self.sim_obj.sim

                    self.stateDict = {}

                    # inputs and params are unhandled...

                    self.inputs = None
                    self.params = None

                    # # currently plot in matlab itself

                    # self.plot = None
                else:
                    raise err.FileNotFound('file does not exist: ' +
                                           python_file_path)
            else:
                raise err.Fatal('unknown sim type : {}'.format(sim_type))

        except KeyError, key:
            raise err.Fatal(
                'expected abstraction parameter undefined: {}'.format(key))
Beispiel #2
0
def simulator_factory(config_dict,
                      benchmark_os_path,
                      plt,
                      plant_pvt_init_data,
                      parallel=False,
                      test_params=None,
                      sim_args=None):

    # ##!!##logger.debug('requested simulator creation')

    sim_type = config_dict['plant_description']
    if sim_type == 'matlab':
        logger.info('creating matlab simulator')

        # get the m_file's path

        m_file_path = config_dict['plant_path']
        abs_m_file_path = fp.construct_path(m_file_path, benchmark_os_path)
        if fp.validate_file_names([abs_m_file_path]):

            # return MatlabSim(m_file_path, benchmark_os_path, parallel)

            return MEngPy(m_file_path, benchmark_os_path, parallel, sim_args)
        else:
            raise err.FileNotFound('file does not exist: ' + m_file_path)
    elif sim_type == 'simulink':
        return SimulinkSim()
    elif sim_type == 'python':
        logger.info('creating Native Python simulator')

        # get the file path

        python_file_path = config_dict['plant_path']
        #(module_name, file_ext) = python_file_path.split('.')
        (module_name, file_ext) = fp.split_filename_ext(python_file_path)
        if file_ext != 'py':
            raise err.Fatal(
                'Python file extension py expected, found: {}'.format(
                    file_ext))
        module_path = fp.construct_path(python_file_path, benchmark_os_path)
        if fp.validate_file_names([module_path]):
            return NativeSim(module_name, module_path, plt,
                             plant_pvt_init_data, parallel)
        else:
            raise err.FileNotFound('file does not exist: ' + python_file_path)
    elif sim_type == 'test':
        return TestSim(test_params)
    else:
        raise err.Fatal('unknown sim type : {}'.format(sim_type))
Beispiel #3
0
def simulator_factory(
        config_dict,
        benchmark_os_path,
        plt,
        plant_pvt_init_data,
        parallel=False,
        test_params=None,
        sim_args=None
        ):

    # ##!!##logger.debug('requested simulator creation')

    sim_type = config_dict['plant_description']
    if sim_type == 'matlab':
        logger.info('creating matlab simulator')

        # get the m_file's path

        m_file_path = config_dict['plant_path']
        abs_m_file_path = fp.construct_path(m_file_path, benchmark_os_path)
        if fp.validate_file_names([abs_m_file_path]):

            # return MatlabSim(m_file_path, benchmark_os_path, parallel)

            return MEngPy(m_file_path, benchmark_os_path, parallel, sim_args)
        else:
            raise err.FileNotFound('file does not exist: ' + m_file_path)
    elif sim_type == 'simulink':
        return SimulinkSim()
    elif sim_type == 'python':
        logger.info('creating Native Python simulator')

        # get the file path

        python_file_path = config_dict['plant_path']
        #(module_name, file_ext) = python_file_path.split('.')
        (module_name, file_ext) = fp.split_filename_ext(python_file_path)
        if file_ext != 'py':
            raise err.Fatal('Python file extension py expected, found: {}'.format(file_ext))
        module_path = fp.construct_path(python_file_path, benchmark_os_path)
        if fp.validate_file_names([module_path]):
            return NativeSim(module_name, module_path, plt, plant_pvt_init_data, parallel)
        else:
            raise err.FileNotFound('file does not exist: ' + python_file_path)
    elif sim_type == 'test':
        return TestSim(test_params)
    else:
        raise err.Fatal('unknown sim type : {}'.format(sim_type))
Beispiel #4
0
def parse(file_path):
    test_des_file = file_path
    path = fp.get_abs_base_path(file_path)

    test_dir = fp.get_abs_base_path(test_des_file)
    SYS.path.append(test_dir)

    sut = imp.load_source('test_des', test_des_file)

    try:
        assert (len(sut.initial_set) == 2)
        assert (len(sut.error_set) == 2)
        assert (len(sut.ci) == 2)
        assert (len(sut.pi) == 2)

        assert (len(sut.ci[0]) == len(sut.ci[1]))
        assert (len(sut.pi[0]) == len(sut.pi[1]))

        assert (len(sut.initial_set[0]) == len(sut.initial_set[1]))
        assert (len(sut.error_set[0]) == len(sut.error_set[1]))

        assert (len(sut.initial_set[0]) == len(sut.error_set[0]))

        assert (len(sut.initial_set[0]) == len(sut.grid_eps))

        num_dims = NumDims(
            si=len(sut.initial_controller_integer_state),
            sf=len(sut.initial_controller_float_state),
            s=len(sut.initial_controller_integer_state) +
            len(sut.initial_controller_float_state),
            x=len(sut.initial_set[0]),
            u=sut.num_control_inputs,
            ci=len(sut.ci[0]),
            pi=len(sut.pi[0]),
            d=len(sut.initial_discrete_state),
            pvt=0,
        )

        if not hasattr(sut, 'ci_grid_eps') or len(sut.ci_grid_eps) == 0:
            sut.ci_grid_eps = []

#         if hasattr(sut, 'ci_grid_eps'):
#             if len(sut.ci_grid_eps) == 0:
#                 sut.ci_grid_eps = None
#         else:
#             sut.ci_grid_eps = None

        if not hasattr(sut, 'pi_grid_eps') or len(sut.pi_grid_eps) == 0:
            sut.pi_grid_eps = []

#         if hasattr(sut, 'pi_grid_eps'):
#             if len(sut.pi_grid_eps) == 0:
#                 sut.pi_grid_eps = None
#         else:
#             sut.pi_grid_eps = None

        if num_dims.ci == 0:
            ci = None
        else:
            ci = cns.IntervalCons(np.array(sut.ci[0]), np.array(sut.ci[1]))

        if num_dims.pi == 0:
            pi = None
        else:
            pi = cns.IntervalCons(np.array(sut.pi[0]), np.array(sut.pi[1]))

        assert ((pi is None and sut.pi_grid_eps == [])
                or (pi is not None and sut.pi_grid_eps != []))
        assert ((ci is None and sut.ci_grid_eps == [])
                or (ci is not None and sut.ci_grid_eps != []))

        if pi is not None:
            assert (len(sut.pi[0]) == len(sut.pi_grid_eps))

        if ci is not None:
            assert (len(sut.ci[0]) == len(sut.ci_grid_eps))

        plant_config_dict = {
            'plant_description': sut.plant_description,
            'plant_path': sut.plant_path,
            #'refinement_factor': sut.refinement_factor,
            'eps': np.array(sut.grid_eps, dtype=float),
            #'pi_eps': np.array(sut.pi_grid_eps, dtype=float),
            'num_samples': int(sut.num_samples),
            'delta_t': float(sut.delta_t),
            #'type': 'string',
            'type': 'value',
        }
        #print(plant_config_dict)
        #for k, d in plant_config_dict.iteritems():
        #    plant_config_dict[k] = str(d)

        # TODO: fix the list hack, once the controller ifc matures

        init_cons = cns.IntervalCons(np.array(sut.initial_set[0]),
                                     np.array(sut.initial_set[1]))

        init_cons_list = [init_cons]

        final_cons = cns.IntervalCons(np.array(sut.error_set[0]),
                                      np.array(sut.error_set[1]))
        T = sut.T
        delta_t = sut.delta_t

        if sut.controller_path is not None:
            controller_object_str = fp.split_filename_ext(
                sut.controller_path)[0]
            controller_path_dir_path = fp.construct_path(
                sut.controller_path_dir_path, path)
        else:
            controller_object_str = None
            controller_path_dir_path = None

        initial_discrete_state = sut.initial_discrete_state
        initial_controller_state = (sut.initial_controller_integer_state +
                                    sut.initial_controller_float_state)
        MAX_ITER = sut.MAX_ITER

        num_segments = int(np.ceil(T / delta_t))

        controller_path = sut.controller_path
        plant_pvt_init_data = sut.plant_pvt_init_data

        sys = System(controller_path, num_dims, plant_config_dict, delta_t,
                     controller_path_dir_path, controller_object_str, path,
                     plant_pvt_init_data, sut.min_smt_sample_dist,
                     sut.ci_grid_eps, sut.pi_grid_eps)
        prop = Property(T, init_cons_list, init_cons, final_cons, ci, pi,
                        initial_discrete_state, initial_controller_state,
                        MAX_ITER, num_segments)

        #num_sim_samples = sut.num_sim_samples
        #METHOD = sut.METHOD
        #symbolic_analyzer = sut.symbolic_analyzer
        #plot = sut.plot
        #MODE = sut.MODE
        #opts = Options(plot, MODE, num_sim_samples, METHOD, symbolic_analyzer)
    except AttributeError as e:
        raise MissingSystemDefError(e)
    print('system loaded...')
    return sys, prop
Beispiel #5
0
def parse(file_path):
    test_des_file = file_path
    path = fp.get_abs_base_path(file_path)

    test_dir = fp.get_abs_base_path(test_des_file)
    SYS.path.append(test_dir)

    sut = imp.load_source('test_des', test_des_file)

    try:
        assert(len(sut.initial_set) == 2)
        assert(len(sut.error_set) == 2)
        assert(len(sut.ci) == 2)
        assert(len(sut.pi) == 2)

        assert(len(sut.ci[0]) == len(sut.ci[1]))
        assert(len(sut.pi[0]) == len(sut.pi[1]))

        assert(len(sut.initial_set[0]) == len(sut.initial_set[1]))
        assert(len(sut.error_set[0]) == len(sut.error_set[1]))

        assert(len(sut.initial_set[0]) == len(sut.error_set[0]))

        assert(len(sut.initial_set[0]) == len(sut.grid_eps))

        num_dims = NumDims(
            si=len(sut.initial_controller_integer_state),
            sf=len(sut.initial_controller_float_state),
            s=len(sut.initial_controller_integer_state)+len(sut.initial_controller_float_state),
            x=len(sut.initial_set[0]),
            u=sut.num_control_inputs,
            ci=len(sut.ci[0]),
            pi=len(sut.pi[0]),
            d=len(sut.initial_discrete_state),
            pvt=0,
            )

        if not hasattr(sut, 'ci_grid_eps') or len(sut.ci_grid_eps) == 0:
            sut.ci_grid_eps = []

#         if hasattr(sut, 'ci_grid_eps'):
#             if len(sut.ci_grid_eps) == 0:
#                 sut.ci_grid_eps = None
#         else:
#             sut.ci_grid_eps = None

        if not hasattr(sut, 'pi_grid_eps') or len(sut.pi_grid_eps) == 0:
            sut.pi_grid_eps = []

#         if hasattr(sut, 'pi_grid_eps'):
#             if len(sut.pi_grid_eps) == 0:
#                 sut.pi_grid_eps = None
#         else:
#             sut.pi_grid_eps = None

        if num_dims.ci == 0:
            ci = None
        else:
            ci = cns.IntervalCons(np.array(sut.ci[0]), np.array(sut.ci[1]))

        if num_dims.pi == 0:
            pi = None
        else:
            pi = cns.IntervalCons(np.array(sut.pi[0]), np.array(sut.pi[1]))

        assert((pi is None and sut.pi_grid_eps == []) or
               (pi is not None and sut.pi_grid_eps != []))
        assert((ci is None and sut.ci_grid_eps == []) or
               (ci is not None and sut.ci_grid_eps != []))

        if pi is not None:
            assert(len(sut.pi[0]) == len(sut.pi_grid_eps))

        if ci is not None:
            assert(len(sut.ci[0]) == len(sut.ci_grid_eps))

        plant_config_dict = {'plant_description': sut.plant_description,
                             'plant_path': sut.plant_path,
                             #'refinement_factor': sut.refinement_factor,
                             'eps': np.array(sut.grid_eps, dtype=float),
                             #'pi_eps': np.array(sut.pi_grid_eps, dtype=float),
                             'num_samples': int(sut.num_samples),
                             'delta_t': float(sut.delta_t),
                             #'type': 'string',
                             'type': 'value',
                             }
        #print(plant_config_dict)
        #for k, d in plant_config_dict.iteritems():
        #    plant_config_dict[k] = str(d)

        # TODO: fix the list hack, once the controller ifc matures

        init_cons = cns.IntervalCons(np.array(sut.initial_set[0]),
                                     np.array(sut.initial_set[1]))

        init_cons_list = [init_cons]

        final_cons = cns.IntervalCons(np.array(sut.error_set[0]),
                                      np.array(sut.error_set[1]))
        T = sut.T
        delta_t = sut.delta_t

        if sut.controller_path is not None:
            controller_object_str = fp.split_filename_ext(sut.controller_path)[0]
            controller_path_dir_path = fp.construct_path(sut.controller_path_dir_path, path)
        else:
            controller_object_str = None
            controller_path_dir_path = None

        initial_discrete_state = sut.initial_discrete_state
        initial_controller_state = (sut.initial_controller_integer_state +
                                    sut.initial_controller_float_state)
        MAX_ITER = sut.MAX_ITER

        num_segments = int(np.ceil(T / delta_t))

        controller_path = sut.controller_path
        plant_pvt_init_data = sut.plant_pvt_init_data

        sys = System(controller_path, num_dims, plant_config_dict,
                     delta_t, controller_path_dir_path,
                     controller_object_str, path, plant_pvt_init_data,
                     sut.min_smt_sample_dist, sut.ci_grid_eps,
                     sut.pi_grid_eps)
        prop = Property(T, init_cons_list, init_cons, final_cons, ci,
                        pi, initial_discrete_state, initial_controller_state,
                        MAX_ITER, num_segments)

        #num_sim_samples = sut.num_sim_samples
        #METHOD = sut.METHOD
        #symbolic_analyzer = sut.symbolic_analyzer
        #plot = sut.plot
        #MODE = sut.MODE
        #opts = Options(plot, MODE, num_sim_samples, METHOD, symbolic_analyzer)
    except AttributeError as e:
        raise MissingSystemDefError(e)
    print('system loaded...')
    return sys, prop
Beispiel #6
0
def parse_without_sanity_check(file_path):
    test_des_file = file_path
    path = fp.get_abs_base_path(file_path)

    test_dir = fp.get_abs_base_path(test_des_file)
    SYS.path.append(test_dir)

    sut = imp.load_source('test_des', test_des_file)

    plant_config_dict = {
        'plant_description': sut.plant_description,
        'plant_path': sut.plant_path,
        'refinement_factor': sut.refinement_factor,
        #  'grid_eps': sut.grid_eps,
        #  'num_samples': sut.num_samples,
        'delta_t': sut.delta_t,
        'type': 'string',
    }

    for k, d in plant_config_dict.iteritems():
        plant_config_dict[k] = str(d)

    num_dims = NumDims(
        si=len(sut.initial_controller_integer_state),
        sf=len(sut.initial_controller_float_state),
        s=len(sut.initial_controller_integer_state) +
        len(sut.initial_controller_float_state),
        x=len(sut.initial_set[0]),
        u=sut.num_control_inputs,
        ci=len(sut.ci[0]),
        pi=0,
        d=len(sut.initial_discrete_state),
        pvt=0,
    )

    if num_dims.ci == 0:
        ci = None
    else:

        ci = cns.IntervalCons(np.array(sut.ci[0]), np.array(sut.ci[1]))
    if num_dims.pi == 0:
        pi = None
    else:
        pi = cns.IntervalCons(np.array(sut.pi[0]), np.array(sut.pi[1]))

    # TODO: fix the list hack, once the controller ifc matures

    init_cons = cns.IntervalCons(np.array(sut.initial_set[0]),
                                 np.array(sut.initial_set[1]))

    init_cons_list = [init_cons]

    final_cons = cns.IntervalCons(np.array(sut.error_set[0]),
                                  np.array(sut.error_set[1]))
    T = sut.T

    if sut.controller_path is not None:
        controller_object_str = fp.split_filename_ext(sut.controller_path)[0]
        controller_path_dir_path = fp.construct_path(
            sut.controller_path_dir_path, path)
    else:
        controller_object_str = None
        controller_path_dir_path = None

    delta_t = sut.delta_t
    #try:  # enforce it for now!
    #except:
    #    controller_path_dir_path = None
    initial_discrete_state = sut.initial_discrete_state
    initial_controller_state = sut.initial_controller_integer_state \
                             + sut.initial_controller_float_state
    MAX_ITER = sut.MAX_ITER
    #try:  # enforce it for now!
    #except:
    #    None
    num_segments = int(np.ceil(T / delta_t))

    controller_path = sut.controller_path
    plant_pvt_init_data = sut.plant_pvt_init_data

    sys = System(controller_path, num_dims, plant_config_dict, delta_t,
                 controller_path_dir_path, controller_object_str, path,
                 plant_pvt_init_data)
    prop = Property(T, init_cons_list, init_cons, final_cons, ci, pi,
                    initial_discrete_state, initial_controller_state, MAX_ITER,
                    num_segments)

    #num_sim_samples = sut.num_sim_samples
    #METHOD = sut.METHOD
    #symbolic_analyzer = sut.symbolic_analyzer
    #plot = sut.plot
    #MODE = sut.MODE
    #opts = Options(plot, MODE, num_sim_samples, METHOD, symbolic_analyzer)
    return sys, prop