コード例 #1
0
ファイル: battery.py プロジェクト: crocs-muni/booltest
    def init_config(self):
        self.parallel_tasks = self.args.threads or 1
        self.bool_wrapper = self.args.booltest_bin
        try:
            if self.args.config:
                with open(self.args.config) as fh:
                    self.bool_config = json.load(fh)

                if not self.bool_wrapper:
                    self.bool_wrapper = jsonpath("$.wrapper", self.bool_config, True)
                if not self.args.threads:
                    self.parallel_tasks = jsonpath("$.threads", self.bool_config, True) or self.args.threads or 1

        except Exception as e:
            logger.error("Could not load the config %s" % (e,), exc_info=e)

        if not self.bool_wrapper:
            self.bool_wrapper = "\"%s\" -m booltest.booltest_main" % sys.executable
コード例 #2
0
def get_sage_python_bin(binpath=None,
                        rtt_settings_path=None,
                        rtt_config=None,
                        search_dir=None):
    if binpath is not None and os.path.exists(binpath):
        return binpath

    if rtt_settings_path or rtt_config:
        if rtt_settings_path:
            with open(rtt_settings_path, 'r') as fh:
                rtt_config = json.load(fh)

        cand = jsonpath('$.toolkit-settings.binaries.sage-python', rtt_config,
                        True)
        if cand is not None and os.path.exists(cand):
            return cand

    cand = os.getenv("SAGE_PYTHON_PATH")
    if cand is not None and os.path.exists(cand):
        return cand

    if search_dir is None and rtt_settings_path is not None:
        search_dir = os.path.dirname(rtt_settings_path)

    if search_dir:
        cand = os.path.realpath(os.path.join(search_dir, 'sage-python'))
        if os.path.exists(cand):
            if os.access(cand, os.X_OK):
                return cand
            else:
                logger.info(
                    "sage found in search-dir but it is not executable")

    sage = get_sage_bin(rtt_settings_path=rtt_settings_path,
                        rtt_config=rtt_config,
                        search_dir=search_dir)
    if not sage:
        return None

    # auto-detect
    try:
        sage_dir = os.path.dirname(os.path.realpath(sage))
        cands = [
            os.path.join(sage_dir, 'local/bin/python3'),
            os.path.join(sage_dir, 'local/bin/python'),
        ]

        for c in cands:
            if os.path.exists(c) and os.access(c, os.X_OK):
                return c

    except Exception as e:
        pass

    return None
コード例 #3
0
ファイル: battery.py プロジェクト: crocs-muni/booltest
    def print_test_res(self, res):
        for rs in res:  # type: BoolRes
            passed = (rs.pval >= self.args.alpha if rs.is_halving else not rs.rejects) if rs.ret_code == 0 else None
            desc_str = ""
            if rs.is_halving:
                desc_str = "pvalue: %5e" % (rs.pval,)
            else:
                desc_str = "alpha: %5e" % (rs.alpha,)

            res = rs.js_res["inputs"][0]["res"]
            dist_poly = jsonpath('$[0].dists[0].poly', res, True)
            time_elapsed = jsonpath('$.time_elapsed', rs.js_res, True)
            best_dist_zscore = jsonpath('$[0].dists[0].zscore', res, True) or -1
            ref_zscore_min = jsonpath('$[0].ref_minmax[0]', res, True) or -1
            ref_zscore_max = jsonpath('$[0].ref_minmax[1]', res, True) or -1

            aux_str = ""
            if rs.is_halving:
                best_dist_zscore_halving = jsonpath('$[1].dists[0].zscore', res, True)
                aux_str = "Learn: (z-score: %.5f, acc. zscores: [%.5f, %.5f]), Eval: (z-score: %.5f)" \
                          % (best_dist_zscore, ref_zscore_min, ref_zscore_max, best_dist_zscore_halving)
            else:
                aux_str = "z-score: %.5f, acc. zscores: [%.5f, %.5f]" \
                          % (best_dist_zscore, ref_zscore_min, ref_zscore_max)

            logger.info(" - %s %s: passed: %s, %s, dist: %s\n   elapsed time: %6.2f s, %s"
                        % (rs.job.name, rs.job.vinfo, passed, desc_str, dist_poly,
                           time_elapsed, aux_str))
コード例 #4
0
ファイル: battery.py プロジェクト: crocs-muni/booltest
    def generate_jobs(self):
        dcli = self.args.cli
        if dcli is None:
            dcli = jsonpath('$.default-cli', self.bool_config, True)
        if dcli is None:
            dcli = '--no-summary --json-out --log-prints --top 128 --no-comb-and --only-top-comb --only-top-deg ' \
                   '--no-term-map --topterm-heap --topterm-heap-k 256 --best-x-combs 512'
        if '--no-summary' not in dcli:
            dcli += ' --no-summary'
        if '--json-out' not in dcli:
            dcli += ' --json-out'
        if '--log-prints' not in dcli:
            dcli += ' --log-prints'

        strategies = jsonpath('$.strategies', self.bool_config, True)
        if strategies is None:
            strategies = []
            methods = self.norm_methods(self.args.methods or ["1", "2"])
            for mt in methods:
                strat = collections.OrderedDict()
                strat['name'] = "v%s" % mt
                strat['cli'] = "--halving" if mt == '2' else ''
                strat['variations'] = [collections.OrderedDict([
                    ('bl', self.norm_params(self.args.block, [128, 256, 384, 512])),
                    ('deg', self.norm_params(self.args.deg, [1, 2])),
                    ('cdeg', self.norm_params(self.args.comb_deg, [1, 2])),
                    ('exclusions', []),
                ])]
                strategies.append(strat)

        for st in strategies:
            name = st['name']
            st_cli = jsonpath('$.cli', st, True) or ''
            st_vars = jsonpath('$.variations', st, True) or []
            ccli = ('%s %s' % (dcli, st_cli)).strip()

            if not st_vars:
                yield BoolJob(ccli, name)
                continue

            for cvar in st_vars:
                blocks = listize(jsonpath('$.bl', cvar, True)) or [None]
                degs = listize(jsonpath('$.deg', cvar, True)) or [None]
                cdegs = listize(jsonpath('$.cdeg', cvar, True)) or [None]
                pcli = ['--block', '--degree', '--combine-deg']
                vinfo = ['', '', '']
                iterator = itertools.product(blocks, degs, cdegs)

                for el in iterator:
                    c = ' '.join([(('%s %s') % (pcli[ix], dt)) for (ix, dt) in enumerate(el) if dt is not None])
                    vi = '-'.join([(('%s%s') % (vinfo[ix], dt)).strip() for (ix, dt) in enumerate(el) if dt is not None])
                    ccli0 = ('%s %s' % (ccli, c)).strip()

                    yield BoolJob(ccli0, name, vi)
コード例 #5
0
    def init_rtt_config(self):
        try:
            self.rtt_config_dir = os.path.dirname(self.args.rtt_config)
            with open(self.args.rtt_config) as fh:
                dt = fh.read()
                self.rtt_config = json.loads(dt)
                self.rtt_config_hash = hashlib.sha256(dt.encode("utf8")).hexdigest()

            self.bool_config = jsonpath('"toolkit-settings"."booltest"', self.rtt_config, False)
            if not self.bool_wrapper:
                self.bool_wrapper = jsonpath("$.wrapper", self.bool_config, True)

            if not self.args.threads:
                self.parallel_tasks = try_fnc(lambda: int(os.getenv('RTT_PARALLEL', None)))
            if not self.parallel_tasks:
                self.parallel_tasks = jsonpath('$."toolkit-settings".execution."max-parallel-tests"', self.rtt_config, True) or 1

        except Exception as e:
            logger.error("Could not load RTT config %s at %s" % (e, self.args.rtt_config), exc_info=e)

        finally:
            if self.parallel_tasks is None:
                self.parallel_tasks = self.args.threads or try_fnc(lambda: int(os.getenv('RTT_PARALLEL', None))) or 1
コード例 #6
0
    def get_value(self, path: str, use_list: Optional[bool] = None) -> Any:
        """Return value from json config file using JSON path.

        Arguments:
            path {str} -- A JSON path valid string.
        """
        expr = jsonpath(path).find(self.config)
        if not expr:
            return [] if use_list else None
        if use_list:
            return [e.value for e in expr]
        elif use_list == False:
            return expr[0].value
        # Guess whether to return list or not by default
        if len(expr) == 1:
            return expr[0].value
        else:
            return [e.value for e in expr]
コード例 #7
0
def get_cryptostreams_bin(binpath=None,
                          rtt_settings_path=None,
                          rtt_config=None,
                          search_dir=None):
    if binpath is not None and os.path.exists(binpath):
        return binpath

    if rtt_settings_path or rtt_config:
        if rtt_settings_path:
            with open(rtt_settings_path, 'r') as fh:
                rtt_config = json.load(fh)

        cand = jsonpath('$.toolkit-settings.binaries.cryptostreams',
                        rtt_config, True)
        if cand is not None and os.path.exists(cand):
            return cand

    cand = os.getenv("CRYPTOSTREAMS")
    if cand is not None and os.path.exists(cand):
        return cand

    if search_dir is None:
        search_dir = os.path.dirname(rtt_settings_path)

    if search_dir:
        dname = search_dir
        cands = sorted(glob.glob('%s/crypto-streams*' % dname))
        if cands and len(cands) > 0 and os.path.exists(cands[0]):
            rcand = os.path.realpath(cands[0])
            if os.access(rcand, os.X_OK):
                return rcand

    cand = try_which('crypto-streams-v3.0')
    if cand is not None:
        return cand

    cand = try_which('crypto-streams')
    if cand is not None:
        return cand

    return None
コード例 #8
0
def get_rtt_data_gen_bin(binpath=None,
                         rtt_settings_path=None,
                         search_dir=None,
                         rtt_config=None):
    if binpath is not None and os.path.exists(binpath):
        return binpath

    if rtt_settings_path or rtt_config:
        if rtt_settings_path:
            with open(rtt_settings_path, 'r') as fh:
                rtt_config = json.load(fh)

        cand = jsonpath('$.toolkit-settings.binaries.rtt-data-gen', rtt_config,
                        True)
        if cand is not None and os.path.exists(cand):
            return cand

    cand = os.getenv("RTT_DATA_GEN_PATH")
    if cand is not None and os.path.exists(cand):
        return cand

    if search_dir is None:
        search_dir = os.path.dirname(rtt_settings_path)

    if search_dir:
        cand = os.path.realpath(os.path.join(search_dir, 'rtt-data-gen'))
        if os.path.exists(cand):
            if os.access(cand, os.X_OK):
                return cand
            else:
                logger.info(
                    "rtt-data-gen found in search-dir but it is not executable"
                )

    cand = try_which('rtt-data-gen')
    if cand is not None:
        return cand

    return "%s -m rtt_data_gen.main" % sys.executable
コード例 #9
0
def get_sage_bin(binpath=None,
                 rtt_settings_path=None,
                 rtt_config=None,
                 search_dir=None):
    if binpath is not None and os.path.exists(binpath):
        return binpath

    if rtt_settings_path or rtt_config:
        if rtt_settings_path:
            with open(rtt_settings_path, 'r') as fh:
                rtt_config = json.load(fh)

        cand = jsonpath('$.toolkit-settings.binaries.sage', rtt_config, True)
        if cand is not None and os.path.exists(cand):
            return cand

    cand = os.getenv("SAGE_PATH")
    if cand is not None and os.path.exists(cand):
        return cand

    if search_dir is None and rtt_settings_path is not None:
        search_dir = os.path.dirname(rtt_settings_path)

    if search_dir:
        cand = os.path.realpath(os.path.join(search_dir, 'sage'))
        if os.path.exists(cand):
            if os.access(cand, os.X_OK):
                return cand
            else:
                logger.info(
                    "sage found in search-dir but it is not executable")

    cand = try_which('sage')
    if cand is not None:
        return cand

    return None
コード例 #10
0
ファイル: utils.py プロジェクト: steinnes/pykubeks
 def repl(m):
     path = m.group(2)
     if not path.startswith("$"):
         path = "$" + path
     return jsonpath(path).find(obj)[0].value
コード例 #11
0
def get_booltest_info(results, cursor, variant_id):
    if not results:
        return None
    try:
        js = json.loads(results[0].message,
                        object_pairs_hook=collections.OrderedDict)
        res = js["inputs"][0]["res"]
        js["halving"] = jsonpath('$.halving', js, True) or False
        js["time_elapsed"] = jsonpath('$.time_elapsed', js, True)
        js["best_dist"] = jsonpath('$[0].dists[0]', res, True)
        js["best_dist_poly"] = jsonpath('$[0].dists[0].poly', res, True)
        js["best_dist_zscore"] = jsonpath('$[0].dists[0].zscore', res, True)
        js["best_dist_halving"] = jsonpath('$[1].halvings[0]', res,
                                           True) if js["halving"] else None
        js["ref_samples"] = jsonpath('$[0].ref_samples', res, True)
        js["ref_alpha"] = jsonpath('$[0].ref_alpha', res, True)
        js["ref_zscore_min"] = jsonpath('$[0].ref_minmax[0]', res, True)
        js["ref_zscore_max"] = jsonpath('$[0].ref_minmax[1]', res, True)
        js["rejects"] = jsonpath('$[0].rejects', res, True)
        if js["halving"]:
            js["best_dist_zscore_halving"] = jsonpath('$[1].dists[0].zscore',
                                                      res, True)
            js["pval"] = jsonpath('$.pval', js["best_dist_halving"], True)
        return js

    except Exception as e:
        logger.info("Exception parsing BoolTest results: %s" % (e, ),
                    exc_info=e)