Example #1
0
    def parse_worker_command_line_arguments(self):
        """parse_worker_command_line_arguments

        Parses the command line arguments for a GPS worker.

        Returns
        -------
        arguments: dict
             A dictionary containing the parsed arguments.
        """
        parser = argparse.ArgumentParser()
        for arg in self.redis_arguments:
             parser.add_argument(*_get_aliases(arg), dest=_get_name(arg), **self.redis_arguments[arg])
        # Parse the command line arguments and convert to a dictionary
        args = vars(parser.parse_args())
        keys = list(args.keys())
        # Remove everything that is None so that we know to replace those values with scenario file arguments
        # instead.
        for arg in keys:
            if args[arg] is None:
                del args[arg]

        if helper.isFile(self.redis_defaults):
            args, _ = self.parse_file_arguments(self.redis_defaults, args)
        self._validate_redis_arguments_defined(args)
        return args 
Example #2
0
    def parse_arguments(self):
        """parse_arguments
        Parse the command line arguments, then, if provided, parse the 
        arguments in the scenario file. Then adds default values for
        paramaters without definitions. Finally, validates all argument
        definitions, checks that needed files and directories exist, and then
        checks to make sure that all required arguements received definitions.
        
        Returns
        -------
        arguments : dict
            A dictionary mapping all GPS arguments to definitions.
        skipped_lines : list of str
            A list of all non-comment lines in the scenario file that were
            skipped.
        """
        skipped_lines = []
        # First parse the command line arguments
        arguments = self.parse_command_line_arguments()
        # If a scenario file was provided, parse the arguments from it
        if 'scenario_file' in arguments:
            # If an experiment directory is specified, we will change to that directory
            experiment_dir = arguments[
                'experiment_dir'] if 'experiment_dir' in arguments else '.'
            with helper.cd(experiment_dir):
                try:
                    arguments, skipped_lines = self.parse_file_arguments(
                        arguments['scenario_file'], arguments)
                except IOError:
                    raise IOError(
                        "The scenario file '{}' could not be found from within GPS's "
                        "current working directory '{}' (which is the experiment directory, "
                        "if one was specified on the command line)."
                        "".format(arguments['scenario_file'], os.getcwd()))
        # Finally, load the default values of the redis configuration parameters
        if helper.isFile(self.redis_defaults):
            arguments, _ = self.parse_file_arguments(self.redis_defaults,
                                                     arguments)
        # Finally, load the default values of all GPS parameters (that make sense to be shared)
        arguments, _ = self.parse_file_arguments(self.defaults, arguments)
        # Check that all parameters have defintions (optional parameters not specified by the
        # user will have already been included with default values)
        self._validate_all_arguments_defined(arguments)
        # Make sure all of the files and directories can be found
        _validate_files_and_directories(arguments)
        # Make sure GPS's budget was set
        _validate_budget(arguments)

        # Save the data for later
        self.parsed_arguments = arguments

        return arguments, skipped_lines
Example #3
0
def _validate_files_and_directories(arguments):
    with helper.cd(arguments['experiment_dir']):
        files = ['pcs_file', 'instance_file']
        for filename in files:            
            if not helper.isFile(arguments[filename]):
                raise IOError("The {} '{}' could not be found within GPS's current working "
                              "directory '{}' (which is the experiment directory, if one was "
                              "specified)."
                              "".format(filename.replace('_', ' '), arguments[filename], os.getcwd()))
        directories = ['temp_dir']
        for directory in directories:            
            if not helper.isDir(arguments[directory]):
                raise IOError("The {} '{}' could not be found within GPS's current working "
                              "directory '{}' (which is the experiment directory, if one was "
                              "specified)."
                              "".format(directory.replace('_', ' '), arguments[directory], os.getcwd()))
Example #4
0
def read_output_file(outputFile):
    # Specify inf in case of error or timeout
    runtime = float('inf')
    sol = float('inf')
    res = "CRASHED"
    misc = 'The target algorithm failed to produce output in the expected format'
    if not helper.isFile(outputFile):
        misc = 'The target algorithm failed to produce any output'
    else:
        # Parse the results from the temp file
        with open(outputFile) as f:
            for line in f:
                if ("Result for SMAC:" in line
                        or "Result for ParamILS:" in line
                        or "Result for GPS:" in line
                        or "Result for Configurator:" in line):
                    results = line[line.index(":") + 1:].split(",")

                    runtime = float(results[1])
                    sol = float(results[2])

                    if ("SAT" in results[0] or "UNSAT" in results[0]
                            or "SUCCESS" in results[0]):
                        res = "SUCCESS"
                    elif ("CRASHED" in results[0]):
                        res = "CRASHED"
                    elif ("TIMEOUT" in results[0]):
                        res = "TIMEOUT"
                        runtime = float('inf')
                    else:
                        res = "CRASHED"

                    misc = results[-1].strip() + ' - ' + str(results[0])

    os.system('rm ' + outputFile + ' -f')

    return res, runtime, sol, misc