Ejemplo n.º 1
0
def define_result_parser(simulator_config=None):
    """
    This function creates a ScheduleParser instance enabled for parsing AccaSim schedule files.

    The objects produced by this function are used for post-processing simulation results.

    :return: A ScheduleParser object
    """
    try:
        if simulator_config is not None:
            _schedule_output = load_config(simulator_config)['schedule_output']
        else:
            # If no simulation config is supplied, DEFAULT_SIMULATION is used
            _schedule_output = DEFAULT_SIMULATION['SCHEDULE_OUTPUT']
        # _separators = _schedule_output['separators']
        _format = _schedule_output['format']
        _attributes = _schedule_output['attributes']
    except KeyError as e:
        print(
            'Schedule output format not identified. Please check the simulator configuration file for the key \'schedule_output\'.')
        exit()

    for _attr_name, _data_type in _attributes.items():
        _format = _format.replace('{' + _attr_name + '}', type_regexp(_data_type[-1]).format(_attr_name))
    return ScheduleParser(_format, [])
Ejemplo n.º 2
0
    def generate_enviroment(self, config_path):
        """

        Generated the syntethic system from the config file

        :param config_path: Path the config file

        :return: resource manager object.

        """
        config = load_config(config_path)
        equiv = config.pop('equivalence', {})
        start_time = config.pop('start_time', 0)
        resources = Resources(**config)
        return ResourceManager(resources), equiv, start_time
Ejemplo n.º 3
0
    def define_default_constants(self, config_filepath, **kwargs):
        """

        Defines the default constants of the simulator, and update if the user gives new values.

        :param config_filepath: Path to the config file in json format

        """
        config = DEFAULT_SIMULATION
        for k, v in config.items():
            if k not in kwargs:
                kwargs[k] = v
        if config_filepath:
            for k, v in load_config(config_filepath).items():
                kwargs[k] = v
        kwargs = self.define_filepaths(**kwargs)
        self.constants.load_constants(kwargs)
Ejemplo n.º 4
0
    def _set_resources(self, resources_obj, sys_config):
        """

        :param resources_obj:
        :param sys_config:
        :return:
        """
        if resources_obj:
            obj_assertion(
                resources_obj, Resources,
                'Received {} type as system resource. resources_class type expected.',
                [resources_obj.__class__.__name__])
            return resources_obj
        elif sys_config:
            config = load_config(sys_config)
            resources_obj = Resources(node_prefix='', **config)
            return resources_obj
        else:
            raise Exception(
                'A resources object or the path to the system config must be given.'
            )
Ejemplo n.º 5
0
    def __init__(self,
                 workload,
                 sys_config,
                 performance,
                 request_limits,
                 reader_class=None,
                 resources_target=None,
                 user_behavior=None,
                 walltime_calculation=None,
                 non_processing_resources=['mem'],
                 **kwargs):
        """

        :param workload:
        :param sys_config:
        :param performance:
        :param request_limits:
        :param reader_class:
        :param resources_target:
        :param user_behavior:
        :param walltime_calculation:
        :param non_processing_resources:
        :param kwargs:
        """
        self.walltime_calculation = walltime_calculation
        show_msg = False
        save_parameters = False
        job_parameters = {}
        arrive_parameters = {}
        job_gen_optional = {}
        arrive_gen_optional = {}

        config = load_config(sys_config)

        resources = self._set_resources(None, sys_config)
        equivalence = config.pop('equivalence', {})
        start_time = config.pop('start_time', int(time.time()))

        if not reader_class:
            reader_class = self._default_simple_swf_reader(
                workload, start_time, equivalence, resources)

        if not hasattr(reader_class, "next"):
            raise Exception('The reader_class must implement the next method.')

        if not resources_target:
            resources_target = self._set_resources(None, sys_config)

        total_jobs, _submissiont_times, _job_total_opers, serial_prob, nodes_parallel_prob, hour_prob, day_prob, month_prob, max_opers_serial, max_parallel_duration = self._initialize(
            reader_class, performance, resources, non_processing_resources)
        if 'show_msg' in kwargs:
            show_msg = kwargs['show_msg']

        if 'job_parameters' in kwargs:
            job_parameters = kwargs['job_parameters']

        if 'job_distributions' in kwargs:
            job_gen_optional['distributions'] = kwargs['job_distributions']

        if 'arrive_parameters' in kwargs:
            arrive_parameters = kwargs['arrive_parameters']

        if 'save_parameters' in kwargs:
            save_parameters = kwargs['save_parameters']

        parallel_prob = 1 - serial_prob

        self.arrive_generator = ArriveGenerator(start_time, hour_prob,
                                                day_prob, month_prob,
                                                arrive_parameters, total_jobs)

        if show_msg:
            print('Arrive Generator samples...')
        self.arrive_generator.add_sample(_submissiont_times,
                                         save=save_parameters)
        if show_msg:
            print('Arrive Generator samples... Loaded')

        total_nodes = sum([d['nodes'] for d in resources.definition])
        total_resources = resources.total_resources()
        resource_types = list(resources.total_resources().keys())
        min_request, max_request = request_limits['min'], request_limits['max']

        self.job_generator = JobGenerator(
            total_nodes, resource_types, serial_prob, parallel_prob,
            nodes_parallel_prob, performance, min_request, max_request,
            job_parameters, max_opers_serial, max_parallel_duration,
            **job_gen_optional)

        if show_msg:
            print('Job Generator samples...')
        self.job_generator.add_sample(_job_total_opers, save=save_parameters)
        if show_msg:
            print('Job Generator samples... Loaded')
Ejemplo n.º 6
0
import socket, json
import os
import argparse
from accasim.utils.misc import CONSTANT, load_config, system_status

# A simple launch script to contact the watcher demon related to a running test session, and obtain information about
# it. By default the connection is launched on localhost, but the user can choose an IP if the tests are running
# on a different machine.
if __name__ == '__main__':
    CONFIG_FOLDER = 'config/'
    ESSENTIALS_FILENAME = 'essentials.config'
    const = CONSTANT()
    const.load_constants(load_config(os.path.join(CONFIG_FOLDER, ESSENTIALS_FILENAME)))

    parser = argparse.ArgumentParser(description="Client For HPC Simulator Watcher Daemon")
    parser.add_argument("-usage", action="store_true", dest="usage", help="Request current virtual resource usage.")
    parser.add_argument("-progress", action="store_true", dest="progress", help="Request current local progress.")
    parser.add_argument("-all", action="store_true", dest="all", help="Request all previous data.")
    parser.add_argument("-ip", action="store", dest="hostip", default="localhost", type=str, help="IP of server machine.")

    args = parser.parse_args()

    # Remember that commands and responses must not be longer than MAX_LENGTH!
    command = ''
    if args.usage:
        command = 'usage'
    elif args.progress:
        command = 'progress'
    elif args.all:
        command = 'all'
    else: