itp-interface 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- itp_interface/__init__.py +0 -0
- itp_interface/agent/__init__.py +0 -0
- itp_interface/agent/simple_proof_agent.py +100 -0
- itp_interface/coq_ser_api/__init__.py +165 -0
- itp_interface/coq_ser_api/contexts.py +283 -0
- itp_interface/coq_ser_api/coq_agent.py +459 -0
- itp_interface/coq_ser_api/coq_backend.py +135 -0
- itp_interface/coq_ser_api/coq_util.py +839 -0
- itp_interface/coq_ser_api/example.py +67 -0
- itp_interface/coq_ser_api/lsp_backend.py +375 -0
- itp_interface/coq_ser_api/py.typed +0 -0
- itp_interface/coq_ser_api/serapi_backend.py +841 -0
- itp_interface/coq_ser_api/util.py +145 -0
- itp_interface/coq_ser_api_old/__init__.py +2583 -0
- itp_interface/coq_ser_api_old/contexts.py +172 -0
- itp_interface/coq_ser_api_old/util.py +146 -0
- itp_interface/lean_server/__init__.py +0 -0
- itp_interface/lean_server/commands.py +484 -0
- itp_interface/lean_server/lean3_search_tool.py +358 -0
- itp_interface/lean_server/lean4_repl_interface.py +151 -0
- itp_interface/lean_server/lean4_utils.py +255 -0
- itp_interface/lean_server/lean_cmd_server.py +111 -0
- itp_interface/lean_server/lean_context.py +60 -0
- itp_interface/lean_server/lean_sync_server.py +174 -0
- itp_interface/lean_server/lean_utils.py +199 -0
- itp_interface/lean_server/py.typed +1 -0
- itp_interface/main/__init__.py +0 -0
- itp_interface/main/config/afp_data_gen.yaml +14 -0
- itp_interface/main/config/benchmark/CompCert.yaml +366 -0
- itp_interface/main/config/benchmark/GeoCoq.yaml +930 -0
- itp_interface/main/config/benchmark/UniMath.yaml +2690 -0
- itp_interface/main/config/benchmark/afp_isabelle.yaml +29200 -0
- itp_interface/main/config/benchmark/agent_proverbot_hard.yaml +247 -0
- itp_interface/main/config/benchmark/category-theory.yaml +470 -0
- itp_interface/main/config/benchmark/compcert_118_subset.yaml +148 -0
- itp_interface/main/config/benchmark/compcert_benchmark.yaml +36 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard.yaml +498 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_1.yaml +55 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_2.yaml +24 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_3.yaml +95 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_7_per_cent.yaml +78 -0
- itp_interface/main/config/benchmark/compcert_benchmark_test.yaml +38 -0
- itp_interface/main/config/benchmark/compcert_benchmark_train.yaml +340 -0
- itp_interface/main/config/benchmark/leandojo_novel_premises_test.yaml +2908 -0
- itp_interface/main/config/benchmark/leandojo_novel_premises_train.yaml +98645 -0
- itp_interface/main/config/benchmark/leandojo_novel_premises_val.yaml +2912 -0
- itp_interface/main/config/benchmark/leandojo_random.yaml +2889 -0
- itp_interface/main/config/benchmark/leandojo_random_test.yaml +2421 -0
- itp_interface/main/config/benchmark/leandojo_random_train.yaml +62729 -0
- itp_interface/main/config/benchmark/leandojo_random_val.yaml +2504 -0
- itp_interface/main/config/benchmark/math-comp.yaml +200 -0
- itp_interface/main/config/benchmark/miniF2F_test.yaml +12 -0
- itp_interface/main/config/benchmark/miniF2F_test_aime.yaml +27 -0
- itp_interface/main/config/benchmark/miniF2F_test_algebra.yaml +30 -0
- itp_interface/main/config/benchmark/miniF2F_test_amc12.yaml +57 -0
- itp_interface/main/config/benchmark/miniF2F_test_few_shot_hard.yaml +231 -0
- itp_interface/main/config/benchmark/miniF2F_test_imo.yaml +32 -0
- itp_interface/main/config/benchmark/miniF2F_test_induction.yaml +20 -0
- itp_interface/main/config/benchmark/miniF2F_test_mathd_algebra.yaml +82 -0
- itp_interface/main/config/benchmark/miniF2F_test_mathd_algebra_hard.yaml +72 -0
- itp_interface/main/config/benchmark/miniF2F_test_mathd_numbertheory.yaml +72 -0
- itp_interface/main/config/benchmark/miniF2F_test_numbertheory.yaml +20 -0
- itp_interface/main/config/benchmark/minicompcert_benchmark_1.yaml +14 -0
- itp_interface/main/config/benchmark/proverbot_hard.yaml +104 -0
- itp_interface/main/config/benchmark/re_prover.yaml +66 -0
- itp_interface/main/config/benchmark/re_prover_hard.yaml +41 -0
- itp_interface/main/config/benchmark/re_prover_very_hard.yaml +22 -0
- itp_interface/main/config/benchmark/reprover_with_retrieval.yaml +73 -0
- itp_interface/main/config/benchmark/reprover_with_retrieval_hard.yaml +30 -0
- itp_interface/main/config/benchmark/reprover_with_retrieval_neg.yaml +195 -0
- itp_interface/main/config/benchmark/simple_benchmark_1.yaml +24 -0
- itp_interface/main/config/benchmark/simple_benchmark_8.yaml +50 -0
- itp_interface/main/config/benchmark/simple_benchmark_9.yaml +65 -0
- itp_interface/main/config/benchmark/simple_benchmark_isabelle.yaml +18 -0
- itp_interface/main/config/benchmark/simple_benchmark_lean.yaml +12 -0
- itp_interface/main/config/benchmark/simple_benchmark_lean_training_data.yaml +12 -0
- itp_interface/main/config/benchmark/simple_rl_benchmark_lean.yaml +14 -0
- itp_interface/main/config/benchmark/stack_machine.yaml +13 -0
- itp_interface/main/config/benchmark/stack_machine_hard.yaml +15 -0
- itp_interface/main/config/category_theory_data_gen.yaml +14 -0
- itp_interface/main/config/category_theory_data_gen_random.yaml +16 -0
- itp_interface/main/config/compcert_data_gen_test.yaml +10 -0
- itp_interface/main/config/compcert_data_gen_train.yaml +7 -0
- itp_interface/main/config/env_settings/bm25_retrieval.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_no_dfns.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_only_local_no_dfns.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_with_print.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_with_print_only_local.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_with_print_only_local_no_dfns.yaml +2 -0
- itp_interface/main/config/env_settings/no_retrieval.yaml +2 -0
- itp_interface/main/config/experiments.yaml +12 -0
- itp_interface/main/config/geo_coq_data_gen.yaml +14 -0
- itp_interface/main/config/geo_coq_data_gen_random.yaml +16 -0
- itp_interface/main/config/leandojo_random_data_gen.yaml +16 -0
- itp_interface/main/config/math_comp_data_gen.yaml +14 -0
- itp_interface/main/config/math_comp_data_gen_random.yaml +16 -0
- itp_interface/main/config/mathlib_data_gen.yaml +14 -0
- itp_interface/main/config/repo/coq_repos.yaml +191 -0
- itp_interface/main/config/run_settings/default_coq_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/run_settings/default_isabelle_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/run_settings/default_lean4_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/run_settings/default_lean_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/simple_coq_data_gen.yaml +12 -0
- itp_interface/main/config/simple_coq_data_gen_random.yaml +17 -0
- itp_interface/main/config/simple_lean_data_gen.yaml +12 -0
- itp_interface/main/config/simple_rl_lean_data_gen.yaml +12 -0
- itp_interface/main/config/uni_math_data_gen.yaml +14 -0
- itp_interface/main/config.py +192 -0
- itp_interface/main/extract_benchmark_dataset.py +106 -0
- itp_interface/main/filter_dataset.py +107 -0
- itp_interface/main/install.py +92 -0
- itp_interface/main/merge_dataset.py +96 -0
- itp_interface/main/run_tool.py +444 -0
- itp_interface/pisa/.git +1 -0
- itp_interface/pisa/.gitignore +125 -0
- itp_interface/pisa/.idea/.gitignore +8 -0
- itp_interface/pisa/.idea/ClojureProjectResolveSettings.xml +6 -0
- itp_interface/pisa/.idea/codeStyles/Project.xml +7 -0
- itp_interface/pisa/.idea/codeStyles/codeStyleConfig.xml +5 -0
- itp_interface/pisa/.idea/inspectionProfiles/Project_Default.xml +16 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_android_annotations_4_1_1_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_api_grpc_proto_google_common_protos_1_17_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_code_findbugs_jsr305_3_0_2_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_code_gson_gson_2_8_6_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_errorprone_error_prone_annotations_2_3_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_guava_failureaccess_1_0_1_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_guava_guava_30_0_jre_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava_jar.xml +9 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_j2objc_j2objc_annotations_1_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_protobuf_protobuf_java_3_12_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_protobuf_protobuf_java_util_3_12_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_fastparse_2_13_2_3_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_geny_2_13_0_6_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_sourcecode_2_13_0_2_1_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_lenses_2_13_0_10_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_scalapb_runtime_2_13_0_10_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_scalapb_runtime_grpc_2_13_0_10_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_zio_grpc_zio_grpc_core_2_13_0_4_2_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thoughtworks_paranamer_paranamer_2_8_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__commons_io_commons_io_2_8_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__de_unruh_java_patterns_0_1_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__de_unruh_scala_isabelle_2_13_master_SNAPSHOT_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_izumi_reflect_2_13_1_0_0_M9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_izumi_reflect_thirdparty_boopickle_shaded_2_13_1_0_0_M9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_2_13_1_0_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_stacktracer_2_13_1_0_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_streams_2_13_1_0_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_api_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_context_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_core_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_netty_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_protobuf_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_protobuf_lite_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_services_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_stub_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_buffer_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_http2_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_http_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_socks_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_common_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_handler_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_handler_proxy_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_resolver_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_transport_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_perfmark_perfmark_api_0_19_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__net_java_dev_jna_jna_5_3_1_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__net_liftweb_lift_json_2_13_3_4_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_apache_commons_commons_lang3_3_11_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_apache_commons_commons_text_1_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_checkerframework_checker_qual_3_5_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_codehaus_mojo_animal_sniffer_annotations_1_18_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_jetbrains_annotations_20_1_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_jline_jline_3_16_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_log4s_log4s_2_13_1_9_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_modules_scala_collection_compat_2_13_2_1_6_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_modules_scala_xml_2_13_1_3_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_compiler_2_13_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_4_jar.xml +23 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_reflect_2_13_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scalap_2_13_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scalaz_scalaz_core_2_13_7_3_2_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_slf4j_slf4j_api_1_7_30_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_slf4j_slf4j_simple_1_7_30_jar.xml +13 -0
- itp_interface/pisa/.idea/misc.xml +7 -0
- itp_interface/pisa/.idea/modules/PISA-build.iml +127 -0
- itp_interface/pisa/.idea/modules/PISA.iml +94 -0
- itp_interface/pisa/.idea/modules.xml +9 -0
- itp_interface/pisa/.idea/other.xml +6 -0
- itp_interface/pisa/.idea/sbt.xml +20 -0
- itp_interface/pisa/.idea/scala_compiler.xml +6 -0
- itp_interface/pisa/.idea/uiDesigner.xml +124 -0
- itp_interface/pisa/.idea/vcs.xml +6 -0
- itp_interface/pisa/.scalafmt.conf +2 -0
- itp_interface/pisa/LICENSE +29 -0
- itp_interface/pisa/README.md +262 -0
- itp_interface/pisa/build.sbt +49 -0
- itp_interface/pisa/build.sh +26 -0
- itp_interface/pisa/command_generation/close_gaps.py +44 -0
- itp_interface/pisa/command_generation/conjecture_normal_order.py +62 -0
- itp_interface/pisa/command_generation/conjecturer_command_generator.py +36 -0
- itp_interface/pisa/command_generation/create_dirs.py +11 -0
- itp_interface/pisa/command_generation/find_std.py +67 -0
- itp_interface/pisa/command_generation/generate_build_commands_afp.py +15 -0
- itp_interface/pisa/command_generation/generate_build_commands_std.py +15 -0
- itp_interface/pisa/command_generation/generate_commands_afp.py +103 -0
- itp_interface/pisa/command_generation/generate_commands_mini.py +73 -0
- itp_interface/pisa/command_generation/generate_commands_std.py +69 -0
- itp_interface/pisa/command_generation/generate_hammer_extraction_text.py +5 -0
- itp_interface/pisa/command_generation/hammer_command_generator.py +40 -0
- itp_interface/pisa/command_generation/hp_search_command_generator.py +63 -0
- itp_interface/pisa/command_generation/oracle_command_generator.py +56 -0
- itp_interface/pisa/command_generation/search_command_generator.py +69 -0
- itp_interface/pisa/command_generation/summarise_problem_names.py +45 -0
- itp_interface/pisa/command_generation/tpu_hp_search.py +75 -0
- itp_interface/pisa/docker/Dockerfile +34 -0
- itp_interface/pisa/docker/docker_tutorial.md +64 -0
- itp_interface/pisa/eval_setup/copy_isabelle.py +42 -0
- itp_interface/pisa/eval_setup/copy_pisa_jars.py +18 -0
- itp_interface/pisa/mesh_transformer_utils/tokenization.py +86 -0
- itp_interface/pisa/project/build.properties +1 -0
- itp_interface/pisa/project/plugins.sbt +5 -0
- itp_interface/pisa/requirements.txt +4 -0
- itp_interface/pisa/scripts/extract_last_k_steps.py +28 -0
- itp_interface/pisa/scripts/extract_proof_corpus.py +26 -0
- itp_interface/pisa/scripts/gather_hammer_results.py +27 -0
- itp_interface/pisa/scripts/length_in_char_stats.py +20 -0
- itp_interface/pisa/scripts/mix.py +127 -0
- itp_interface/pisa/scripts/results_stat.py +52 -0
- itp_interface/pisa/scripts/test_array_job.sh +34 -0
- itp_interface/pisa/setup.sh +25 -0
- itp_interface/pisa/src/main/protobuf/server.proto +60 -0
- itp_interface/pisa/src/main/python/.idea/.gitignore +8 -0
- itp_interface/pisa/src/main/python/.idea/inspectionProfiles/Project_Default.xml +18 -0
- itp_interface/pisa/src/main/python/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- itp_interface/pisa/src/main/python/.idea/misc.xml +4 -0
- itp_interface/pisa/src/main/python/.idea/modules.xml +8 -0
- itp_interface/pisa/src/main/python/.idea/python.iml +12 -0
- itp_interface/pisa/src/main/python/.idea/vcs.xml +6 -0
- itp_interface/pisa/src/main/python/conjecturing_parsing/conjecturer_postprocessing.py +59 -0
- itp_interface/pisa/src/main/python/data_extraction/extract_data.py +184 -0
- itp_interface/pisa/src/main/python/data_extraction/find_premises.py +221 -0
- itp_interface/pisa/src/main/python/data_extraction/process_data.py +129 -0
- itp_interface/pisa/src/main/python/legacy/PisaFlexibleClient.py +167 -0
- itp_interface/pisa/src/main/python/legacy/autof_test.py +74 -0
- itp_interface/pisa/src/main/python/legacy/cmd_client.py +23 -0
- itp_interface/pisa/src/main/python/legacy/convert_scala_dump_to_test_name_jsons.py +14 -0
- itp_interface/pisa/src/main/python/legacy/create_data_txt.py +72 -0
- itp_interface/pisa/src/main/python/legacy/create_finetune_tfrecords.py +311 -0
- itp_interface/pisa/src/main/python/legacy/demo.py +49 -0
- itp_interface/pisa/src/main/python/legacy/evaluate.py +108 -0
- itp_interface/pisa/src/main/python/legacy/extract_first_step.py +25 -0
- itp_interface/pisa/src/main/python/legacy/get_global_facts.py +35 -0
- itp_interface/pisa/src/main/python/legacy/mix_data.py +19 -0
- itp_interface/pisa/src/main/python/legacy/one_stage_extraction.py +111 -0
- itp_interface/pisa/src/main/python/legacy/prepare_episodic_transitions.py +137 -0
- itp_interface/pisa/src/main/python/legacy/prepare_translation_pairs.py +277 -0
- itp_interface/pisa/src/main/python/pisa_client.py +322 -0
- itp_interface/pisa/src/main/python/server_pb2.py +394 -0
- itp_interface/pisa/src/main/python/server_pb2_grpc.py +230 -0
- itp_interface/pisa/src/main/python/test_client.py +17 -0
- itp_interface/pisa/src/main/python/test_client2.py +79 -0
- itp_interface/pisa/src/main/python/utils/filters.py +59 -0
- itp_interface/pisa/src/main/python/utils/pisa_server_control.py +29 -0
- itp_interface/pisa/src/main/scala/pisa/agent/CheckSyntax.scala +257 -0
- itp_interface/pisa/src/main/scala/pisa/agent/DepThms.scala +29 -0
- itp_interface/pisa/src/main/scala/pisa/agent/PisaStat.scala +46 -0
- itp_interface/pisa/src/main/scala/pisa/agent/RefactorTest.scala +40 -0
- itp_interface/pisa/src/main/scala/pisa/agent/RepHammer.scala +95 -0
- itp_interface/pisa/src/main/scala/pisa/server/HammFacts.scala +63 -0
- itp_interface/pisa/src/main/scala/pisa/server/PisaOS.scala +881 -0
- itp_interface/pisa/src/main/scala/pisa/server/PisaOneStage.scala +540 -0
- itp_interface/pisa/src/main/scala/pisa/server/PisaOneStageServers.scala +1048 -0
- itp_interface/pisa/src/main/scala/pisa/utils/TheoryManager.scala +95 -0
- itp_interface/pisa/src/test/python/analyse_debug.py +33 -0
- itp_interface/pisa/src/test/python/extract_test_seq2seq.py +53 -0
- itp_interface/pisa/src/test/python/extract_test_theorem_ground_truth_indices.py +31 -0
- itp_interface/pisa/src/test/python/proof_originality.py +24 -0
- itp_interface/pisa/src/test/python/test_command_generator.py +25 -0
- itp_interface/pisa/src/test/python/test_model_sequence_accuracy.py +70 -0
- itp_interface/pisa/src/test/scala/pisa/Easy.scala +26 -0
- itp_interface/pisa/src/test/scala/pisa/TestCurl.scala +82 -0
- itp_interface/pisa/src/test/scala/pisa/TestIsa.scala +27 -0
- itp_interface/pisa/test.sh +19 -0
- itp_interface/pisa/universal_test_theorems.tar.gz +0 -0
- itp_interface/repo/build.py +78 -0
- itp_interface/repo/clone.py +79 -0
- itp_interface/repo/dataset_discovery.py +99 -0
- itp_interface/retrieval/__init__.py +0 -0
- itp_interface/retrieval/abstraction.py +35 -0
- itp_interface/retrieval/coq_bm25_reranker.py +153 -0
- itp_interface/retrieval/isabelle_bm25_reranker.py +86 -0
- itp_interface/retrieval/lean3_bm25_reranker.py +86 -0
- itp_interface/rl/__init__.py +0 -0
- itp_interface/rl/abstraction.py +168 -0
- itp_interface/rl/proof_action.py +172 -0
- itp_interface/rl/proof_state.py +149 -0
- itp_interface/rl/proof_tree.py +109 -0
- itp_interface/rl/simpl_proof_env_pool.py +16 -0
- itp_interface/rl/simple_proof_env.py +713 -0
- itp_interface/rl/simple_proof_env_pool.py +591 -0
- itp_interface/scripts/setup.sh +228 -0
- itp_interface/tools/__init__.py +0 -0
- itp_interface/tools/basic_utils.py +172 -0
- itp_interface/tools/bin_packing.py +61 -0
- itp_interface/tools/cache.py +93 -0
- itp_interface/tools/coq_build_spec.py +31 -0
- itp_interface/tools/coq_build_tool.py +319 -0
- itp_interface/tools/coq_context_helper.py +354 -0
- itp_interface/tools/coq_executor.py +508 -0
- itp_interface/tools/coq_local_data_generation_transform.py +158 -0
- itp_interface/tools/coq_parse_utils.py +154 -0
- itp_interface/tools/coq_raw_proofs.py +193 -0
- itp_interface/tools/coq_theorem_proof_pair_generation_transform.py +146 -0
- itp_interface/tools/coq_training_data_generator.py +76 -0
- itp_interface/tools/dynamic_coq_proof_exec.py +220 -0
- itp_interface/tools/dynamic_isabelle_proof_exec.py +229 -0
- itp_interface/tools/dynamic_lean4_proof_exec.py +236 -0
- itp_interface/tools/dynamic_lean_proof_exec.py +228 -0
- itp_interface/tools/isabelle_context_helper.py +66 -0
- itp_interface/tools/isabelle_executor.py +862 -0
- itp_interface/tools/isabelle_local_data_generation_transform.py +149 -0
- itp_interface/tools/isabelle_parse_utils.py +131 -0
- itp_interface/tools/isabelle_server.py +106 -0
- itp_interface/tools/lean4_context_helper.py +72 -0
- itp_interface/tools/lean4_local_data_generation_transform.py +122 -0
- itp_interface/tools/lean4_sync_executor.py +1193 -0
- itp_interface/tools/lean_cmd_executor.py +804 -0
- itp_interface/tools/lean_context_helper.py +327 -0
- itp_interface/tools/lean_dojo_data_generation_transform.py +206 -0
- itp_interface/tools/lean_executor.py +687 -0
- itp_interface/tools/lean_local_data_generation_transform.py +136 -0
- itp_interface/tools/lean_parse_utils.py +32 -0
- itp_interface/tools/log_utils.py +20 -0
- itp_interface/tools/proof_exec_callback.py +76 -0
- itp_interface/tools/ray_utils.py +265 -0
- itp_interface/tools/repl/.git +1 -0
- itp_interface/tools/repl/.github/workflows/ci.yml +24 -0
- itp_interface/tools/repl/.gitignore +7 -0
- itp_interface/tools/repl/.vscode/copyright.code-snippets +13 -0
- itp_interface/tools/repl/.vscode/extensions.json +13 -0
- itp_interface/tools/repl/.vscode/module-docstring.code-snippets +35 -0
- itp_interface/tools/repl/.vscode/settings.json +11 -0
- itp_interface/tools/repl/README.md +174 -0
- itp_interface/tools/repl/REPL/Frontend.lean +47 -0
- itp_interface/tools/repl/REPL/JSON.lean +186 -0
- itp_interface/tools/repl/REPL/Lean/ContextInfo.lean +9 -0
- itp_interface/tools/repl/REPL/Lean/Environment.lean +31 -0
- itp_interface/tools/repl/REPL/Lean/InfoTree/ToJson.lean +114 -0
- itp_interface/tools/repl/REPL/Lean/InfoTree.lean +272 -0
- itp_interface/tools/repl/REPL/Main.lean +323 -0
- itp_interface/tools/repl/REPL/Snapshots.lean +306 -0
- itp_interface/tools/repl/REPL/Util/Path.lean +36 -0
- itp_interface/tools/repl/REPL/Util/Pickle.lean +44 -0
- itp_interface/tools/repl/REPL.lean +4 -0
- itp_interface/tools/repl/lake-manifest.json +5 -0
- itp_interface/tools/repl/lakefile.lean +15 -0
- itp_interface/tools/repl/lean-toolchain +1 -0
- itp_interface/tools/repl/test/Mathlib/.gitignore +5 -0
- itp_interface/tools/repl/test/Mathlib/H20231110.sh +2 -0
- itp_interface/tools/repl/test/Mathlib/ReplMathlibTests.lean +1 -0
- itp_interface/tools/repl/test/Mathlib/lake-manifest.json +68 -0
- itp_interface/tools/repl/test/Mathlib/lakefile.lean +11 -0
- itp_interface/tools/repl/test/Mathlib/lean-toolchain +1 -0
- itp_interface/tools/repl/test/Mathlib/test/20240209.expected.out +20 -0
- itp_interface/tools/repl/test/Mathlib/test/20240209.in +3 -0
- itp_interface/tools/repl/test/Mathlib/test/20240209.lean +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231020.expected.out +8 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231020.in +8 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231020.lean +22 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231110.expected.out +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231110.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115.expected.out +19 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115.in +5 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_2.expected.out +18 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_2.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_3.expected.out +10 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_3.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231214.in +9 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231214.lean +30 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215.expected.out +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215_2.expected.out +14 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215_2.in +3 -0
- itp_interface/tools/repl/test/Mathlib/test/exact.expected.out +37 -0
- itp_interface/tools/repl/test/Mathlib/test/exact.in +10 -0
- itp_interface/tools/repl/test/Mathlib/test/import_Mathlib.lean +1 -0
- itp_interface/tools/repl/test/Mathlib/test/induction.expected.out +29 -0
- itp_interface/tools/repl/test/Mathlib/test/induction.in +10 -0
- itp_interface/tools/repl/test/Mathlib/test/induction.lean +6 -0
- itp_interface/tools/repl/test/Mathlib/test/on_goal.expected.out +22 -0
- itp_interface/tools/repl/test/Mathlib/test/on_goal.in +5 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle.expected.out +16 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle.in +6 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle_2.expected.out +4 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle_2.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test.sh +41 -0
- itp_interface/tools/repl/test/all_tactics.expected.out +13 -0
- itp_interface/tools/repl/test/all_tactics.in +1 -0
- itp_interface/tools/repl/test/by_cases.expected.out +25 -0
- itp_interface/tools/repl/test/by_cases.in +8 -0
- itp_interface/tools/repl/test/by_cases.lean +4 -0
- itp_interface/tools/repl/test/calc.expected.out +32 -0
- itp_interface/tools/repl/test/calc.in +1 -0
- itp_interface/tools/repl/test/def_eval.expected.out +9 -0
- itp_interface/tools/repl/test/def_eval.in +3 -0
- itp_interface/tools/repl/test/enableInitializersExecution.expected.out +2 -0
- itp_interface/tools/repl/test/enableInitializersExecution.in +1 -0
- itp_interface/tools/repl/test/file.expected.out +8 -0
- itp_interface/tools/repl/test/file.in +1 -0
- itp_interface/tools/repl/test/file.lean +5 -0
- itp_interface/tools/repl/test/have_by_sorry.expected.out +28 -0
- itp_interface/tools/repl/test/have_by_sorry.in +6 -0
- itp_interface/tools/repl/test/import_lean.in +1 -0
- itp_interface/tools/repl/test/incomplete.expected.out +18 -0
- itp_interface/tools/repl/test/incomplete.in +3 -0
- itp_interface/tools/repl/test/incomplete.lean +0 -0
- itp_interface/tools/repl/test/infotree.expected.out +20 -0
- itp_interface/tools/repl/test/infotree.in +2 -0
- itp_interface/tools/repl/test/invalid_tactic.expected.out +20 -0
- itp_interface/tools/repl/test/invalid_tactic.in +3 -0
- itp_interface/tools/repl/test/name_generator.expected.out +53 -0
- itp_interface/tools/repl/test/name_generator.in +18 -0
- itp_interface/tools/repl/test/no_goal_sorry.expected.out +11 -0
- itp_interface/tools/repl/test/no_goal_sorry.in +1 -0
- itp_interface/tools/repl/test/no_goal_sorry_2.expected.out +12 -0
- itp_interface/tools/repl/test/no_goal_sorry_2.in +1 -0
- itp_interface/tools/repl/test/options.expected.out +17 -0
- itp_interface/tools/repl/test/options.in +6 -0
- itp_interface/tools/repl/test/pickle_environment.expected.out +8 -0
- itp_interface/tools/repl/test/pickle_environment.in +7 -0
- itp_interface/tools/repl/test/pickle_environment_with_imports.expected.out +10 -0
- itp_interface/tools/repl/test/pickle_environment_with_imports.in +9 -0
- itp_interface/tools/repl/test/pickle_open.expected.out +8 -0
- itp_interface/tools/repl/test/pickle_open.in +7 -0
- itp_interface/tools/repl/test/pickle_open_2.expected.out +4 -0
- itp_interface/tools/repl/test/pickle_open_2.in +3 -0
- itp_interface/tools/repl/test/pickle_open_scoped.expected.out +18 -0
- itp_interface/tools/repl/test/pickle_open_scoped.in +8 -0
- itp_interface/tools/repl/test/pickle_open_scoped_2.expected.out +14 -0
- itp_interface/tools/repl/test/pickle_open_scoped_2.in +3 -0
- itp_interface/tools/repl/test/pickle_proof_state_1.expected.out +26 -0
- itp_interface/tools/repl/test/pickle_proof_state_1.in +15 -0
- itp_interface/tools/repl/test/pickle_proof_state_2.expected.out +4 -0
- itp_interface/tools/repl/test/pickle_proof_state_2.in +3 -0
- itp_interface/tools/repl/test/pickle_proof_state_env.expected.out +26 -0
- itp_interface/tools/repl/test/pickle_proof_state_env.in +15 -0
- itp_interface/tools/repl/test/pickle_scoped_notation.in +16 -0
- itp_interface/tools/repl/test/pickle_scoped_notation_2.in +3 -0
- itp_interface/tools/repl/test/proof_step.expected.out +18 -0
- itp_interface/tools/repl/test/proof_step.in +7 -0
- itp_interface/tools/repl/test/readme.expected.out +16 -0
- itp_interface/tools/repl/test/readme.in +5 -0
- itp_interface/tools/repl/test/sorry_hypotheses.expected.out +16 -0
- itp_interface/tools/repl/test/sorry_hypotheses.in +4 -0
- itp_interface/tools/repl/test/synthesize_placeholder.expected.out +7 -0
- itp_interface/tools/repl/test/synthesize_placeholder.in +1 -0
- itp_interface/tools/repl/test/tactic_mode_sorry.expected.out +14 -0
- itp_interface/tools/repl/test/tactic_mode_sorry.in +3 -0
- itp_interface/tools/repl/test/tactic_sorry.expected.out +12 -0
- itp_interface/tools/repl/test/tactic_sorry.in +1 -0
- itp_interface/tools/repl/test/term_sorry.expected.out +12 -0
- itp_interface/tools/repl/test/term_sorry.in +1 -0
- itp_interface/tools/repl/test/trace_simp.expected.out +41 -0
- itp_interface/tools/repl/test/trace_simp.in +15 -0
- itp_interface/tools/repl/test/unfinished_tactic_block.expected.out +11 -0
- itp_interface/tools/repl/test/unfinished_tactic_block.in +1 -0
- itp_interface/tools/repl/test/unknown_environment.expected.out +2 -0
- itp_interface/tools/repl/test/unknown_environment.in +1 -0
- itp_interface/tools/repl/test/unknown_proof_state.expected.out +14 -0
- itp_interface/tools/repl/test/unknown_proof_state.in +3 -0
- itp_interface/tools/repl/test/unknown_tactic.expected.out +14 -0
- itp_interface/tools/repl/test/unknown_tactic.in +3 -0
- itp_interface/tools/repl/test/variables.expected.out +26 -0
- itp_interface/tools/repl/test/variables.in +5 -0
- itp_interface/tools/repl/test.sh +43 -0
- itp_interface/tools/run_data_generation_transforms.py +350 -0
- itp_interface/tools/theorem_details.py +25 -0
- itp_interface/tools/training_data.py +358 -0
- itp_interface/tools/training_data_format.py +599 -0
- itp_interface-1.0.0.dist-info/METADATA +78 -0
- itp_interface-1.0.0.dist-info/RECORD +485 -0
- itp_interface-1.0.0.dist-info/WHEEL +4 -0
- itp_interface-1.0.0.dist-info/entry_points.txt +3 -0
- itp_interface-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
root_dir = f"{__file__.split('itp_interface')[0]}"
|
|
6
|
+
if root_dir not in sys.path:
|
|
7
|
+
sys.path.append(root_dir)
|
|
8
|
+
import typing
|
|
9
|
+
|
|
10
|
+
class CoqLineByLineReader:
|
|
11
|
+
def __init__(self, file_name: str = None, file_content: str = None):
|
|
12
|
+
assert file_name is not None or file_content is not None, "Either file_name or file_content must be provided"
|
|
13
|
+
assert file_name is None or file_content is None, "Only one of file_name or file_content must be provided"
|
|
14
|
+
self.file_name : str = file_name
|
|
15
|
+
self.file_content : str = file_content
|
|
16
|
+
if self.file_name is not None:
|
|
17
|
+
with open(file_name, 'r') as fd:
|
|
18
|
+
self.file_content : str = fd.read()
|
|
19
|
+
self.remove_comments()
|
|
20
|
+
|
|
21
|
+
def remove_comments(self):
|
|
22
|
+
CODE_MODE = 0
|
|
23
|
+
COMMENT_MODE = 1
|
|
24
|
+
idx = 0
|
|
25
|
+
mode = CODE_MODE
|
|
26
|
+
code_without_comments = []
|
|
27
|
+
comment_stack = []
|
|
28
|
+
while idx < len(self.file_content):
|
|
29
|
+
ch = self.file_content[idx]
|
|
30
|
+
if mode == CODE_MODE and ch == '(' and idx + 1 < len(self.file_content) and self.file_content[idx + 1] == '*':
|
|
31
|
+
mode = COMMENT_MODE
|
|
32
|
+
idx += 2
|
|
33
|
+
comment_stack.append("(*")
|
|
34
|
+
elif mode == COMMENT_MODE and ch == '(' and idx + 1 < len(self.file_content) and self.file_content[idx + 1] == '*':
|
|
35
|
+
mode = COMMENT_MODE
|
|
36
|
+
idx += 2
|
|
37
|
+
comment_stack.append("(*") # Start of nested comment
|
|
38
|
+
elif mode == COMMENT_MODE and ch == '*' and idx + 1 < len(self.file_content) and self.file_content[idx + 1] == ')':
|
|
39
|
+
comment_stack.pop()
|
|
40
|
+
if len(comment_stack) == 0:
|
|
41
|
+
mode = CODE_MODE
|
|
42
|
+
else:
|
|
43
|
+
assert comment_stack[-1] == "(*", "Comment stack should only contain '(*'"
|
|
44
|
+
mode = COMMENT_MODE # There is some nested comment still open
|
|
45
|
+
idx += 2
|
|
46
|
+
elif mode == COMMENT_MODE:
|
|
47
|
+
mode = COMMENT_MODE
|
|
48
|
+
idx += 1
|
|
49
|
+
elif mode == CODE_MODE:
|
|
50
|
+
code_without_comments.append(ch)
|
|
51
|
+
idx += 1
|
|
52
|
+
else:
|
|
53
|
+
raise Exception("Unknown mode")
|
|
54
|
+
self.file_content = "".join(code_without_comments)
|
|
55
|
+
|
|
56
|
+
def instruction_step_generator(self) -> typing.Iterator[str]:
|
|
57
|
+
CODE_MODE = 0
|
|
58
|
+
CODE_QT_MODE = 1
|
|
59
|
+
all_code = self.file_content
|
|
60
|
+
idx = 0
|
|
61
|
+
mode = CODE_MODE
|
|
62
|
+
instr_start = 0
|
|
63
|
+
special_context_starting_chars = ["+", "-", "*", "{", "}"]
|
|
64
|
+
while idx < len(all_code):
|
|
65
|
+
ch = all_code[idx]
|
|
66
|
+
if mode == CODE_MODE and ch == '.' and idx + 1 < len(all_code) and len(all_code[idx + 1].strip()) == 0:
|
|
67
|
+
code_to_yield = all_code[instr_start: idx + 1].strip()
|
|
68
|
+
contexts = []
|
|
69
|
+
context = ""
|
|
70
|
+
while any([code_to_yield.startswith(ctx) for ctx in special_context_starting_chars]):
|
|
71
|
+
context += code_to_yield[0]
|
|
72
|
+
if len(context) >= 2 and context[-2] != context[-1]:
|
|
73
|
+
# Split the context
|
|
74
|
+
contexts.append(context[:-1])
|
|
75
|
+
context = context[-1]
|
|
76
|
+
code_to_yield = code_to_yield[1:].strip()
|
|
77
|
+
if len(code_to_yield) == 0:
|
|
78
|
+
break
|
|
79
|
+
if len(context) > 0:
|
|
80
|
+
contexts.append(context) # Add the last context if it was missed
|
|
81
|
+
for ctx in contexts:
|
|
82
|
+
yield ctx.strip()
|
|
83
|
+
code_to_yield = code_to_yield.strip()
|
|
84
|
+
if len(code_to_yield) > 0:
|
|
85
|
+
yield code_to_yield
|
|
86
|
+
idx += 1
|
|
87
|
+
mode = CODE_MODE
|
|
88
|
+
instr_start = idx
|
|
89
|
+
elif mode == CODE_MODE and ch == '.' and idx + 1 == len(all_code):
|
|
90
|
+
code_to_yield = all_code[instr_start: idx + 1].strip()
|
|
91
|
+
contexts = []
|
|
92
|
+
context = ""
|
|
93
|
+
while any([code_to_yield.startswith(ctx) for ctx in special_context_starting_chars]):
|
|
94
|
+
context += code_to_yield[0]
|
|
95
|
+
if len(context) >= 2 and context[-2] != context[-1]:
|
|
96
|
+
# Split the context
|
|
97
|
+
contexts.append(context[:-1])
|
|
98
|
+
context = context[-1]
|
|
99
|
+
code_to_yield = code_to_yield[1:].strip()
|
|
100
|
+
if len(code_to_yield) == 0:
|
|
101
|
+
break
|
|
102
|
+
code_to_yield = code_to_yield.strip()
|
|
103
|
+
if len(context) > 0:
|
|
104
|
+
contexts.append(context) # Add the last context if it was missed
|
|
105
|
+
for ctx in contexts:
|
|
106
|
+
yield ctx.strip()
|
|
107
|
+
if len(code_to_yield) > 0:
|
|
108
|
+
yield code_to_yield
|
|
109
|
+
idx += 1
|
|
110
|
+
mode = CODE_MODE
|
|
111
|
+
instr_start = idx
|
|
112
|
+
elif mode == CODE_MODE and ch == "\"":
|
|
113
|
+
idx += 1
|
|
114
|
+
mode = CODE_QT_MODE
|
|
115
|
+
elif mode == CODE_QT_MODE and ch == "\"" and idx + 1 < len(all_code) and all_code[idx + 1] == "\"":
|
|
116
|
+
idx += 1
|
|
117
|
+
mode = CODE_QT_MODE
|
|
118
|
+
elif mode == CODE_QT_MODE and ch == "\"":
|
|
119
|
+
idx += 1
|
|
120
|
+
mode = CODE_MODE
|
|
121
|
+
elif mode == CODE_MODE:
|
|
122
|
+
mode = CODE_MODE
|
|
123
|
+
idx += 1
|
|
124
|
+
elif mode == CODE_QT_MODE:
|
|
125
|
+
mode = CODE_QT_MODE
|
|
126
|
+
idx += 1
|
|
127
|
+
# instruction start doesn't change
|
|
128
|
+
else:
|
|
129
|
+
raise Exception("This case is not possible")
|
|
130
|
+
if instr_start < len(all_code):
|
|
131
|
+
yield all_code[instr_start:].strip()
|
|
132
|
+
|
|
133
|
+
class CoqStepByStepStdInReader:
|
|
134
|
+
def __init__(self):
|
|
135
|
+
pass
|
|
136
|
+
|
|
137
|
+
def instruction_step_generator(self) -> typing.Iterator[str]:
|
|
138
|
+
while True:
|
|
139
|
+
try:
|
|
140
|
+
line = input()
|
|
141
|
+
if line == "(* exit *)":
|
|
142
|
+
break
|
|
143
|
+
yield line.strip() # Keep going line by line
|
|
144
|
+
except EOFError:
|
|
145
|
+
break
|
|
146
|
+
|
|
147
|
+
if __name__ == "__main__":
|
|
148
|
+
file_content = """
|
|
149
|
+
{reflexivity. }
|
|
150
|
+
"""
|
|
151
|
+
coq_reader = CoqLineByLineReader(file_content=file_content)
|
|
152
|
+
assert coq_reader.file_content is not None
|
|
153
|
+
for idx, instruction in enumerate(coq_reader.instruction_step_generator()):
|
|
154
|
+
print(f"[{idx}]: {instruction}")
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
root_dir = f"{__file__.split('itp_interface')[0]}"
|
|
6
|
+
if root_dir not in sys.path:
|
|
7
|
+
sys.path.append(root_dir)
|
|
8
|
+
import logging
|
|
9
|
+
import os
|
|
10
|
+
import typing
|
|
11
|
+
import ray
|
|
12
|
+
from itp_interface.tools.ray_utils import RayUtils
|
|
13
|
+
from itp_interface.tools.coq_parse_utils import CoqLineByLineReader
|
|
14
|
+
from itp_interface.tools.training_data_format import Goal, TrainingDataFormat, TrainingDataMetadataFormat
|
|
15
|
+
from itp_interface.tools.training_data import TrainingData
|
|
16
|
+
from itp_interface.tools.proof_exec_callback import ProofExecutorCallback
|
|
17
|
+
from itp_interface.tools.coq_build_tool import CoqRepoBuilder
|
|
18
|
+
|
|
19
|
+
def extract_raw_proof(file_content: str, lemma_name: str) -> TrainingDataFormat:
|
|
20
|
+
# Find the first occurence of the lemma_name and then find the first occurence of "Qed."
|
|
21
|
+
# The proof is the text between the two
|
|
22
|
+
start_index = file_content.find(lemma_name)
|
|
23
|
+
assert start_index != -1, f"Lemma {lemma_name} not found in file"
|
|
24
|
+
end_index = file_content.find("Qed.", start_index)
|
|
25
|
+
assert end_index != -1, f"Lemma {lemma_name} does not have a proof"
|
|
26
|
+
lemma_proof = file_content[start_index:end_index + len("Qed.")]
|
|
27
|
+
line_reader = CoqLineByLineReader(file_content=lemma_proof)
|
|
28
|
+
# Just read the first line
|
|
29
|
+
statement = next(line_reader.instruction_step_generator())
|
|
30
|
+
# Find the next occurence of '.' after the statement which is not in a comment or quotation
|
|
31
|
+
next_dot_index = lemma_proof.find(".", len(statement) - 1) # This may not always work but it is good enough for now
|
|
32
|
+
assert next_dot_index != -1, f"Lemma {lemma_name} does not have a statement"
|
|
33
|
+
proof = lemma_proof[next_dot_index + 1:]
|
|
34
|
+
goal = Goal(goal=statement)
|
|
35
|
+
training_data = TrainingDataFormat(start_goals=[goal], end_goals=[], proof_steps=[proof])
|
|
36
|
+
return training_data
|
|
37
|
+
|
|
38
|
+
@ray.remote
|
|
39
|
+
def get_proofs_in_file(coq_proof_exec_callback: ProofExecutorCallback, file_content: str, file_path: str) -> typing.List[TrainingDataFormat]:
|
|
40
|
+
training_data_collection : typing.List[TrainingDataFormat] = []
|
|
41
|
+
failures = []
|
|
42
|
+
with coq_proof_exec_callback.get_proof_executor() as main_executor:
|
|
43
|
+
while not main_executor.execution_complete:
|
|
44
|
+
assert not main_executor.is_in_proof_mode(), "main_executor must not be in proof mode"
|
|
45
|
+
_ = list(main_executor.run_till_next_lemma_return_exec_stmt())
|
|
46
|
+
if main_executor.execution_complete:
|
|
47
|
+
break
|
|
48
|
+
lemma_name = main_executor.get_lemma_name_if_running()
|
|
49
|
+
if lemma_name is None:
|
|
50
|
+
_ = list(main_executor.run_to_finish_lemma_return_exec())
|
|
51
|
+
|
|
52
|
+
if main_executor.execution_complete:
|
|
53
|
+
break
|
|
54
|
+
else:
|
|
55
|
+
try:
|
|
56
|
+
tdf = extract_raw_proof(file_content, lemma_name)
|
|
57
|
+
training_data_collection.append(tdf)
|
|
58
|
+
main_executor.run_to_finish_lemma()
|
|
59
|
+
except Exception:
|
|
60
|
+
print(f"Failed to extract proof for lemma {lemma_name} in {file_path}")
|
|
61
|
+
_ = list(main_executor.run_to_finish_lemma_return_exec())
|
|
62
|
+
failures.append(lemma_name)
|
|
63
|
+
continue
|
|
64
|
+
return file_path, training_data_collection, failures
|
|
65
|
+
|
|
66
|
+
def dump_raw_proofs(repo_builder: CoqRepoBuilder, output_dir: str, logger: logging.Logger):
|
|
67
|
+
assert os.path.exists(output_dir), f"output_dir {output_dir} does not exist"
|
|
68
|
+
RayUtils.init_ray(num_of_cpus=20, object_store_memory_in_gb=100, memory_in_gb=1)
|
|
69
|
+
projects = repo_builder.compilable_projects
|
|
70
|
+
|
|
71
|
+
def _log_proof_cnt(file_type: str, proof_cnt_in_file: int, file_path: str, failures: typing.List[str]):
|
|
72
|
+
logger.info(f"==============================>[{file_type}] Added proofs {proof_cnt_in_file} in {file_path} <==============================")
|
|
73
|
+
if len(failures) > 0:
|
|
74
|
+
logger.info(f"==============================>[{file_type}] Failed to extract proofs for {len(failures)} lemmas in {file_path} <==============================")
|
|
75
|
+
for lemma_name in failures:
|
|
76
|
+
logger.info(f"==============================>[{file_type}] Failed to extract proof for lemma {lemma_name} in {file_path} <==============================")
|
|
77
|
+
|
|
78
|
+
def _get_next_files_callback(files):
|
|
79
|
+
_idx = 0
|
|
80
|
+
sorted_files = sorted(files)
|
|
81
|
+
def _get_files(cnt: int):
|
|
82
|
+
nonlocal _idx
|
|
83
|
+
file_input = []
|
|
84
|
+
for file_path in sorted_files[_idx:_idx + cnt]:
|
|
85
|
+
if file_path.startswith(project_path):
|
|
86
|
+
with open(file_path, 'r') as fd:
|
|
87
|
+
file_content = fd.read()
|
|
88
|
+
coq_proof_exec_callback = ProofExecutorCallback(
|
|
89
|
+
project_folder=project_path,
|
|
90
|
+
file_path=file_path,
|
|
91
|
+
use_hammer=False,
|
|
92
|
+
timeout_in_secs=60,
|
|
93
|
+
use_human_readable_proof_context=True,
|
|
94
|
+
suppress_error_log=True,
|
|
95
|
+
logger=logger)
|
|
96
|
+
file_input.append((coq_proof_exec_callback, file_content, file_path))
|
|
97
|
+
_idx += cnt
|
|
98
|
+
return file_input
|
|
99
|
+
return _get_files
|
|
100
|
+
|
|
101
|
+
def _get_file_op_remotes_callback(file_inputs):
|
|
102
|
+
return [get_proofs_in_file.remote(coq_proof_exec_callback, file_content, file_path) for coq_proof_exec_callback, file_content, file_path in file_inputs]
|
|
103
|
+
|
|
104
|
+
def _transform_outputs_callback(training_data: TrainingData, file_type: str):
|
|
105
|
+
def _transform_outputs(results: typing.List[typing.List[TrainingDataFormat]]):
|
|
106
|
+
for file_path, training_data_collection, failures in results:
|
|
107
|
+
for tdf in training_data_collection:
|
|
108
|
+
training_data.merge(tdf)
|
|
109
|
+
_log_proof_cnt(file_type, len(training_data_collection), file_path, failures)
|
|
110
|
+
return _transform_outputs
|
|
111
|
+
|
|
112
|
+
for project in sorted(projects):
|
|
113
|
+
project_proof_cnt = 0
|
|
114
|
+
# Create temporary directory for each project
|
|
115
|
+
logger.info(f"==============================> Discovering files in project {project}<==============================")
|
|
116
|
+
project_path = os.path.join(repo_builder.root, project)
|
|
117
|
+
assert os.path.exists(project_path), f"project_path {project_path} does not exist"
|
|
118
|
+
files_type_map = {
|
|
119
|
+
"train": repo_builder.train_compilable_files,
|
|
120
|
+
"test": repo_builder.test_compilable_files,
|
|
121
|
+
}
|
|
122
|
+
for file_type, files in files_type_map.items():
|
|
123
|
+
output_path = os.path.join(output_dir, project, file_type)
|
|
124
|
+
os.makedirs(output_path, exist_ok=True)
|
|
125
|
+
training_metadata = TrainingDataMetadataFormat(training_data_buffer_size=2500, data_filename_prefix="single_data_", lemma_ref_filename_prefix="single_lemma_ref_")
|
|
126
|
+
training_data = TrainingData(output_path, "single.meta.json", training_metadata)
|
|
127
|
+
RayUtils.ray_run_within_parallel_limits(
|
|
128
|
+
10,
|
|
129
|
+
len(files),
|
|
130
|
+
_transform_outputs_callback(training_data, file_type),
|
|
131
|
+
_get_next_files_callback(files),
|
|
132
|
+
_get_file_op_remotes_callback,
|
|
133
|
+
logger=logger,
|
|
134
|
+
turn_off_logging=True)
|
|
135
|
+
logger.info(f"[{file_type}] Saving training data to {output_path}")
|
|
136
|
+
save_folder = training_data.save()
|
|
137
|
+
logger.info(f"[{file_type}] Saved training data to {save_folder}")
|
|
138
|
+
project_proof_cnt += len(training_data)
|
|
139
|
+
logger.info(f"==============================>[{file_type}] Added all {len(training_data)} proofs in project {project}<==============================")
|
|
140
|
+
logger.info(f"==============================> Added {project_proof_cnt} proofs in project {project}<==============================")
|
|
141
|
+
logger.info(f"==============================> Added proofs in all projects<==============================")
|
|
142
|
+
|
|
143
|
+
def count_proofs(repo_builder: CoqRepoBuilder, logger: logging.Logger):
|
|
144
|
+
proof_cnt = 0
|
|
145
|
+
projects = repo_builder.compilable_projects
|
|
146
|
+
for project in sorted(projects):
|
|
147
|
+
project_proof_cnt = 0
|
|
148
|
+
# Create temporary directory for each project
|
|
149
|
+
logger.info(f"==============================> Discovering files in project {project}<==============================")
|
|
150
|
+
project_path = os.path.join(repo_builder.root, project)
|
|
151
|
+
assert os.path.exists(project_path), f"project_path {project_path} does not exist"
|
|
152
|
+
files_type_map = {
|
|
153
|
+
"train": repo_builder.train_compilable_files,
|
|
154
|
+
"test": repo_builder.test_compilable_files,
|
|
155
|
+
}
|
|
156
|
+
for file_type, files in files_type_map.items():
|
|
157
|
+
file_type_cnt = 0
|
|
158
|
+
for file_path in sorted(files):
|
|
159
|
+
current_proof_cnt = 0
|
|
160
|
+
if file_path.startswith(project_path):
|
|
161
|
+
with open(file_path, 'r') as fd:
|
|
162
|
+
file_content = fd.read()
|
|
163
|
+
current_proof_cnt = file_content.count("Qed.")
|
|
164
|
+
logger.info(f"==============================>[{file_type}] Found {current_proof_cnt} proofs in file {file_path}<==============================")
|
|
165
|
+
proof_cnt += current_proof_cnt
|
|
166
|
+
file_type_cnt += current_proof_cnt
|
|
167
|
+
project_proof_cnt += current_proof_cnt
|
|
168
|
+
logger.info(f"==============================>[{file_type}] Found {file_type_cnt} proofs in project {project}<==============================")
|
|
169
|
+
logger.info(f"==============================> Found {project_proof_cnt} proofs in project {project}<==============================")
|
|
170
|
+
logger.info(f"==============================> Found {proof_cnt} proofs in all projects<==============================")
|
|
171
|
+
|
|
172
|
+
if __name__ == "__main__":
|
|
173
|
+
import time
|
|
174
|
+
import argparse
|
|
175
|
+
os.chdir(root_dir)
|
|
176
|
+
current_time = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
|
|
177
|
+
logging_dir = f".log/tools/coq_raw_proofs/{current_time}"
|
|
178
|
+
os.makedirs(logging_dir, exist_ok=True)
|
|
179
|
+
log_file = f"{os.path.join(logging_dir, f'coq_raw_proofs.log')}"
|
|
180
|
+
logging.basicConfig(filename=log_file, filemode='w', level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
181
|
+
logger = logging.getLogger("ProofCounter")
|
|
182
|
+
logger.info(f"Process ID: {os.getpid()}")
|
|
183
|
+
repo_builder = CoqRepoBuilder(root_dir)
|
|
184
|
+
parser = argparse.ArgumentParser()
|
|
185
|
+
parser.add_argument("--info_file", type=str, default="data/test/coq/custom_group_theory/compilable_projects_info.log.json", help="The file which will have the info about the compilable projects")
|
|
186
|
+
parser.add_argument("--output_dir", type=str, default=".log/tools/coq_raw_proofs/data/test/coq/custom_group_theory", help="The directory where the raw proofs will be dumped")
|
|
187
|
+
args = parser.parse_args()
|
|
188
|
+
info_file = args.info_file
|
|
189
|
+
repo_builder : CoqRepoBuilder = CoqRepoBuilder.load_from_file(info_file)
|
|
190
|
+
output_dir = os.path.join(args.output_dir, current_time)
|
|
191
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
192
|
+
# count_proofs(repo_builder, logger)
|
|
193
|
+
dump_raw_proofs(repo_builder, output_dir, logger)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
root_dir = f"{__file__.split('itp_interface')[0]}"
|
|
6
|
+
if root_dir not in sys.path:
|
|
7
|
+
sys.path.append(root_dir)
|
|
8
|
+
|
|
9
|
+
import typing
|
|
10
|
+
from itp_interface.tools.coq_context_helper import CoqContextHelper
|
|
11
|
+
from itp_interface.tools.coq_training_data_generator import GenericTrainingDataGenerationTransform, TrainingDataGenerationType
|
|
12
|
+
from itp_interface.tools.training_data_format import Goal, MergableCollection, TrainingDataMetadataFormat, TrainingDataCollection, TrainingDataFormat
|
|
13
|
+
from itp_interface.tools.coq_executor import CoqExecutor
|
|
14
|
+
from itp_interface.tools.training_data import TrainingData
|
|
15
|
+
|
|
16
|
+
class LocalTheoremProofPairGenerationTransform(GenericTrainingDataGenerationTransform):
|
|
17
|
+
def __init__(self,
|
|
18
|
+
depth = None,
|
|
19
|
+
max_search_results = None,
|
|
20
|
+
buffer_size : int = 10000,
|
|
21
|
+
logger = None,
|
|
22
|
+
max_parallelism : int = 4):
|
|
23
|
+
super().__init__(TrainingDataGenerationType.LOCAL, buffer_size, logger)
|
|
24
|
+
self.depth = depth
|
|
25
|
+
self.max_search_results = max_search_results
|
|
26
|
+
self.max_parallelism = max_parallelism
|
|
27
|
+
|
|
28
|
+
def get_meta_object(self) -> MergableCollection:
|
|
29
|
+
return TrainingDataMetadataFormat(training_data_buffer_size=self.buffer_size)
|
|
30
|
+
|
|
31
|
+
def get_data_collection_object(self) -> MergableCollection:
|
|
32
|
+
return TrainingDataCollection()
|
|
33
|
+
|
|
34
|
+
def load_meta_from_file(self, file_path) -> MergableCollection:
|
|
35
|
+
return TrainingDataMetadataFormat.load_from_file(file_path)
|
|
36
|
+
|
|
37
|
+
def load_data_from_file(self, file_path) -> MergableCollection:
|
|
38
|
+
return TrainingDataCollection.load_from_file(file_path, self.logger)
|
|
39
|
+
|
|
40
|
+
def __call__(self, training_data: TrainingData, project_id : str, coq_executor: CoqExecutor, print_coq_executor_callback: typing.Callable[[], CoqExecutor]) -> TrainingData:
|
|
41
|
+
print_coq_executor = print_coq_executor_callback()
|
|
42
|
+
coq_context_helper = CoqContextHelper(print_coq_executor, self.depth, self.logger)
|
|
43
|
+
coq_context_helper.__enter__()
|
|
44
|
+
file_namespace = coq_executor.main_file.replace('/', '.')
|
|
45
|
+
self.logger.info(f"=========================Processing {file_namespace}=========================")
|
|
46
|
+
proof_running = False
|
|
47
|
+
cmd_ran = coq_executor.run_next()
|
|
48
|
+
cmd_exec = coq_executor.current_stmt
|
|
49
|
+
prev_goal : typing.List[Goal] = coq_context_helper.get_focussed_goals(coq_executor) if coq_executor.is_in_proof_mode() else []
|
|
50
|
+
line_number = coq_executor.line_num
|
|
51
|
+
lemma_name = coq_executor.get_lemma_name_if_running()
|
|
52
|
+
if lemma_name is None:
|
|
53
|
+
lemma_name = "__NONE__"
|
|
54
|
+
proof_id = self.get_proof_id(project_id, file_namespace, line_number, lemma_name)
|
|
55
|
+
local_lemma_refs_cnt = 0
|
|
56
|
+
external_lemma_refs_cnt = 0
|
|
57
|
+
while cmd_ran:
|
|
58
|
+
if coq_executor.is_in_proof_mode() and lemma_name != "__NONE__":
|
|
59
|
+
proof_running = True
|
|
60
|
+
prev_goal : typing.List[Goal] = [Goal(goal.hypotheses, goal.goal) for goal in prev_goal]
|
|
61
|
+
next_goal : typing.List[Goal] = coq_context_helper.get_focussed_goals(coq_executor)
|
|
62
|
+
if len(prev_goal) > 0 and cmd_exec != "Proof.":
|
|
63
|
+
training_data_format = TrainingDataFormat(
|
|
64
|
+
proof_id=proof_id,
|
|
65
|
+
all_useful_defns_theorems=[],
|
|
66
|
+
start_goals=prev_goal,
|
|
67
|
+
end_goals=next_goal,
|
|
68
|
+
proof_steps=[cmd_exec],
|
|
69
|
+
simplified_goals=[],
|
|
70
|
+
addition_state_info={})
|
|
71
|
+
try:
|
|
72
|
+
coq_context_helper.set_relevant_defns_in_training_data_point(training_data_format, print_coq_executor, self.logger)
|
|
73
|
+
coq_context_helper.set_local_thms_dfns(training_data_format, coq_executor, self.logger)
|
|
74
|
+
except Exception:
|
|
75
|
+
self.logger.warning(f"Ignoring error in getting useful defns for cmd: \"{cmd_exec}\"")
|
|
76
|
+
self.logger.warning(f"Killing print coq executor")
|
|
77
|
+
self.logger.exception("Exception occurred!!")
|
|
78
|
+
try:
|
|
79
|
+
coq_context_helper.__exit__(None, None, None)
|
|
80
|
+
except:
|
|
81
|
+
pass
|
|
82
|
+
print_coq_executor = print_coq_executor_callback()
|
|
83
|
+
coq_context_helper = CoqContextHelper(print_coq_executor, self.depth, self.logger)
|
|
84
|
+
coq_context_helper.__enter__()
|
|
85
|
+
self.logger.warning(f"Re-initialized print coq executor")
|
|
86
|
+
assert len(training_data_format.proof_steps) > 0, f"Proof steps cannot be empty for {proof_id}"
|
|
87
|
+
for goal in training_data_format.start_goals:
|
|
88
|
+
lemma_cnt = len(training_data_format.all_useful_defns_theorems)
|
|
89
|
+
assert all([0 <= lemma_ref.lemma_idx < lemma_cnt for lemma_ref in goal.used_theorems_local]), f"Invalid lemma idx in {proof_id}"
|
|
90
|
+
assert all([0 <= lemma_ref.lemma_idx < lemma_cnt for lemma_ref in goal.used_theorems_external]), f"Invalid lemma idx in {proof_id}"
|
|
91
|
+
assert all([0 <= lemma_ref.lemma_idx < lemma_cnt for lemma_ref in goal.possible_useful_theorems_external]), f"Invalid lemma idx in {proof_id}"
|
|
92
|
+
assert all([0 <= lemma_ref.lemma_idx < lemma_cnt for lemma_ref in goal.possible_useful_theorems_local]), f"Invalid lemma idx in {proof_id}"
|
|
93
|
+
training_data.merge(training_data_format)
|
|
94
|
+
local_lemma_refs_cnt += sum([len(goal.used_theorems_local) for goal in training_data_format.start_goals])
|
|
95
|
+
external_lemma_refs_cnt += sum([len(goal.used_theorems_external) for goal in training_data_format.start_goals])
|
|
96
|
+
prev_goal = next_goal
|
|
97
|
+
else:
|
|
98
|
+
prev_goal = []
|
|
99
|
+
cmd_ran = coq_executor.run_next()
|
|
100
|
+
cmd_exec = coq_executor.current_stmt
|
|
101
|
+
line_number = coq_executor.line_num
|
|
102
|
+
if proof_running and not coq_executor.is_in_proof_mode():
|
|
103
|
+
proof_running = False
|
|
104
|
+
self.logger.info(f"Finished processing lemma {lemma_name}")
|
|
105
|
+
lemma_name = coq_executor.get_lemma_name_if_running()
|
|
106
|
+
if lemma_name is None:
|
|
107
|
+
lemma_name = "__NONE__"
|
|
108
|
+
proof_id = self.get_proof_id(project_id, file_namespace, line_number, lemma_name)
|
|
109
|
+
|
|
110
|
+
self.logger.info(f"===============Finished processing {file_namespace}=====================")
|
|
111
|
+
try:
|
|
112
|
+
coq_context_helper.__exit__(None, None, None)
|
|
113
|
+
except:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
import os
|
|
119
|
+
import logging
|
|
120
|
+
import time
|
|
121
|
+
os.chdir(root_dir)
|
|
122
|
+
project_dir = "data/test/coq/custom_group_theory/theories"
|
|
123
|
+
file_name = "data/test/coq/custom_group_theory/theories/grpthm.v"
|
|
124
|
+
output_path = ".log/local_data_generation_transform/data/"
|
|
125
|
+
log_path = ".log/local_data_generation_transform/log/"
|
|
126
|
+
project_id = project_dir.replace('/', '.')
|
|
127
|
+
os.makedirs(output_path, exist_ok=True)
|
|
128
|
+
os.makedirs(log_path, exist_ok=True)
|
|
129
|
+
time_str = time.strftime("%Y%m%d-%H%M%S")
|
|
130
|
+
log_file = f"{log_path}/local_data_generation_transform-{time_str}.log"
|
|
131
|
+
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
|
|
132
|
+
logger = logging.getLogger(__name__)
|
|
133
|
+
def _print_coq_executor_callback():
|
|
134
|
+
search_coq_exec = CoqExecutor(project_dir, file_name, use_human_readable_proof_context=True, suppress_error_log=True)
|
|
135
|
+
search_coq_exec.__enter__()
|
|
136
|
+
return search_coq_exec
|
|
137
|
+
transform = LocalTheoremProofPairGenerationTransform(0, buffer_size=1000)
|
|
138
|
+
training_data = TrainingData(
|
|
139
|
+
output_path,
|
|
140
|
+
"training_metadata.json",
|
|
141
|
+
training_meta=transform.get_meta_object(),
|
|
142
|
+
logger=logger)
|
|
143
|
+
with CoqExecutor(project_dir, file_name, use_human_readable_proof_context=True, suppress_error_log=True) as coq_exec:
|
|
144
|
+
transform(training_data, project_id, coq_exec, _print_coq_executor_callback)
|
|
145
|
+
save_info = training_data.save()
|
|
146
|
+
logger.info(f"Saved training data to {save_info}")
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
root_dir = f"{__file__.split('itp_interface')[0]}"
|
|
5
|
+
if root_dir not in sys.path:
|
|
6
|
+
sys.path.append(root_dir)
|
|
7
|
+
|
|
8
|
+
import typing
|
|
9
|
+
import logging
|
|
10
|
+
import enum
|
|
11
|
+
from itp_interface.tools.training_data_format import MergableCollection, TrainingDataFormat
|
|
12
|
+
from torch.multiprocessing import set_start_method
|
|
13
|
+
try:
|
|
14
|
+
set_start_method('spawn')
|
|
15
|
+
except RuntimeError:
|
|
16
|
+
pass
|
|
17
|
+
logger = logging.getLogger("CoqTrainingGenerator")
|
|
18
|
+
|
|
19
|
+
class TrainingDataGenerationType(enum.Enum):
|
|
20
|
+
FULL = 0
|
|
21
|
+
RETRIEVER = 1
|
|
22
|
+
GENERATION_BM25 = 2
|
|
23
|
+
GENERATION_DPR = 3
|
|
24
|
+
TEXT = 4
|
|
25
|
+
LOCAL = 5
|
|
26
|
+
|
|
27
|
+
class GenericTheoremRetriever:
|
|
28
|
+
def __init__(self):
|
|
29
|
+
self.logger = None
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def filter_best_context(self, partial_data: TrainingDataFormat) -> TrainingDataFormat:
|
|
33
|
+
raise NotImplementedError("retrieve_best_context must be implemented")
|
|
34
|
+
|
|
35
|
+
def set_logger(self, logger: logging.Logger):
|
|
36
|
+
self.logger = logger
|
|
37
|
+
|
|
38
|
+
class GenericTrainingDataGenerationTransform(object):
|
|
39
|
+
|
|
40
|
+
"""Class to generate training data for for coq based automatic theorem provers.
|
|
41
|
+
|
|
42
|
+
This class is responsible for generating training data for coq based automatic theorem provers.
|
|
43
|
+
NOTE: This class is not thread safe!!
|
|
44
|
+
"""
|
|
45
|
+
def __init__(self,
|
|
46
|
+
training_data_type: TrainingDataGenerationType,
|
|
47
|
+
buffer_size : int = 10000,
|
|
48
|
+
logger = None):
|
|
49
|
+
"""Initialize the training data generator.
|
|
50
|
+
"""
|
|
51
|
+
assert buffer_size > 0, "Buffer size must be greater than 0"
|
|
52
|
+
self.buffer_size = buffer_size
|
|
53
|
+
self.logger : logging.Logger = logger if logger is not None else logging.getLogger()
|
|
54
|
+
self.training_data_generation_type : TrainingDataGenerationType = training_data_type
|
|
55
|
+
|
|
56
|
+
def get_meta_object(self) -> MergableCollection:
|
|
57
|
+
raise NotImplementedError("get_meta_object must be implemented")
|
|
58
|
+
|
|
59
|
+
def get_data_collection_object(self) -> MergableCollection:
|
|
60
|
+
raise NotImplementedError("get_data_collection_object must be implemented")
|
|
61
|
+
|
|
62
|
+
def load_meta_from_file(self, file_path) -> MergableCollection:
|
|
63
|
+
raise NotImplementedError("load_meta_from_file must be implemented")
|
|
64
|
+
|
|
65
|
+
def load_data_from_file(self, file_path) -> MergableCollection:
|
|
66
|
+
raise NotImplementedError("load_data_from_file must be implemented")
|
|
67
|
+
|
|
68
|
+
def get_proof_id(self, project_id: str, file_namespace: str, line_number: int, lemma_name: str) -> str:
|
|
69
|
+
return f"<{project_id}>.{file_namespace}.{line_number:06d}.{lemma_name}"
|
|
70
|
+
|
|
71
|
+
def __call__(self, *args: typing.Any, **kwds: typing.Any) -> typing.Any:
|
|
72
|
+
raise NotImplementedError("__call__ must be implemented")
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def name(self):
|
|
76
|
+
return self.training_data_generation_type.name.lower()
|