Esempio n. 1
0
    def __init__(self, s):
        """ Initializes object of Probe.

        :param s: name of the probe
        """
        assert isinstance(s, str)

        self.s = s
        self.probe = z3.Probe(s)
def get_features(file_path, feature_setting, logic="", track=""):
    if file_path not in cache:
        cache[file_path] = {}
    if logic not in cache[file_path]:
        cache[file_path][logic] = {}
    if track not in cache[file_path][logic]:
        cache[file_path][logic][track] = {}
    if feature_setting == "bow":
        features = get_syntactic_count_features(file_path)
    elif feature_setting == "probes":
        g = z3.Goal()
        g.add(z3.parse_smt2_file(file_path))
        features = [z3.Probe(x)(g) for x in PROBES]
    else:
        g = z3.Goal()
        g.add(z3.parse_smt2_file(file_path))
        features = get_syntactic_count_features(file_path) + [
            z3.Probe(x)(g) for x in PROBES
        ]

    cache[file_path][logic][track] = features
    return features
Esempio n. 3
0
def arith_avg_bw_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'arith-avg-bw'), ctx)
Esempio n. 4
0
def arith_max_deg_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'arith-max-deg'), ctx)
Esempio n. 5
0
def is_unbounded_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'is-unbounded'), ctx)
Esempio n. 6
0
def is_qfbv_eq_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'is-qfbv-eq'), ctx)
Esempio n. 7
0
def is_propositional_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'is-propositional'), ctx)
Esempio n. 8
0
def has_patterns_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'has-patterns'), ctx)
Esempio n. 9
0
def produce_model_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'produce-model'), ctx)
Esempio n. 10
0
def produce_proofs_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'produce-proofs'), ctx)
Esempio n. 11
0
def num_bv_consts_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'num-bv-consts'), ctx)
Esempio n. 12
0
def num_exprs_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'num-exprs'), ctx)
Esempio n. 13
0
def size_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'size'), ctx)
Esempio n. 14
0
def depth_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'depth'), ctx)
Esempio n. 15
0
def memory_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'memory'), ctx)
Esempio n. 16
0
def is_nra_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'is-nra'), ctx)
Esempio n. 17
0
def produce_unsat_cores_probe(ctx=None):
    ctx = z3._get_ctx(ctx)
    return z3.Probe(z3core.Z3_mk_probe(ctx.ref(), 'produce-unsat-cores'), ctx)
Esempio n. 18
0
def parse_with_z3(file, out_dir, check_only, split_queries, simplify, skip_err,
                  datalog):
    if check_only:
        assertions = z3.parse_smt2_file(file)
        check.check_chcs(assertions.children())
        print("success")
        return
    lst = file.split('/')
    tmp = lst.pop()
    lst = tmp.split('.')
    base_name = lst[0]
    assert len(lst) > 0
    if len(lst) > 1:
        for stuff in lst[1:-1]:
            base_name = base_name + '.' + stuff

    # Check if the file is actually in datalog.
    engine = z3.Fixedpoint()
    engine.set("xform.inline_eager", simplify, "xform.inline_linear", simplify,
               "xform.slice", simplify, "xform.coi", simplify,
               "xform.compress_unbound", simplify, "xform.subsumption_checker",
               simplify, "xform.tail_simplifier_pve", simplify)
    try:
        queries = engine.parse_file(file)
    except z3.Z3Exception as e:
        raise Exc('Parse error on file {}'.format(file))

    assertions = engine.get_assertions()
    for rule in engine.get_rules():
        assertions.push(rule)
    for query in queries:
        assertions.push(z3.Implies(query, False))

    # engine.get_assertions()
    goals = z3.Goal()
    goals.add(assertions)

    non_lin = z3.Probe('arith-max-deg')
    if non_lin(goals) > 1:
        raise Skip('found non-linear expressions')

    # if simplify:
    tactic = z3.Tactic("horn-simplify")
    simplified = tactic(goals, "xform.inline_eager", simplify,
                        "xform.inline_linear", simplify, "xform.slice",
                        simplify, "xform.coi", simplify,
                        "xform.compress_unbound", simplify,
                        "xform.subsumption_checker", simplify,
                        "xform.tail_simplifier_pve", simplify)

    # else:
    #     simplified = [goals]
    clauses = []
    queries = []
    if len(simplified) == 0:
        raise Skip('empty benchmark (possibly because of pre-processing)')

    pred_decls = set()

    for index, clause in enumerate(simplified[0]):
        try:
            clause, is_query = fix.fix_clause(clause, pred_decls)
            if is_query:
                queries.append(clause)
            else:
                clauses.append(clause)
        except Exc as e:
            raise Exc('While fixing clause {}:\n{}'.format(index, e.value))

    if len(queries) < 1:
        raise Skip('no query clause (possibly because of pre-processing)')

    separated_clauses = []

    if split_queries:

        for cnt, query in enumerate(queries):
            these_clauses = []
            for clause in clauses:
                these_clauses.append(clause)
            these_clauses.append(query)

            separated_clauses.append(these_clauses)

    else:

        for query in queries:
            clauses.append(query)

        separated_clauses.append(clauses)

    cnt = 0

    for clauses in separated_clauses:

        if out_dir is not None:
            out_file = "{}/{}_{:0>3}.smt2".format(out_dir, base_name, cnt)
            cnt += 1
            print('Writing to {}'.format(out_file))
            writer = open(out_file, mode='w')
        else:
            writer = sys.stdout

        if split_queries:
            try:
                check.check_chcs(clauses)
            except Exc as e:
                exc = Exc('Result of formatting is ill-formed:\n{}'.format(
                    e.value))
                if skip_err:
                    eprint('Error on file {}'.format(file))
                    eprint(exc.value)
                    continue
                else:
                    raise exc

        if datalog:
            write_clauses_datalog(pred_decls, clauses, writer)
        else:
            write_clauses_smt2(pred_decls, clauses, writer)