Exemplo n.º 1
0
def main(tlsf_file_name, output_file_name, dot_file_name, smt_files_prefix, keep_temp_files) -> int:
    """ :return: REALIZABLE, UNREALIZABLE, UNKNOWN (see elli) """

    timer = Timer()
    logic = UFLRA()

    ltl3ba, solver_factory = create_spec_converter_z3(logic, True, False, smt_files_prefix, not keep_temp_files)

    ltl_text, part_text = convert_tlsf_to_acacia(tlsf_file_name)
    is_moore = get_spec_type(tlsf_file_name)

    try:
        timer.sec_restart()
        env_model = elli.check_unreal(
            ltl_text, part_text, is_moore, ltl3ba, solver_factory, 1, 1, ltl3ba_timeout_sec=200
        )
        logging.info("unreal check took (sec): %i" % timer.sec_restart())
        logging.info("env model is {NOT} FOUND".format(NOT="" if env_model else "NOT"))
        if env_model:
            print("UNREALIZABLE")
            logging.debug(lts_to_dot(env_model, ARG_MODEL_STATE, is_moore))
            return UNREALIZABLE
    except subprocess.TimeoutExpired:
        logging.info("I aborted unreal check (>200sec). Proceed to real check.")

    model = elli.check_real(ltl_text, part_text, is_moore, ltl3ba, solver_factory, 1, 40)
    logging.info("real check took (sec): %i" % timer.sec_restart())
    logging.info("sys model is {NOT} FOUND".format(NOT="" if model else "NOT"))
    if not model:
        logging.info("trying check_real without formula strengthening")
        model = elli.check_real(ltl_text, part_text, is_moore, ltl3ba, solver_factory, 1, 40, opt_level=0)
        logging.info("(without formula strengthening): real check took (sec): %i" % timer.sec_restart())
        logging.info("(without formula strengthening): sys model is {NOT} FOUND".format(NOT="" if model else "NOT"))

    if not model:
        return UNKNOWN

    dot_model_str = lts_to_dot(model, ARG_MODEL_STATE, not is_moore)

    if dot_file_name:
        with open(dot_file_name, "w") as out:
            out.write(dot_model_str)
            logging.info(
                "{model_type} model is written to {file}".format(model_type=["Mealy", "Moore"][is_moore], file=out.name)
            )
    else:
        logging.info(dot_model_str)

    aiger_model_str = lts_to_aiger(model)
    logging.info("circuit size: %i" % len(model.states))

    if output_file_name:
        with open(output_file_name, "w") as out:
            out.write(aiger_model_str)
    else:
        print("REALIZABLE")
        print(aiger_model_str)

    solver_factory.down_solvers()
    return REALIZABLE
Exemplo n.º 2
0
def run_and_report(spec_file_name, is_moore_: bool, output_file_name,
                   dot_file_name, tasks_creator: TaskCreator):
    timer = Timer()
    ltl_text, part_text, is_moore = convert_tlsf_or_acacia_to_acacia(
        spec_file_name, is_moore_)

    tasks = tasks_creator.create(ltl_text, part_text, is_moore)

    is_real, lts_or_aiger = run_synth_tasks(tasks)

    if is_real is None:
        logging.warning('Either crashed or did not succeed')
        print_syntcomp_unknown()
        exit(UNKNOWN_RC)

    logging.info('finished in %i sec.' % timer.sec_restart())

    if not lts_or_aiger:
        logging.info('status unknown')
        print_syntcomp_unknown()
        exit(UNKNOWN_RC)

    if not is_real:
        if isinstance(lts_or_aiger, LTS):
            lts_str = lts_to_dot(lts_or_aiger, ARG_MODEL_STATE,
                                 is_moore)  # we invert machine type
            _write_dot_result(lts_str, dot_file_name)
        print_syntcomp_unreal()
        exit(UNREALIZABLE_RC)
    else:
        if isinstance(lts_or_aiger, LTS):
            lts_str = lts_to_dot(lts_or_aiger, ARG_MODEL_STATE, not is_moore)
            logging.info('state machine size: %i' % len(lts_or_aiger.states))
            _write_dot_result(lts_str, dot_file_name)
            lts_aiger = lts_to_aiger(lts_or_aiger)
        else:
            lts_aiger = lts_or_aiger
        if output_file_name:
            with open(output_file_name, 'w') as out:
                out.write(lts_aiger)
        print_syntcomp_real(lts_aiger)
        exit(REALIZABLE_RC)
Exemplo n.º 3
0
def main():
    """ :return: 1 if model is found, 0 otherwise """

    parser = argparse.ArgumentParser(
        description="Bounded Synthesis Tool", formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument("spec", metavar="spec", type=str, help="the specification file (acacia+ format)")

    group = parser.add_mutually_exclusive_group()  # default: moore=False, mealy=True
    group.add_argument("--moore", action="store_true", default=False, help="system is Moore")
    group.add_argument("--mealy", action="store_false", default=True, help="system is Mealy")

    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        "--bound",
        metavar="bound",
        type=int,
        default=128,
        required=False,
        help="upper bound on the size of the model (for unreal this specifies size of env model)",
    )
    group.add_argument(
        "--size",
        metavar="size",
        type=int,
        default=0,
        required=False,
        help="search the model of this size (for unreal this specifies size of env model)",
    )

    parser.add_argument("--incr", action="store_true", required=False, default=False, help="use incremental solving")
    parser.add_argument("--tmp", action="store_true", required=False, default=False, help="keep temporary smt2 files")
    parser.add_argument("--dot", metavar="dot", type=str, required=False, help="write the output into a dot graph file")
    parser.add_argument("--log", metavar="log", type=str, required=False, default=None, help="name of the log file")
    parser.add_argument(
        "--unreal",
        action="store_true",
        required=False,
        help="simple check of unrealizability: "
        "invert the spec, system type, (in/out)puts, "
        "and synthesize the model for env "
        "(a more sophisticated check could search for env that disproves systems of given size)"
        "(note that the inverted spec will NOT be strengthened)",
    )
    parser.add_argument("-v", "--verbose", action="count", default=0)

    args = parser.parse_args()

    setup_logging(args.verbose, args.log)
    logging.info(args)

    if args.incr and args.tmp:
        logging.warning(
            "--tmp --incr: incremental queries do not produce smt2 files, " "so I won't save any temporal files."
        )

    with tempfile.NamedTemporaryFile(dir="./") as smt_file:
        smt_files_prefix = smt_file.name

    ltl3ba, solver_factory = create_spec_converter_z3(UFLRA(), args.incr, False, smt_files_prefix, not args.tmp)
    if args.size == 0:
        min_size, max_size = 1, args.bound
    else:
        min_size, max_size = args.size, args.size

    ltl_text, part_text = readfile(args.spec), readfile(args.spec.replace(".ltl", ".part"))
    if not args.unreal:
        model = check_real(ltl_text, part_text, args.moore, ltl3ba, solver_factory, min_size, max_size)
    else:
        model = check_unreal(ltl_text, part_text, args.moore, ltl3ba, solver_factory, min_size, max_size)

    logging.info(
        "{status} model for {who}".format(status=("FOUND", "NOT FOUND")[model is None], who=("sys", "env")[args.unreal])
    )
    if model:
        dot_model_str = lts_to_dot(model, ARG_MODEL_STATE, (not args.moore) ^ args.unreal)

        if args.dot:
            with open(args.dot, "w") as out:
                out.write(dot_model_str)
                logging.info(
                    "{model_type} model is written to {file}".format(
                        model_type=["Mealy", "Moore"][args.moore], file=out.name
                    )
                )
        else:
            logging.info(dot_model_str)

    solver_factory.down_solvers()

    return UNKNOWN if model is None else (REALIZABLE, UNREALIZABLE)[args.unreal]
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description='Bounded Synthesis Tool',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('spec',
                        metavar='spec',
                        type=str,
                        help='the specification file (Acacia or TLSF format)')

    gr = parser.add_mutually_exclusive_group()
    gr.add_argument('--moore',
                    action='store_true',
                    default=True,
                    dest='moore',
                    help='system is Moore (ignored for TLSF)')
    gr.add_argument('--mealy',
                    action='store_false',
                    default=False,
                    dest='moore',
                    help='system is Mealy (ignored for TLSF)')

    gr = parser.add_mutually_exclusive_group()
    gr.add_argument('--spot',
                    action='store_true',
                    default=True,
                    dest='spot',
                    help='use SPOT for translating LTL->BA')
    gr.add_argument('--ltl3ba',
                    action='store_false',
                    default=False,
                    dest='spot',
                    help='use LTL3BA for translating LTL->BA')

    parser.add_argument(
        '--maxK',
        type=int,
        default=0,
        help="reduce liveness to co-reachability (safety)."
        "This sets the upper bound on the number of 'bad' visits."
        "We iterate over increasing k (exact value of k is set heuristically)."
        "(k=0 means no reduction)")

    gr = parser.add_mutually_exclusive_group()
    gr.add_argument(
        '--bound',
        metavar='bound',
        type=int,
        default=32,
        required=False,
        help=
        'upper bound on the size of the model (for unreal this specifies size of env model)'
    )
    gr.add_argument(
        '--size',
        metavar='size',
        type=int,
        default=0,
        required=False,
        help=
        'search the model of this size (for unreal this specifies size of env model)'
    )

    parser.add_argument('--incr',
                        action='store_true',
                        required=False,
                        default=False,
                        help='use incremental solving')
    parser.add_argument('--tmp',
                        action='store_true',
                        required=False,
                        default=False,
                        help='keep temporary smt2 files')
    parser.add_argument('--dot',
                        metavar='dot',
                        type=str,
                        required=False,
                        help='write the output into a dot graph file')
    parser.add_argument('--log',
                        metavar='log',
                        type=str,
                        required=False,
                        default=None,
                        help='name of the log file')
    parser.add_argument(
        '--unreal',
        action='store_true',
        required=False,
        help='simple check of unrealizability: '
        'invert the spec, system type, (in/out)puts, '
        'and synthesize the model for env '
        '(note that the inverted spec will NOT be strengthened)')
    parser.add_argument('-v', '--verbose', action='count', default=0)

    args = parser.parse_args()

    setup_logging(args.verbose, args.log)
    logging.info(args)

    if args.incr and args.tmp:
        logging.warning(
            "--tmp --incr: incremental queries do not produce smt2 files, "
            "so I won't save any temporal files.")

    with tempfile.NamedTemporaryFile(dir='./') as smt_file:
        smt_files_prefix = smt_file.name

    ltl_to_automaton = (translator_via_ltl3ba.LTLToAtmViaLTL3BA,
                        translator_via_spot.LTLToAtmViaSpot)[args.spot]()
    solver_factory = Z3SolverFactory(smt_files_prefix, Z3_PATH, args.incr,
                                     False, not args.tmp)

    if args.size == 0:
        min_size, max_size = 1, args.bound
    else:
        min_size, max_size = args.size, args.size

    ltl_text, part_text, is_moore = convert_tlsf_or_acacia_to_acacia(
        args.spec, args.moore)

    if args.unreal:
        model = check_unreal(ltl_text, part_text, is_moore, ltl_to_automaton,
                             solver_factory.create(), args.maxK, min_size,
                             max_size)
    else:
        model = check_real(ltl_text, part_text, is_moore, ltl_to_automaton,
                           solver_factory.create(), args.maxK, min_size,
                           max_size)

    if not model:
        logging.info('model NOT FOUND')
    else:
        logging.info('FOUND model for {who} of size {size}'.format(
            who=('sys', 'env')[args.unreal], size=len(model.states)))

    if model:
        dot_model_str = lts_to_dot(model, ARG_MODEL_STATE,
                                   (not is_moore) ^ args.unreal)
        if args.dot:
            with open(args.dot, 'w') as out:
                out.write(dot_model_str)
                logging.info('{model_type} model is written to {file}'.format(
                    model_type=['Mealy', 'Moore'][is_moore], file=out.name))
        else:
            logging.info(dot_model_str)

    solver_factory.down_solvers()

    return UNKNOWN_RC if model is None else (REALIZABLE_RC,
                                             UNREALIZABLE_RC)[args.unreal]
Exemplo n.º 5
0
def main():
    """ :return: 1 if model is found, 0 otherwise """
    parser = argparse.ArgumentParser(
        description='Bounded Synthesizer for CTL*',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('spec',
                        metavar='spec',
                        type=str,
                        help='the specification file (in python format)')

    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        '--bound',
        metavar='bound',
        type=int,
        default=128,
        required=False,
        help=
        'upper bound on the size of the model (for unreal this specifies size of env model)'
    )
    group.add_argument(
        '--size',
        metavar='size',
        type=int,
        default=0,
        required=False,
        help=
        'search the model of this size (for unreal this specifies size of env model)'
    )

    group = parser.add_mutually_exclusive_group()
    group.add_argument('--direct',
                       action='store_true',
                       default=True,
                       dest='direct',
                       help='use direct encoding')
    group.add_argument('--aht',
                       action='store_false',
                       default=False,
                       dest='direct',
                       help='encode via AHT')

    parser.add_argument('--incr',
                        action='store_true',
                        required=False,
                        default=False,
                        help='use incremental solving')
    parser.add_argument('--tmp',
                        action='store_true',
                        required=False,
                        default=False,
                        help='keep temporary smt2 files')
    parser.add_argument('--dot',
                        metavar='dot',
                        type=str,
                        required=False,
                        help='write the output into a dot graph file')
    parser.add_argument('--aiger',
                        metavar='aiger',
                        type=str,
                        required=False,
                        help='write the output into an AIGER format')
    parser.add_argument('--log',
                        metavar='log',
                        type=str,
                        required=False,
                        default=None,
                        help='name of the log file')
    parser.add_argument('-v', '--verbose', action='count', default=0)

    args = parser.parse_args()

    setup_logging(args.verbose, args.log)
    logging.info(args)

    if args.incr and args.tmp:
        logging.warning(
            "--tmp --incr: incremental queries do not produce smt2 files, "
            "so I won't save any temporal files.")

    with tempfile.NamedTemporaryFile(dir='./') as smt_file:
        smt_files_prefix = smt_file.name

    ltl_to_atm = translator_via_spot.LTLToAtmViaSpot()
    solver_factory = Z3SolverFactory(smt_files_prefix, Z3_PATH, args.incr,
                                     False, not args.tmp)

    if args.size == 0:
        min_size, max_size = 1, args.bound
    else:
        min_size, max_size = args.size, args.size

    spec = parse_python_spec(args.spec)
    model = check_real(spec, min_size, max_size, ltl_to_atm, solver_factory,
                       args.direct)

    logging.info('{status} model for {who}'.format(
        status=('FOUND', 'NOT FOUND')[model is None], who='sys'))
    if model:
        dot_model_str = lts_to_dot(model, ARG_MODEL_STATE, False)

        if args.dot:
            with open(args.dot, 'w') as out:
                out.write(dot_model_str)
                logging.info(
                    'Moore model is written to {file}'.format(file=out.name))
        else:
            logging.info(dot_model_str)

        if args.aiger:
            with open(args.aiger, 'w') as aiger_out:
                aiger_out.write(lts_to_aiger(model))

    solver_factory.down_solvers()

    return UNKNOWN if model is None else REALIZABLE