Example #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
Example #2
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]
Example #3
0
        '--opt',
        choices=sorted(list(OPTS.keys()), key=lambda v: OPTS[v]),
        required=False,
        default=ASYNC_HUB,
        help='apply an optimization (choose one) (default: %(default)s)')

    args = parser.parse_args(sys.argv[1:])

    logger = setup_logging(args.verbose)

    logger.info(args)

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

    ltl2ucw_converter, z3solver_factory = create_spec_converter_z3(
        logger, UFLIA(None), args.incr, smt_files_prefix)
    if not ltl2ucw_converter or not z3solver_factory:
        exit(0)

    bounds = list(
        range(2, args.bound +
              1) if args.size == 0 else range(args.size, args.size + 1))

    logic = UFLIA(None)

    logger.info('temp file prefix used is %s', smt_files_prefix)

    is_realizable = main(args.ltl.read(), args.opt, args.moore, args.dot,
                         bounds, args.cutoff, ltl2ucw_converter,
                         z3solver_factory, logic, args.cincr, logger)
Example #4
0
File: bosy.py Project: 5nizza/Party
                        help='keep temporary smt2 files')
    parser.add_argument('--incr', action='store_true', required=False, default=False,
                        help='produce incremental queries')
    parser.add_argument('-v', '--verbose', action='count', default=0)

    args = parser.parse_args(sys.argv[1:])

    logger = setup_logging(args.verbose)

    logger.info(args)

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

    logic = UFLIA(None)
    ltl2ucw_converter, solver_factory = create_spec_converter_z3(logger, logic, args.incr, smt_files_prefix)
    if not ltl2ucw_converter or not solver_factory:
        exit(1)

    bounds = list(range(1, args.bound + 1) if args.size == 0 else range(args.size, args.size + 1))

    ltl_text = args.ltl.read()

    part_file_name = '.'.join(args.ltl.name.split('.')[:-1]) + '.part'
    with open(part_file_name) as part_file:
        part_text = part_file.read()

    generic_smt_encoder.ENCODE_INCREMENTALLY = args.incr

    is_realizable = main(ltl_text, part_text, args.moore, args.dot, args.nusmv, bounds,
                         ltl2ucw_converter,
Example #5
0
                        required=False,
                        default=False,
                        help='produce incremental queries')
    parser.add_argument('-v', '--verbose', action='count', default=0)

    args = parser.parse_args(sys.argv[1:])

    logger = setup_logging(args.verbose)

    logger.info(args)

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

    logic = UFLIA(None)
    ltl2ucw_converter, solver_factory = create_spec_converter_z3(
        logger, logic, args.incr, smt_files_prefix)
    if not ltl2ucw_converter or not solver_factory:
        exit(1)

    bounds = list(
        range(1, args.bound +
              1) if args.size == 0 else range(args.size, args.size + 1))

    ltl_text = args.ltl.read()

    part_file_name = '.'.join(args.ltl.name.split('.')[:-1]) + '.part'
    with open(part_file_name) as part_file:
        part_text = part_file.read()

    generic_smt_encoder.ENCODE_INCREMENTALLY = args.incr
Example #6
0
    parser.add_argument('--cincr', action='store_true', required=False, default=False,
                        help='try smaller cutoff sizes first')
    parser.add_argument('--opt', choices=sorted(list(OPTS.keys()), key=lambda v: OPTS[v]), required=False,
                        default=ASYNC_HUB,
                        help='apply an optimization (choose one) (default: %(default)s)')

    args = parser.parse_args(sys.argv[1:])

    logger = setup_logging(args.verbose)

    logger.info(args)

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

    ltl2ucw_converter, z3solver_factory = create_spec_converter_z3(logger, UFLIA(None), args.incr, smt_files_prefix)
    if not ltl2ucw_converter or not z3solver_factory:
        exit(0)

    bounds = list(range(2, args.bound + 1) if args.size == 0 else range(args.size, args.size + 1))

    logic = UFLIA(None)

    logger.info('temp file prefix used is %s', smt_files_prefix)

    is_realizable = main(args.ltl.read(),
                         args.opt,
                         args.moore,
                         args.dot,
                         bounds,
                         args.cutoff,
Example #7
0
                       help='assume a Mealy model')

    parser.add_argument('--minsize', metavar='minsize', type=int, default=1, required=False,
                        help='start from size')
    parser.add_argument('--maxsize', metavar='maxsize', type=int, default=4, required=False,
                        help='stop at this size')

    parser.add_argument('-v', '--verbose', action='count', default=0)

    args = parser.parse_args()
    assert args.minsize <= args.maxsize

    logger = setup_logging(args.verbose)
    logger.info(args)

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

    ltl3ba, solver_factory = create_spec_converter_z3(UFLRA(),
                                                      False,
                                                      True,
                                                      smt_files_prefix,
                                                      True)
    elli.check_real(readfile(args.spec),
                    readfile(args.spec.replace('.ltl', '.part')),
                    args.moore,
                    ltl3ba, solver_factory,
                    args.minsize, args.maxsize)
    solver_factory.down_solvers()
    exit(0)