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)
def run_pipeline(examples_sstable: Optional[Text], scrub_parameters: Optional[Text], prover_tasks: List[proof_assistant_pb2.ProverTask], prover_options: deephol_pb2.ProverOptions, path_output: str): """Create and run simple prover pipeline.""" prover.cache_embeddings(prover_options) prover_pipeline = make_pipeline(prover_tasks, prover_options, path_output) pipeline = prover_pipeline if examples_sstable: theorem_db = io_util.load_theorem_database_from_file( str(prover_options.path_theorem_database)) def examples_pipeline(root): """Examples pipeline.""" scrub_str_enum_map = { 'NOTHING': options_pb2.ConvertorOptions.NOTHING, 'TESTING': options_pb2.ConvertorOptions.TESTING, 'VALIDATION_AND_TESTING': options_pb2.ConvertorOptions.VALIDATION_AND_TESTING, } training_examples_pipeline( proof_logs=prover_pipeline(root), tactics_filename=prover_options.path_tactics, theorem_db=theorem_db, examples_sstables=[examples_sstable], scrub_parameters=scrub_str_enum_map[scrub_parameters]) pipeline = examples_pipeline runner.Runner().run(pipeline).wait_until_finish()
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 compute_embeddings_for_thms_from_db_file(self, file_path: str) -> None: """Compute the embeddings for the theorems given in a test file. Args: file_path: Path to the text protobuf file containing the theorem database. """ tf.logging.info('Reading theorems database from "%s"', file_path) theorem_database = io_util.load_theorem_database_from_file(file_path) self.compute_embeddings_for_thms_from_db(theorem_database)
def test_compute_thm_embeddings_for_thms_from_file(self): store = self.store self.assertIsNone(store.thm_embeddings) file_path = test_util.test_src_dir_path(TEST_THEOREM_DB_PATH) store.compute_embeddings_for_thms_from_db_file(file_path) db = io_util.load_theorem_database_from_file(file_path) self.thms = _process_thms(db.theorems) self.assertAllClose(store.thm_embeddings, np.array([[thm.__hash__(), 1] for thm in self.thms]))
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)
def main(argv): if len(argv) > 1: raise ValueError('Too many command-line arguments.') if FLAGS.theorem_database is None: tf.logging.fatal('--theorem_database flag is required.') if FLAGS.proof_logs is None: tf.logging.fatal('--proof_logs flag is required.') theorem_db = io_util.load_theorem_database_from_file(FLAGS.theorem_database) proof_logs = io_util.read_protos(FLAGS.proof_logs, deephol_pb2.ProofLog) ocaml_code = proof_checker_lib.verify(proof_logs, theorem_db) with tf.gfile.Open(FLAGS.out_file, 'w') as f: f.write(ocaml_code) tf.logging.info('Proof checker successful.')
def __init__(self, lm: loop_meta.LoopMeta, config: loop_pb2.LoopConfig): self.loop_meta = lm self.config = config self.checkpoint_monitor = checkpoint_monitor.CheckpointMonitor( config.path_model_directory, self.loop_meta.checkpoints_path()) self.theorem_db = io_util.load_theorem_database_from_file( str(config.prover_options.path_theorem_database)) if not self.theorem_db.HasField('name'): self.theorem_db.name = 'default' tasks_file = None if config.HasField('prover_tasks_file'): tasks_file = config.prover_tasks_file self.prover_tasks = prover_util.get_task_list( tasks_file, None, None, self.theorem_db, config.prover_options.splits_to_prove, set(config.prover_options.library_tags)) logging.info('Number of tasks: %d', len(self.prover_tasks))