コード例 #1
0
ファイル: benchmarks.py プロジェクト: jiry17/IntSy
def std_unification_solver(theory, syn_ctx, synth_funs, grammar_map, specification, verifier):
    if len(synth_funs) > 1:
        raise UnsuitableSolverException("DT Unification Solver: Multi-function unification not supported")
    if specification.is_multipoint:
        raise UnsuitableSolverException("Multi point specification")

    synth_fun = synth_funs[0]
    grammar = grammar_map[synth_fun]

    decomposed_grammar = grammar.decompose(syn_ctx.macro_instantiator)
    if decomposed_grammar == None:
        raise UnsuitableSolverException("DT Unification Solver: Unable to decompose grammar")
    term_grammar, pred_grammar, reverse_mapping = decomposed_grammar

    generator_factory = enumerators.PointDistinctGeneratorFactory(specification)
    term_generator = term_grammar.to_generator(generator_factory)
    pred_generator = pred_grammar.to_generator(generator_factory)
    solver = solvers.Solver(syn_ctx)
    term_solver = termsolvers.PointDistinctTermSolver(specification.term_signature, term_generator)
    unifier = unifiers.PointDistinctDTUnifier(pred_generator, term_solver, synth_fun, syn_ctx)
    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(
            generator_factory,
            term_solver,
            unifier,
            verifier,
            verify_term_solve=True
            )
    solution = next(solutions)
    final_solution = rewrite_solution([synth_fun], solution, reverse_mapping)
    return final_solution
コード例 #2
0
def std_unification_solver(theory,
                           syn_ctx,
                           synth_funs,
                           grammar_map,
                           specification,
                           verifier,
                           phog_file,
                           options=options):
    if len(synth_funs) > 1:
        raise UnsuitableSolverException(
            "DT Unification Solver: Multi-function unification not supported")
    if specification.is_multipoint:
        raise UnsuitableSolverException("Multi point specification")

    synth_fun = synth_funs[0]
    grammar = grammar_map[synth_fun]

    decomposed_grammar = grammar.decompose(syn_ctx.macro_instantiator)
    if decomposed_grammar == None:
        raise UnsuitableSolverException(
            "DT Unification Solver: Unable to decompose grammar")
    term_grammar, pred_grammar, reverse_mapping = decomposed_grammar
    generator_factory = enumerators.PointDistinctGeneratorFactory(
        specification)
    term_generator = term_grammar.to_generator(generator_factory)
    pred_generator = pred_grammar.to_generator(generator_factory)
    solver = solvers.Solver(syn_ctx)
    term_phog = SPhog(term_grammar, phog_file, synth_fun.range_type, specification, for_eusolver=True, for_pred_exprs=False) if options.use_sphog() else \
        Phog(term_grammar, phog_file, synth_fun.range_type, for_eusolver=True, for_pred_exprs=False)
    pred_phog = SPhog(pred_grammar, phog_file, synth_fun.range_type, specification, for_eusolver=True, for_pred_exprs=True, ref_grammar=term_grammar) if options.use_sphog() else \
        Phog(pred_grammar, phog_file, synth_fun.range_type, for_eusolver=True, for_pred_exprs=True)

    if term_phog.stat_map is None:
        print(
            'No model available for this problem. We use the classic EUSolver ...'
        )
        term_phog = None
        pred_phog = None
    if pred_phog is not None and pred_phog.stat_map is None:
        pred_phog = None

    term_solver = termsolvers.PointDistinctTermSolver(
        specification.term_signature, term_generator, stat_model=term_phog)
    unifier = unifiers.PointDistinctDTUnifier(pred_generator,
                                              term_solver,
                                              synth_fun,
                                              syn_ctx,
                                              stat_model=pred_phog)
    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(generator_factory,
                             term_solver,
                             unifier,
                             verifier,
                             verify_term_solve=True)
    solution = next(solutions)
    final_solution = rewrite_solution([synth_fun], solution, reverse_mapping)
    return final_solution
コード例 #3
0
ファイル: benchmarks.py プロジェクト: jiry17/IntSy
def memoryless_esolver(theory, syn_ctx, synth_funs, grammar_map, specification, verifier):
    generator_factory = enumerators.RecursiveGeneratorFactory()
    TermSolver = termsolvers.PointlessTermSolver

    if len(synth_funs) > 1:
        sf_list = [ (synth_fun.function_name, synth_fun, grammar_map[synth_fun])
            for synth_fun in synth_funs ]
        grammar = _merge_grammars(sf_list)
    else:
        grammar = grammar_map[synth_funs[0]]

    term_generator = grammar.to_generator(generator_factory)

    term_solver = TermSolver(specification.term_signature, term_generator)
    term_solver.stopping_condition = termsolvers.StoppingCondition.one_term_sufficiency
    unifier = unifiers.NullUnifier(None, term_solver, synth_funs, syn_ctx, specification)

    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(
            generator_factory,
            term_solver,
            unifier,
            verifier,
            verify_term_solve=False
            )
    solution = next(solutions)
    rewritten_solutions = rewrite_solution(synth_funs, solution, reverse_mapping=None)
    return rewritten_solutions
コード例 #4
0
ファイル: benchmarks.py プロジェクト: jiry17/IntSy
def classic_esolver(theory, syn_ctx, synth_funs, grammar_map, specification, verifier):
    if len(synth_funs) != 1:
        raise UnsuitableSolverException("Classic esolver for multi-function disable due to bugs")
    assert len(synth_funs) == 1
    try:
        generator_factory = enumerators.PointDistinctGeneratorFactory(specification)
    except:
        raise UnsuitableSolverException("Enumerator problems")

    TermSolver = termsolvers.PointDistinctTermSolver
    grammar = grammar_map[synth_funs[0]]
    term_generator = grammar.to_generator(generator_factory)

    term_solver = TermSolver(specification.term_signature, term_generator)
    term_solver.stopping_condition = termsolvers.StoppingCondition.one_term_sufficiency
    unifier = unifiers.NullUnifier(None, term_solver, synth_funs, syn_ctx, specification)

    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(
            generator_factory,
            term_solver,
            unifier,
            verifier,
            verify_term_solve=False
            )
    try:
        solution = next(solutions)
    except StopIteration:
        return "NO SOLUTION"
    rewritten_solutions = rewrite_solution(synth_funs, solution, reverse_mapping=None)
    return rewritten_solutions
コード例 #5
0
ファイル: benchmarks.py プロジェクト: jiry17/IntSy
def lia_unification_solver(theory, syn_ctx, synth_funs, grammar_map, specification, verifier):
    if theory != 'LIA':
        raise UnsuitableSolverException('LIA Unification Solver: Not LIA theory')
    if any([sf.range_type != exprtypes.IntType() for sf in synth_funs ]):
        raise UnsuitableSolverException('LIA Unification Solver: Cannot handle bool return values yet')
    if not specification.is_pointwise():
        raise UnsuitableSolverException('LIA Unification Solver: Not pointwise spec')

    okay, massaging = full_lia_grammars(grammar_map) 
    if not okay:
        raise UnsuitableSolverException('LIA Unification Solver: Could not get LIA full grammar')

    term_solver = termsolvers_lia.SpecAwareLIATermSolver(specification.term_signature, specification)
    unifier = unifiers_lia.SpecAwareLIAUnifier(None, term_solver, synth_funs, syn_ctx, specification)
    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(
            enumerators.NullGeneratorFactory(),
            term_solver,
            unifier,
            verifier,
            verify_term_solve=False
            )
    solution = next(solutions)
    final_solution = rewrite_solution(synth_funs, solution, reverse_mapping=None)
    final_solution = lia_massager.massage_full_lia_solution(syn_ctx, synth_funs, final_solution, massaging)
    if final_solution is None:
        raise UnsuitableSolverException('LIA Unification Solver: Could not massage back solution')  
    return final_solution
コード例 #6
0
def classic_esolver(theory, syn_ctx, synth_funs, grammar_map, specification,
                    verifier, phog_file):
    if len(synth_funs) != 1:
        raise UnsuitableSolverException(
            "Classic esolver for multi-function disable due to bugs")
    assert len(synth_funs) == 1
    try:
        generator_factory = enumerators.PointDistinctGeneratorFactory(
            specification)
    except:
        raise UnsuitableSolverException("Enumerator problems")
    TermSolver = termsolvers.PointDistinctTermSolver
    grammar = grammar_map[synth_funs[0]]
    term_generator = grammar.to_generator(generator_factory)

    # init for using PHOG
    phog = SPhog(grammar, phog_file, synth_funs[0].range_type, specification) if options.use_sphog() else \
        Phog(grammar, phog_file, synth_funs[0].range_type)
    if phog.stat_map is None:
        print(
            'No model available for this problem. We use the classic ESolver ...'
        )
        phog = None

    term_solver = TermSolver(specification.term_signature,
                             term_generator,
                             stat_model=phog)
    term_solver.stopping_condition = termsolvers.StoppingCondition.one_term_sufficiency
    unifier = unifiers.NullUnifier(None, term_solver, synth_funs, syn_ctx,
                                   specification)

    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(generator_factory,
                             term_solver,
                             unifier,
                             verifier,
                             verify_term_solve=False)
    try:
        solution = next(solutions)
    except StopIteration:
        return "NO SOLUTION"
    rewritten_solutions = rewrite_solution(synth_funs,
                                           solution,
                                           reverse_mapping=None)
    return rewritten_solutions