示例#1
0
 def evaluate(self, prog):
     realpath = prog.locate_file(self.filename)
     from pecan.program import load
     new_prog = load(realpath).copy_defaults(prog)
     new_prog.evaluate()
     prog.include(new_prog)
     return None
def run_file(filename):
    settings.set_quiet(True)
    orig_level = settings.get_opt_level()
    settings.set_opt_level(0)
    prog = program.load(filename)
    assert prog.evaluate().result.succeeded()
    settings.set_opt_level(orig_level)
示例#3
0
def run_file(filename):
    orig_quiet = settings.is_quiet()
    settings.set_quiet(True)

    prog = program.load(filename)
    assert prog.evaluate().result.succeeded()

    settings.set_quiet(orig_quiet)
示例#4
0
def run_file(filename, expected_output):
    orig_quiet = settings.is_quiet()
    settings.set_quiet(True)

    f = io.StringIO()
    with redirect_stdout(f):
        prog = program.load(filename)
        assert prog.evaluate().result.succeeded()
    assert f.getvalue().strip() == expected_output.strip()

    settings.set_quiet(orig_quiet)
示例#5
0
def main():
    parser = argparse.ArgumentParser(description='An automated theorem prover for Büchi Automata')
    parser.add_argument('file', help='A Pecan file to execute', nargs='?')
    parser.add_argument('-i', '--interactive', help='Run Pecan in interactive mode (REPL)', required=False, action='store_true')
    parser.add_argument('-d', '--debug', help='Output debugging information', required=False, action='count')
    parser.add_argument('-q', '--quiet', help='Quiet mode', required=False, action='store_true')
    parser.add_argument('--no-opt', help='Turns off optimizations', required=False, action='store_true')
    parser.add_argument('--min-opt', help='Set optimizations to minimal levels (only boolean and arithmetic optimizations).', required=False, action='store_true')
    parser.add_argument('--no-stdlib', help='Turns off the default behavior of loading the standard library (from library/std.pn in your Pecan installation)', required=False, action='store_false')
    parser.add_argument('--generate', help='Enumerate true statements, argument is how many variables to use', type=int, required=False)
    parser.add_argument('--heuristics', help='Use heuristics to determine how to simplify automata. This flag is typically useful with large automata (>10000 states), and can cause worse performance with smaller automata.', required=False, action='store_true')
    parser.add_argument('--extract-implications', help='Alternate mode of running a program involving going through each theorem, extracting the top-level implication that needs to be checked (if applicable).', required=False, action='store_true')
    parser.add_argument('--use-var-map', help='Use the var_map from the specified file and convert the main file to use the same var map (i.e., the argument corresponding to <file>)', required=False, type=str)
    parser.add_argument('--stats', help='Write out statistics about each predicate defined and theorem tested (i.e., in save_aut and assert_prop)', required=False, action='store_true')
    parser.add_argument('--output-hoa', help='Outputs encountered Buchi automata into the file', required=False, type=str, dest="output_hoa", metavar="HOA_FILE")
    parser.add_argument('--output-json', help='Write the output in a JSON format of {"stdout": str, "files": array of strings} where the files array is the names of all the files generated by the Pecan program to standard output when Pecan exists. Useful for running headless on a server to gather the result files.', required=False, action='store_true')
    parser.add_argument('--no-progress', help='Disables all progress bars/indicators. Quiet mode implies this option is on. Should use if planning to pipe output to a file.', required=False, action='store_true')

    args = parser.parse_args()

    settings.set_quiet(args.quiet)
    settings.set_opt_level(0 if args.no_opt else 1)
    settings.set_load_stdlib(args.no_stdlib)
    settings.set_use_heuristics(args.heuristics)
    settings.set_min_opt(args.min_opt)
    settings.set_extract_implications(args.extract_implications)
    settings.set_write_statistics(args.stats)
    settings.set_output_hoa(args.output_hoa)
    settings.set_output_json(args.output_json)
    settings.set_show_progress(not args.no_progress)

    if args.debug is None:
        settings.set_debug_level(0)
    else:
        settings.set_debug_level(args.debug)

    if args.use_var_map is not None:
        if args.file is None:
            print('If --use-var-map is specified, you must also specify <file>!')
            exit(1)

        from pecan.tools.hoa_loader import load_hoa
        use_var_map_aut = load_hoa(args.use_var_map)
        main_file_aut = load_hoa(args.file)

        ap_subs = {}
        for v, aps in use_var_map_aut.get_var_map().items():
            for main_ap, new_ap in zip(main_file_aut.get_var_map().get(v, []), aps):
                ap_subs[main_ap] = new_ap

        s = main_file_aut.aut.to_str('hoa')
        for a,b in ap_subs.items():
            s = s.replace(a, b)
        print(s)

        # print(ap_subs)
        # main_file_aut = main_file_aut.ap_substitute(ap_subs)
        # print(main_file_aut.to_str())

        return

    env = None
    prog = None
    if args.generate is not None:
        for pred in theorem_generator.gen_thms(args.generate):
            print(pred)
    elif args.file is not None:
        try:
            prog = program.load(args.file)
            if not settings.get_extract_implications():
                env = prog.evaluate()
        except UnexpectedToken as e:
            print(e)
            return None

    elif not args.interactive:
        parser.print_help()

    if args.interactive:
        if env is None:
            prog = program.from_source('')
            env = prog.evaluate()

        prog = run_repl(env)

    if settings.get_output_json():
        if prog is not None:
            print(json.dumps({'output': settings.get_output(), 'files': prog.get_generated_files()}))
        else:
            print(json.dumps({'output': '', 'files': []}))
示例#6
0
def main():
    parser = argparse.ArgumentParser(
        description='An automated theorem prover for Büchi Automata')
    parser.add_argument('file', help='A Pecan file to execute', nargs='?')
    parser.add_argument('-i',
                        '--interactive',
                        help='Run Pecan in interactive mode (REPL)',
                        required=False,
                        action='store_true')
    parser.add_argument('-d',
                        '--debug',
                        help='Output debugging information',
                        required=False,
                        action='count')
    parser.add_argument('-q',
                        '--quiet',
                        help='Quiet mode',
                        required=False,
                        action='store_true')
    parser.add_argument('--no-opt',
                        help='Turns off optimizations',
                        required=False,
                        action='store_true')
    parser.add_argument(
        '--no-stdlib',
        help=
        'Turns off the default behavior of loading the standard library (from library/std.pn in your Pecan installation)',
        required=False,
        action='store_false')
    parser.add_argument(
        '--generate',
        help='Enumerate true statements, argument is how many variables to use',
        type=int,
        required=False)

    args = parser.parse_args()

    if args.debug is None:
        settings.set_debug_level(0)
    else:
        settings.set_debug_level(args.debug)

    settings.set_quiet(args.quiet)
    settings.set_opt_level(0 if args.no_opt else 1)
    settings.set_load_stdlib(args.no_stdlib)

    env = None
    if args.generate is not None:
        for pred in theorem_generator.gen_thms(args.generate):
            print(pred)
    elif args.file is not None:
        try:
            prog = program.load(args.file)
            env = prog.evaluate()
        except UnexpectedToken as e:
            print(e)
            return None

    elif not args.interactive:
        parser.print_help()

    if args.interactive:
        if env is None:
            prog = program.from_source('')
            env = prog.evaluate()

        run_repl(env)