Esempio n. 1
0
def create_prover(options: deephol_pb2.ProverOptions) -> Prover:
    """Creates a Prover object, initializing all dependencies."""
    theorem_database = io_util.load_theorem_database_from_file(
        str(options.path_theorem_database))
    tactics = io_util.load_tactics_from_file(str(options.path_tactics),
                                             str(options.path_tactics_replace))
    if options.action_generator_options.asm_meson_no_params_only:
        tf.logging.warn(
            'Note: Using Meson action generator with no parameters.')
        action_gen = action_generator.MesonActionGenerator()
    else:
        predictor = get_predictor(options)
        emb_store = None
        if options.HasField('theorem_embeddings'):
            emb_store = embedding_store.TheoremEmbeddingStore(predictor)
            emb_store.read_embeddings(str(options.theorem_embeddings))
            assert emb_store.thm_embeddings.shape[0] == len(
                theorem_database.theorems)
        action_gen = action_generator.ActionGenerator(
            theorem_database, tactics, predictor,
            options.action_generator_options, options.model_architecture,
            emb_store)
    hol_wrapper = setup_prover(theorem_database)
    tf.logging.info('DeepHOL dependencies initialization complete.')
    if options.prover == 'bfs':
        return BFSProver(options, hol_wrapper, action_gen, theorem_database)
    return NoBacktrackProver(options, hol_wrapper, action_gen,
                             theorem_database)
Esempio n. 2
0
def create_processor(
        options: options_pb2.ConvertorOptions,
        theorem_database: Optional[proof_assistant_pb2.TheoremDatabase] = None,
        tactics: Optional[List[deephol_pb2.Tactic]] = None
) -> ProofLogToTFExample:
    """Factory function for ProofLogToTFExample."""

    if theorem_database and options.theorem_database_path:
        raise ValueError(
            'Both thereom database as well as a path to load it from file '
            'provided. Only provide one.')
    if not theorem_database:
        theorem_database = io_util.load_theorem_database_from_file(
            str(options.theorem_database_path))

    if tactics and options.tactics_path:
        raise ValueError('Both tactics as well as a path to load it from '
                         'provided. Only provide one.')
    if not tactics:
        tactics = io_util.load_tactics_from_file(str(options.tactics_path),
                                                 None)
    tactics_name_id_map = {tactic.name: tactic.id for tactic in tactics}

    if options.replacements_hack:
        logging.warning('Replacments hack is enabled.')
        tactics_name_id_map.update({
            'GEN_TAC': 8,
            'MESON_TAC': 11,
            'CHOOSE_TAC': 34,
        })
    if options.format != options_pb2.ConvertorOptions.HOLPARAM:
        raise ValueError(
            'Unknown options_pb2.ConvertorOptions.TFExampleFormat.')
    return ProofLogToTFExample(tactics_name_id_map, theorem_database, options)
def process_prover_flags():
    """Process the flags and return tasks, options and output path."""
    prover_options = get_prover_options()

    if FLAGS.splits:
        tf.logging.info(
            '--splits flag overrides prover options for split selection.')
        splits_to_prove = prover_util.translate_splits(FLAGS.splits)
    else:
        splits_to_prove = list(prover_options.splits_to_prove)
    if not splits_to_prove and not FLAGS.tasks_by_fingerprint:
        tf.logging.fatal('No split specification!')
    tf.logging.info(
        'Splits to prove: %s',
        ', '.join(map(proof_assistant_pb2.Theorem.Split.Name,
                      splits_to_prove)))

    if FLAGS.libraries:
        tf.logging.info(
            '--libraries flag overrides prover options for library_tag selection.'
        )
        if FLAGS.libraries == 'all':
            library_tags = set()
        else:
            library_tags = set([tag for tag in FLAGS.libraries.split(',')])
    else:
        library_tags = set(prover_options.library_tags)
    if not library_tags:
        tf.logging.info('Disregarding library tags.')
    else:
        tf.logging.info('Library tags to prove: %s',
                        ', '.join(sorted(list(library_tags))))

    # Fail fast in case error in specifying tactics.
    _ = io_util.load_tactics_from_file(
        str(prover_options.path_tactics),
        str(prover_options.path_tactics_replace))
    theorem_db = io_util.load_theorem_database_from_file(
        str(prover_options.path_theorem_database))
    if not theorem_db.HasField('name'):
        theorem_db.name = 'default'  # Set a dummy name for backwards compatibility
        tf.logging.warning('Missing theorem database name is set to %s',
                           theorem_db.name)
    if FLAGS.task_list and FLAGS.tasks:
        tf.logging.fatal('Only one of --tasks or --task_list is allowed.')
    prover_tasks = prover_util.get_task_list(FLAGS.tasks, FLAGS.task_list,
                                             FLAGS.tasks_by_fingerprint,
                                             theorem_db, splits_to_prove,
                                             library_tags)
    # TODO(szegedy): Verify tasks that they all fit the theorem database(s)
    tf.logging.info('Number of prover tasks: %d', len(prover_tasks))
    return (prover_tasks, prover_options, FLAGS.output)