コード例 #1
0
 def create_param(self, name, params, paramt, match, match_id, value0, value1):
     """Append integer-parameter to either params or paramt list"""
     if env_isfixed("OPENCL_LIBSMM_SMM_{}".format(name)):
         value_fix = getattr(self.args, name.lower())
         params.append(IntegerParameter(name, value_fix, value_fix))
     else:
         value = (
             int(match.group(match_id)) if match and match.group(match_id) else None
         )
         setattr(self, name.lower(), value)
         paramt.append(IntegerParameter(name, value0, value1))
コード例 #2
0
 def manipulator(self):
     m = ConfigurationManipulator()
     for i in range(0, 1000):
         # bias 3:1 in favor of moving right
         m.add_parameter(
             EnumParameter('move{}'.format(i), ["R", "L", "RB", "LB", "N", "LR", "LRB", "R2", "RB2", "R3", "RB3"]))
         m.add_parameter(IntegerParameter('move_duration{}'.format(i), 1, 60))
         # m.add_parameter(BooleanParameter("D"+str(i)))
     for i in range(0, 1000):
         m.add_parameter(IntegerParameter('jump_frame{}'.format(i), 0, 24000))
         m.add_parameter(IntegerParameter('jump_duration{}'.format(i), 1, 32))
     return m
コード例 #3
0
    def get_tuning_driver(self):
        from ctree.opentuner.driver import OpenTunerDriver
        from opentuner.search.manipulator import ConfigurationManipulator
        from opentuner.search.manipulator import IntegerParameter
        from opentuner.search.manipulator import PowerOfTwoParameter
        from opentuner.search.objective import MinimizeTime, MinimizeEnergy

        manip = ConfigurationManipulator()
        manip.add_parameter(PowerOfTwoParameter("rx", 1, 8))
        manip.add_parameter(PowerOfTwoParameter("ry", 1, 8))
        manip.add_parameter(IntegerParameter("cx", 8, 32))
        manip.add_parameter(IntegerParameter("cy", 8, 32))

        return OpenTunerDriver(manipulator=manip, objective=MinimizeEnergy())
コード例 #4
0
    def build_manipulator(api_config):
        """Build a ConfigurationManipulator object to be used by opentuner.

        Parameters
        ----------
        api_config : dict-like of dict-like
            Configuration of the optimization variables. See API description.

        Returns
        -------
        manipulator : ConfigurationManipulator
            Some over complexified class required by opentuner to run.
        """
        manipulator = ConfigurationManipulator()

        for pname in api_config:
            ptype = api_config[pname]["type"]
            pspace = api_config[pname].get("space", None)
            pmin, pmax = api_config[pname].get("range", (None, None))

            if ptype == "real":
                if pspace in ("linear", "logit"):
                    ot_param = FloatParameter(pname, pmin, pmax)
                elif pspace in ("log", "bilog"):
                    LogFloatParameter_ = ClippedParam(LogFloatParameter)
                    ot_param = LogFloatParameter_(pname, pmin, pmax)
                else:
                    assert False, "unsupported param space = %s" % pspace
            elif ptype == "int":
                if pspace in ("linear", "logit"):
                    ot_param = IntegerParameter(pname, pmin, pmax)
                elif pspace in ("log", "bilog"):
                    ot_param = LogIntegerParameter(pname, pmin, pmax)
                else:
                    assert False, "unsupported param space = %s" % pspace
            elif ptype == "bool":
                # The actual bool parameter seems not to work in Py3 :(
                ot_param = IntegerParameter(pname, 0, 1)
            elif ptype in ("cat", "ordinal"):
                # Treat ordinal and categorical variables the same for now.
                assert "values" in api_config[pname]
                pvalues = api_config[pname]["values"]
                ot_param = EnumParameter(pname, pvalues)
            else:
                assert False, "type=%s/space=%s not handled in opentuner yet" % (
                    ptype, pspace)
            manipulator.add_parameter(ot_param)
        return manipulator
コード例 #5
0
def main():
    parser = argparse.ArgumentParser(parents=opentuner.argparsers())
    args = parser.parse_args()
    manipulator = ConfigurationManipulator()
    manipulator.add_parameter(IntegerParameter('x', -200, 200))
    interface = DefaultMeasurementInterface(args=args,
                                            manipulator=manipulator,
                                            project_name='examples',
                                            program_name='api_test',
                                            program_version='0.1')
    api = TuningRunManager(interface, args)
    for x in xrange(500):
        desired_result = api.get_next_desired_result()
        if desired_result is None:
            # The search space for this example is very small, so sometimes
            # the techniques have trouble finding a config that hasn't already
            # been tested.  Change this to a continue to make it try again.
            break
        cfg = desired_result.configuration.data
        result = Result(time=test_func(cfg))
        api.report_result(desired_result, result)

    best_cfg = api.get_best_configuration()
    api.finish()
    print 'best x found was', best_cfg['x']
コード例 #6
0
 def solve(self, job):
     logging.debug('Starting opentuner')
     failed_jobs_threshold = self.jobs_limit * _FAILED_JOBS_COEF
     manipulator = ConfigurationManipulator()
     for var in job.optimization_job.task_variables:
         if var.HasField('continuous_variable'):
             cont_var = var.continuous_variable
             param = FloatParameter(var.name, cont_var.l, cont_var.r)
         else:
             int_var = var.integer_variable
             param = IntegerParameter(var.name, int_var.l, int_var.r)
         manipulator.add_parameter(param)
     parser = argparse.ArgumentParser(parents=opentuner.argparsers())
     args = parser.parse_args([])
     args.parallelism = 4
     args.no_dups = True
     interface = DefaultMeasurementInterface(args=args,
                                             manipulator=manipulator,
                                             project_name=job.job_id)
     api = TuningRunManager(interface, args)
     jobs = []
     current_value = None
     failed_jobs = 0
     while failed_jobs < failed_jobs_threshold and not self._check_for_termination(
             job):
         remaining_jobs = []
         for job_id, desired_result in jobs:
             res = self._get_evaluation_job_result(job_id)
             if res is not None:
                 if current_value is None or current_value > res + _THRESHOLD_EPS:
                     failed_jobs = 0
                 else:
                     failed_jobs += 1
                 result = Result(time=res)
                 api.report_result(desired_result, result)
             else:
                 remaining_jobs.append((job_id, desired_result))
         jobs = remaining_jobs
         while len(jobs) < self.jobs_limit:
             desired_result = api.get_next_desired_result()
             if desired_result is None:
                 break
             job_id = self._start_evaluation_job(
                 job, desired_result.configuration.data)
             if job_id is None:
                 api.report_result(desired_result, Result(time=math.inf))
             else:
                 jobs.append((job_id, desired_result))
         if not jobs:
             break
         r = api.get_best_result()
         if r is not None:
             current_value = r.time
             logging.debug('Opentuner current state: %s %s', r.time,
                           api.get_best_configuration())
         time.sleep(5)
     res = api.get_best_result().time
     vars = api.get_best_configuration()
     api.finish()
     return res, vars
コード例 #7
0
    def test_bruteforce_driver_2d(self):
        from ctree.tune import (
            BruteForceTuningDriver,
            IntegerParameter,
            MinimizeTime,
        )

        params = [
            IntegerParameter("foo", 0, 10),
            IntegerParameter("bar", 0, 10),
        ]
        driver = BruteForceTuningDriver(params, MinimizeTime())

        unsearched = set(range(0, 100))
        for config in islice(driver.configs, 100):
            entry = config["foo"] * 10 + config["bar"]
            unsearched.remove(entry)
            driver.report(time=0.4)
        self.assertSetEqual(unsearched, set())
コード例 #8
0
	def manipulator(self):
		'''
		Define the search space by creating a ConfigurationManipulator
		'''
		manipulator = ConfigurationManipulator()
		if self.args.window is None:
			manipulator.add_parameter(IntegerParameter('window', 1000, 5000))
		if self.args.interval is None:
			manipulator.add_parameter(IntegerParameter('interval', 2000, 10000))
		if self.args.sketch_size is None:
			manipulator.add_parameter(IntegerParameter('sketch-size', 1000, 5000))
		if self.args.k_hops is None:
			manipulator.add_parameter(IntegerParameter('k-hops', 1, 5))
		if self.args.chunk_size is None:
			manipulator.add_parameter(IntegerParameter('chunk-size', 5, 20))
		if self.args.lambda_param is None:
			manipulator.add_parameter(FloatParameter('lambda-param', 0.0, 1.0))
		# manipulator.add_parameter(EnumParameter('threshold-metric', ['mean', 'max']))
		# manipulator.add_parameter(FloatParameter('num-stds', 3.5, 6.0))
		return manipulator
コード例 #9
0
    def test_bruteforce_driver_2d_parabola(self):
        from ctree.tune import (
            BruteForceTuningDriver,
            IntegerParameter,
            MinimizeTime,
        )

        params = [
            IntegerParameter("x", 0, 10),
            IntegerParameter("y", 0, 10),
        ]
        driver = BruteForceTuningDriver(params, MinimizeTime())

        for config in islice(driver.configs, 100):
            # report height on inverted paraboloid with global min at (3,4)
            x, y = config["x"], config["y"]
            z = (x-3)**2 + (y-4)**2 + 1
            driver.report(time=z)

        for config in islice(driver.configs, 10):
            self.assertEqual((config["x"], config["y"]), (3, 4))
コード例 #10
0
ファイル: spark_tuner.py プロジェクト: umayrh/sparktuner
    def manipulator(self):
        """
        Defines the search space across configuration parameters
        """
        manipulator = ConfigurationManipulator()

        for flag, param in self.ranged_param_dict.items():
            log.info("Adding flag: " + str(flag) + ", " + str(type(param)))
            if isinstance(param, SparkIntType):
                tuner_param = IntegerParameter(
                    flag,
                    param.get_range_start(),
                    param.get_range_end())
            elif isinstance(param, SparkMemoryType):
                tuner_param = ScaledIntegerParameter(
                    flag,
                    param.get_range_start(),
                    param.get_range_end(),
                    param.get_scale())
            elif isinstance(param, SparkBooleanType):
                tuner_param = BooleanParameter(flag)
            else:
                raise SparkTunerConfigError(
                    ValueError, "Invalid type for ConfigurationManipulator")
            log.info("Added config: " + str(type(tuner_param)) +
                     ": legal range " + str(tuner_param.legal_range(None)) +
                     ", search space size " +
                     str(tuner_param.search_space_size()))
            manipulator.add_parameter(tuner_param)
        return manipulator
コード例 #11
0
def create_test_tuning_run(db):
    parser = argparse.ArgumentParser(parents=opentuner.argparsers())
    args = parser.parse_args()
    args.database = db
    manipulator = ConfigurationManipulator()
    manipulator.add_parameter(IntegerParameter('x', -200, 200))
    interface = DefaultMeasurementInterface(args=args,
                                            manipulator=manipulator,
                                            project_name='examples',
                                            program_name='api_test',
                                            program_version='0.1')
    api = TuningRunManager(interface, args)
    return api
コード例 #12
0
 def manipulator(self):
     manipulator = ConfigurationManipulator()
     manipulator.add_parameter(IntegerParameter('pixeldiff_similarity_cutoff', 20, 50))
     manipulator.add_parameter(IntegerParameter('min_max_colorful_cutoff', 5, 20))
     manipulator.add_parameter(IntegerParameter('filter_grayscale_cutoff', 170, 215))
     manipulator.add_parameter(IntegerParameter('black_and_white_grayscale_cutoff', 170, 215))
     manipulator.add_parameter(IntegerParameter('count_around_delete_cutoff', 2, 4))
     manipulator.add_parameter(IntegerParameter('count_around_add_cutoff', 2, 5))
     manipulator.add_parameter(IntegerParameter('conway_many_count', 0, 5))
     manipulator.add_parameter(BooleanParameter('overlay'))
     return manipulator
コード例 #13
0
    def build_search_space(self):
        """
        Set up search space via ConfigurationManipulator, which is responsible for choosing configurations across runs,
        where a configuration is a particular assignment of the parameters. 

        Tightly coupled with agent/system representations used in src.
        
        Repeating from above:
        *initial* search space 
        - parameter per action (candidate index column in index, where candidate index column is one of the query columns) 
          per query
        - see commit 8f94c4b

        *updated* search space
        - parameter per action (same, but here candidate index column is not one of query columns but any of columns in query table)
          per allowed index / indexing decision

         so, at risk of redundancy, an "action" refers to the particular assignment of a parameter, which is 
         an integer indicating noop or a column for a candidate index column 
         
        """

        self.logger.info('Building OpenTuner search space...')

        self.idx_2_idx_cols = {
        }  # store candidate index columns (OpenTuner operates on this) with candidate index (system operates on this)
        self.idx_2_tbl = {}

        manipulator = ConfigurationManipulator()

        for tbl in self.tbls:
            n_cols_per_tbl = len(tpch_table_columns[tbl])

            for candidate_idx in range(self.n_idxs_per_tbl):
                idx_id = "tbl_{}_idx_{}".format(tbl, candidate_idx)
                idx_col_ids = []

                for candidate_idx_col in range(self.n_cols_per_idx):
                    idx_col_id = idx_id + "_idx_col_{}".format(
                        candidate_idx_col)
                    idx_col_ids.append(idx_col_id)

                    manipulator.add_parameter(
                        IntegerParameter(idx_col_id, 0, n_cols_per_tbl))

                self.idx_2_idx_cols[idx_id] = idx_col_ids
                self.idx_2_tbl[idx_id] = tbl

        self.logger.info("... actions are: {}".format(self.idx_2_idx_cols))
        return manipulator
コード例 #14
0
    def test_bruteforce_driver_1d(self):
        from ctree.tune import (
            BruteForceTuningDriver,
            IntegerParameter,
            MinimizeTime,
        )

        objective = MinimizeTime()
        params = [IntegerParameter("foo", 0, 100)]
        driver = BruteForceTuningDriver(params, objective)

        unsearched = set(range(0, 100))
        for config in islice(driver.configs, 100):
            unsearched.remove(config["foo"])
            driver.report(time=0.4)
        self.assertSetEqual(unsearched, set())
コード例 #15
0
    def test_1d_config(self):
        from ctree.opentuner.driver import OpenTunerDriver
        from opentuner.search.objective import MinimizeTime
        from opentuner.search.manipulator import (
            ConfigurationManipulator,
            IntegerParameter,
        )

        cfg = ConfigurationManipulator()
        cfg.add_parameter( IntegerParameter("foo", 0, 199) )
        driver = OpenTunerDriver(manipulator=cfg, objective=MinimizeTime())

        unsearched = set(range(200))
        for cfg in islice(driver.configs, 20):
            val = cfg["foo"]
            driver.report(time=val)
            unsearched.remove(val)
        self.assertEqual(len(unsearched), 180)
コード例 #16
0
    def test_bruteforce_driver_other_params(self):
        from ctree.tune import (
            BruteForceTuningDriver,
            IntegerParameter,
            BooleanParameter,
            EnumParameter,
            MinimizeTime,
        )

        params = [
            IntegerParameter("foo", 0, 10),
            BooleanParameter("bar"),
            EnumParameter("baz", ['monty', 'python', 'rocks']),
        ]
        driver = BruteForceTuningDriver(params, MinimizeTime())

        nConfigs = 10*2*3
        configs = list(islice(driver.configs, nConfigs))
        self.assertEqual(len(configs), nConfigs)
コード例 #17
0
    def manipulator(self):
        """create the configuration manipulator, from example config"""
        upper_limit = self.program_settings['n'] + 1
        cfg = open(self.args.program_cfg_default).read()
        manipulator = ConfigurationManipulator()

        self.choice_sites = dict()

        for m in re.finditer(
                r" *([a-zA-Z0-9_-]+)[ =]+([0-9e.+-]+) *"
                r"[#] *([a-z]+).* ([0-9]+) to ([0-9]+)", cfg):
            k, v, valtype, minval, maxval = m.group(1, 2, 3, 4, 5)
            minval = float(minval)
            maxval = float(maxval)
            if upper_limit:
                maxval = min(maxval, upper_limit)
            assert valtype == 'int'
            # log.debug("param %s %f %f", k, minval, maxval)

            m1 = re.match(r'(.*)_lvl[0-9]+_rule', k)
            m2 = re.match(r'(.*)_lvl[0-9]+_cutoff', k)
            if m1:
                self.choice_sites[m1.group(1)] = int(maxval)
            elif m2:
                pass
            elif k == 'worker_threads':
                manipulator.add_parameter(IntegerParameter(k, 1, 16))
            elif k == 'distributedcutoff':
                pass
            elif minval == 0 and maxval < 64:
                manipulator.add_parameter(SwitchParameter(k, maxval))
            else:
                manipulator.add_parameter(
                    LogIntegerParameter(k, minval, maxval))

        for name, choices in list(self.choice_sites.items()):
            manipulator.add_parameter(
                SelectorParameter('.' + name, list(range(choices + 1)),
                                  old_div(upper_limit, choices)))

        self.manipulator = manipulator
        return manipulator
コード例 #18
0
#!/usr/bin/env python
#
from opentuner import ConfigurationManipulator
from opentuner.search.manipulator import PowerOfTwoParameter, IntegerParameter

mdriver_manipulator = ConfigurationManipulator()

"""
See opentuner/search/manipulator.py for more parameter types,
like IntegerParameter, EnumParameter, etc.

TODO(project3): Implement the parameters of your allocator. Once
you have at least one other parameters, feel free to remove ALIGNMENT.
"""
# mdriver_manipulator.add_parameter(PowerOfTwoParameter('ALIGNMENT', 8, 8))
mdriver_manipulator.add_parameter(IntegerParameter('NUMBUCKETS', 2, 128))
mdriver_manipulator.add_parameter(IntegerParameter('BASESIZE', 2, 1000))
コード例 #19
0
    def manipulator(self):
        # FIXME: should some of these be expressed as booleans or switch parameters?
        # FIXME: how to express P and Q, given PxQ=nprocs, with nprocs being fixed?
        # FIXME: how to express logscaled parameter with a particular base?
        manipulator = ConfigurationManipulator()
        manipulator.add_parameter(IntegerParameter("blocksize", 1, 64))
        manipulator.add_parameter(IntegerParameter("row_or_colmajor_pmapping", 0, 1))
        manipulator.add_parameter(IntegerParameter("pfact", 0, 2))
        manipulator.add_parameter(IntegerParameter("nbmin", 1, 4))
        manipulator.add_parameter(IntegerParameter("ndiv", 2, 2))
        manipulator.add_parameter(IntegerParameter("rfact", 0, 4))
        manipulator.add_parameter(IntegerParameter("bcast", 0, 5))
        manipulator.add_parameter(IntegerParameter("depth", 0, 4))
        manipulator.add_parameter(IntegerParameter("swap", 0, 2))
        manipulator.add_parameter(IntegerParameter("swapping_threshold", 64, 128))
        manipulator.add_parameter(IntegerParameter("L1_transposed", 0, 1))
        manipulator.add_parameter(IntegerParameter("U_transposed", 0, 1))
        manipulator.add_parameter(IntegerParameter("mem_alignment", 4, 16))

        return manipulator
コード例 #20
0
ファイル: opentuner_params.py プロジェクト: Detry322/dlmalloc
#!/usr/bin/env python
#
from opentuner import ConfigurationManipulator
from opentuner.search.manipulator import PowerOfTwoParameter
from opentuner.search.manipulator import IntegerParameter
mdriver_manipulator = ConfigurationManipulator()
"""
See opentuner/search/manipulator.py for more parameter types,
like IntegerParameter, EnumParameter, etc.

TODO(project3): Implement the parameters of your allocator. Once
you have at least one other parameters, feel free to remove ALIGNMENT.
"""
#mdriver_manipulator.add_parameter(IntegerParameter('SMALL_BIN_SEARCH_MAX', 0, 32))
mdriver_manipulator.add_parameter(
    IntegerParameter('LARGE_BIN_SEARCH_MAX', 0, 32))
mdriver_manipulator.add_parameter(IntegerParameter('EXTENSION_SIZE', 8, 2000))
#mdriver_manipulator.add_parameter(IntegerParameter('INITIAL_CHUNK_SIZE', 0, 40000))
コード例 #21
0
ファイル: sjparameters.py プロジェクト: yujincheng/streamjit
            if p is not victim:
                p.set_value(config,
                            p.get_value(config) + v / (len(nonzeroes) - 1))

    def zeroes(self, config):
        return [p for p in self.sub_parameters() if p.get_value(config) == 0]

    def nonzeroes(self, config):
        return [p for p in self.sub_parameters() if p.get_value(config) > 0]

    def update_value_for_json(self, config):
        for (i, p) in zip(xrange(self.count), self.sub_parameters()):
            self.values[i] = p.get_value(config)

    def json_replacement(self):
        return {
            "name": self.name,
            "values": self.values,
            "class": self.javaClass
        }


if __name__ == '__main__':
    ip = IntegerParameter("suman", 2, 7)
    sjip = sjIntegerParameter("ss", 3, 56, 45)
    sjsw = sjSwitchParameter(
        'sjswtch', 'java.lang.Integer', ['AAA', 'BBB', 'CCC', 'DDD'], 2,
        'edu.mit.streamjit.impl.common.Configuration$SwitchParameter')
    print sjsw.getName()
    print sjsw.getUniverse()
    print sjsw.getValue()