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,508 @@
|
|
|
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
|
+
import os
|
|
8
|
+
import logging
|
|
9
|
+
import typing
|
|
10
|
+
import functools
|
|
11
|
+
import random
|
|
12
|
+
import re
|
|
13
|
+
import subprocess
|
|
14
|
+
from itp_interface.coq_ser_api import SerapiInstance, ProofContext, GetCoqAgent, CoqAgent
|
|
15
|
+
from itp_interface.tools.coq_parse_utils import CoqLineByLineReader, CoqStepByStepStdInReader
|
|
16
|
+
logger = logging.getLogger()
|
|
17
|
+
|
|
18
|
+
class CoqExecutor:
|
|
19
|
+
keywords = {
|
|
20
|
+
"Theorem", "Lemma", "Fact", "Remark", "Corollary", "Proposition", "Example", "Proof", "Qed", "Defined", "Admitted", "Abort",
|
|
21
|
+
"Fixpoint", "CoFixpoint", "Function", "Program Fixpoint", "Program CoFixpoint", "Program Function", "Let", "Let Fixpoint",
|
|
22
|
+
"Let CoFixpoint", "Let Function", "Let Program Fixpoint", "Let Program CoFixpoint", "Let Program Function",
|
|
23
|
+
"forall", "exists", "fun", "match", "if", "then", "else", "with", "as", "in", "end", "return", "Type", "Set", "Prop",
|
|
24
|
+
"Require", "Import", "Export", "From", "Module", "Section", "End", "Variable", "Axiom", "Parameter", "Hypothesis", "Context",
|
|
25
|
+
"Notation", "Reserved Notation", "Infix", "Notation", "Reserved Notation", "Infix", "Reserved Infix", "Notation", "Reserved Notation", "Definition",
|
|
26
|
+
"intros", "intro", "apply", "assumption", "exact", "reflexivity", "symmetry", "transitivity", "rewrite", "simpl", "unfold", "cbn", "cbv", "compute",
|
|
27
|
+
"destruct", "induction", "inversion", "injection", "split", "exists", "left", "right", "constructor", "auto", "eauto", "tauto", "omega", "lia", "ring",
|
|
28
|
+
"repeat", "try", "assert", "cut", "cutrewrite", "pose", "pose proof", "remember", "set", "setoid_rewrite", "generalize", "generalize dependent",
|
|
29
|
+
"move", "move =>", "move ->", "move => ->",
|
|
30
|
+
":", ".", "=>", "{", "}"
|
|
31
|
+
}
|
|
32
|
+
def __init__(self, project_root: str = None, main_file: str = None, use_hammer: bool = False, timeout_in_sec: int = 60, use_human_readable_proof_context: bool = False, proof_step_iter: typing.Iterator[str] = None, suppress_error_log: bool = False, setup_cmds: typing.List[str] = []):
|
|
33
|
+
assert proof_step_iter is None or isinstance(proof_step_iter, typing.Iterator), \
|
|
34
|
+
"proof_step_iter must be an iterator"
|
|
35
|
+
assert main_file is not None or proof_step_iter is not None, \
|
|
36
|
+
"Either main_file or proof_step_iter must be provided"
|
|
37
|
+
assert main_file is None or proof_step_iter is None, \
|
|
38
|
+
"Only one of main_file or proof_step_iter must be provided"
|
|
39
|
+
assert main_file is None or (os.path.exists(main_file) and main_file.endswith(".v")), \
|
|
40
|
+
"main_file must be a valid path to a '.v' file"
|
|
41
|
+
assert project_root is None or (os.path.exists(project_root) and os.path.isdir(project_root)), \
|
|
42
|
+
"project_root must be a valid path to a directory"
|
|
43
|
+
self.use_human_readable_proof_context = use_human_readable_proof_context
|
|
44
|
+
self.project_root = project_root if project_root is not None else "."
|
|
45
|
+
self.main_file = main_file
|
|
46
|
+
self.use_hammer = use_hammer
|
|
47
|
+
self.timeout_in_sec = min(timeout_in_sec, 120) # Maximum 120s timeout
|
|
48
|
+
self.current_stmt = None
|
|
49
|
+
self.line_num = 0
|
|
50
|
+
self.main_file_iter = proof_step_iter
|
|
51
|
+
self.suppress_error_log = suppress_error_log
|
|
52
|
+
self.coq : CoqAgent = None
|
|
53
|
+
self.execution_complete = False
|
|
54
|
+
self.setup_cmds = setup_cmds
|
|
55
|
+
|
|
56
|
+
def __enter__(self):
|
|
57
|
+
self._all_dep_handles = []
|
|
58
|
+
all_setup_cmds = '\n'.join(self.setup_cmds)
|
|
59
|
+
if len(all_setup_cmds) > 0:
|
|
60
|
+
try:
|
|
61
|
+
env_settings = subprocess.run(all_setup_cmds, shell=True, stdout=subprocess.PIPE, check=True, text=True).stdout
|
|
62
|
+
except:
|
|
63
|
+
env_settings = None
|
|
64
|
+
logger.error(f"Got an exception while running setup commands:\n {all_setup_cmds}")
|
|
65
|
+
logger.exception(f"Exception Log")
|
|
66
|
+
logger.info(f"Continuing without setting up the environment")
|
|
67
|
+
else:
|
|
68
|
+
env_settings = None
|
|
69
|
+
self.coq : CoqAgent = GetCoqAgent(prelude=self.project_root, use_human_readable_str=self.use_human_readable_proof_context, env_string=env_settings, timeout=self.timeout_in_sec)
|
|
70
|
+
if hasattr(self.coq, "quiet"):
|
|
71
|
+
self.coq.quiet = self.suppress_error_log
|
|
72
|
+
if self.main_file_iter is None:
|
|
73
|
+
self.main_file_iter = CoqLineByLineReader(self.main_file).instruction_step_generator()
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
77
|
+
try:
|
|
78
|
+
self.main_file_iter.close() # Close the file handle
|
|
79
|
+
except:
|
|
80
|
+
pass
|
|
81
|
+
self.coq.kill() # Kill the coq instance after use
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def token_separator_set(self):
|
|
85
|
+
return set(" ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\")
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def token_separator(self):
|
|
89
|
+
return " ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\"
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def token_separator_regex(self):
|
|
93
|
+
return "\s+|\(|\)|\[|\]|\{|\}|\.|,|;|:|\?|@|#|\$|%|\^|&|\||`|\"|\\\\" +\
|
|
94
|
+
""#"|\+|-|\*|/|=|<|>|!|~"
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def get_token_separator_set():
|
|
98
|
+
return set(" ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\")
|
|
99
|
+
|
|
100
|
+
@staticmethod
|
|
101
|
+
def get_token_separators():
|
|
102
|
+
return " ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\"
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def get_token_separator_regex():
|
|
106
|
+
return "\s+|\(|\)|\[|\]|\{|\}|\.|,|;|:|\?|@|#|\$|%|\^|&|\||`|\"|\\\\" +\
|
|
107
|
+
""#"|\+|-|\*|/|=|<|>|!|~"
|
|
108
|
+
|
|
109
|
+
def is_in_proof_mode(self):
|
|
110
|
+
return True if self.coq.proof_context else False
|
|
111
|
+
|
|
112
|
+
def needs_qed(self):
|
|
113
|
+
return self.coq.proof_context is not None and len(self.coq.proof_context.all_goals) == 0
|
|
114
|
+
|
|
115
|
+
def needs_cut_close(self):
|
|
116
|
+
return self.coq.proof_context is not None and len(self.coq.proof_context.fg_goals) == 0 and len(self.coq.proof_context.all_goals) > 0
|
|
117
|
+
|
|
118
|
+
def run_next(self) -> bool:
|
|
119
|
+
try:
|
|
120
|
+
stmt = next(self.main_file_iter)
|
|
121
|
+
except StopIteration:
|
|
122
|
+
self.execution_complete = True
|
|
123
|
+
return False
|
|
124
|
+
self.current_stmt = stmt
|
|
125
|
+
self.line_num += 1
|
|
126
|
+
try:
|
|
127
|
+
self.coq.run_stmt(stmt, timeout=self.timeout_in_sec)
|
|
128
|
+
except:
|
|
129
|
+
if not self.suppress_error_log:
|
|
130
|
+
logger.error(f"Got an exception while running '{stmt}' on coq. File name: {self.main_file}")
|
|
131
|
+
logger.exception(f"Exception Log")
|
|
132
|
+
raise
|
|
133
|
+
return True
|
|
134
|
+
|
|
135
|
+
def get_tokens_in_given_stmt(self, stmt: str, ignore_first_token: bool = False) -> typing.Generator[str, None, None]:
|
|
136
|
+
idx = -1
|
|
137
|
+
for tok in re.split(self.token_separator_regex, stmt):
|
|
138
|
+
idx += 1
|
|
139
|
+
# skip the first token as it is usually a keyword
|
|
140
|
+
if idx == 0 and ignore_first_token:
|
|
141
|
+
continue
|
|
142
|
+
tok1 = tok.strip()
|
|
143
|
+
if len(tok1) > 0:
|
|
144
|
+
yield tok1
|
|
145
|
+
|
|
146
|
+
def tokenize(stmt: str) -> typing.Generator[str, None, None]:
|
|
147
|
+
for tok in re.split(CoqExecutor.get_token_separator_regex(), stmt):
|
|
148
|
+
tok1 = tok.strip()
|
|
149
|
+
if len(tok1) > 0:
|
|
150
|
+
yield tok1
|
|
151
|
+
|
|
152
|
+
@functools.lru_cache(maxsize=10000)
|
|
153
|
+
def print_dfns(self, name: str) -> str:
|
|
154
|
+
if name in CoqExecutor.keywords:
|
|
155
|
+
return ""
|
|
156
|
+
return self.coq.print_symbols(name)
|
|
157
|
+
|
|
158
|
+
# Make this chacheable
|
|
159
|
+
@functools.lru_cache(maxsize=10000)
|
|
160
|
+
def search_type_matching_defns(self, name: str) -> typing.List[str]:
|
|
161
|
+
if name in CoqExecutor.keywords:
|
|
162
|
+
return []
|
|
163
|
+
return self.coq.search_about(name)
|
|
164
|
+
|
|
165
|
+
def get_all_type_matching_defns(self, name: str, should_print_symbol: bool = False) -> typing.Generator[typing.Tuple[str, str], None, None]:
|
|
166
|
+
all_defns = self.search_type_matching_defns(name)
|
|
167
|
+
# Try for an exact match
|
|
168
|
+
for defn in all_defns:
|
|
169
|
+
defn = defn.split(":")
|
|
170
|
+
defn_name = defn[0].strip()
|
|
171
|
+
if len(defn) > 1:
|
|
172
|
+
if should_print_symbol:
|
|
173
|
+
defn_val = self.print_dfns(defn_name).strip()
|
|
174
|
+
else:
|
|
175
|
+
defn_val = ("".join(defn[1:])).strip()
|
|
176
|
+
else:
|
|
177
|
+
defn_val = ""
|
|
178
|
+
yield defn_name, defn_val
|
|
179
|
+
|
|
180
|
+
def search_exact(self, name: str, should_print_symbol: bool = False) -> typing.List[typing.Tuple[str, str]]:
|
|
181
|
+
symb_defn = self.search_type_matching_defns(name)
|
|
182
|
+
main_matches = []
|
|
183
|
+
match_until = set([name])
|
|
184
|
+
# Try for an exact match
|
|
185
|
+
for defn in symb_defn:
|
|
186
|
+
defn = defn.split(":")
|
|
187
|
+
defn_name = defn[0].strip()
|
|
188
|
+
if len(defn) > 1:
|
|
189
|
+
if should_print_symbol:
|
|
190
|
+
defn_val = self.print_dfns(defn_name).strip()
|
|
191
|
+
else:
|
|
192
|
+
defn_val = ("".join(defn[1:])).strip()
|
|
193
|
+
# print(f"should_print_symbol: {should_print_symbol}")
|
|
194
|
+
# print(defn_name)
|
|
195
|
+
# print(defn_val)
|
|
196
|
+
else:
|
|
197
|
+
defn_val = ""
|
|
198
|
+
if defn_name in match_until:
|
|
199
|
+
main_matches.append((defn_name, defn_val))
|
|
200
|
+
break
|
|
201
|
+
return main_matches
|
|
202
|
+
|
|
203
|
+
def search_defn(self, name: str, match_until: typing.Tuple[str], max_search_res: typing.Optional[int] = None, should_print_symbol: bool = False) -> typing.List[typing.Tuple[str, str, bool]]:
|
|
204
|
+
symb_defn = self.search_type_matching_defns(name)
|
|
205
|
+
match_defns = []
|
|
206
|
+
main_matches = []
|
|
207
|
+
match_until = set(match_until)
|
|
208
|
+
# Try for an exact match
|
|
209
|
+
for defn in symb_defn:
|
|
210
|
+
defn = defn.split(":")
|
|
211
|
+
defn_name = defn[0].strip()
|
|
212
|
+
if len(defn) > 1:
|
|
213
|
+
if should_print_symbol:
|
|
214
|
+
defn_val = self.print_dfns(defn_name).strip()
|
|
215
|
+
else:
|
|
216
|
+
defn_val = ("".join(defn[1:])).strip()
|
|
217
|
+
else:
|
|
218
|
+
defn_val = ""
|
|
219
|
+
if defn_name in match_until:
|
|
220
|
+
main_matches.append((defn_name, defn_val, True))
|
|
221
|
+
else:
|
|
222
|
+
match_defns.append((defn_name, defn_val, False))
|
|
223
|
+
if max_search_res is not None:
|
|
224
|
+
match_defns = random.sample(match_defns, max(0, min(max_search_res - 1, len(match_defns))))
|
|
225
|
+
match_defns.extend(main_matches)
|
|
226
|
+
return match_defns
|
|
227
|
+
|
|
228
|
+
def run_without_executing(self, stmt: str):
|
|
229
|
+
while True:
|
|
230
|
+
try:
|
|
231
|
+
stmt = next(self.main_file_iter)
|
|
232
|
+
except StopIteration:
|
|
233
|
+
return
|
|
234
|
+
self.current_stmt = stmt
|
|
235
|
+
self.line_num += 1
|
|
236
|
+
|
|
237
|
+
def run_lemma_without_executing(self):
|
|
238
|
+
while True:
|
|
239
|
+
try:
|
|
240
|
+
stmt = next(self.main_file_iter)
|
|
241
|
+
self.current_stmt = stmt
|
|
242
|
+
self.line_num += 1
|
|
243
|
+
if "Qed." in stmt or "Defined." in stmt or "Admitted." in stmt:
|
|
244
|
+
return True
|
|
245
|
+
except StopIteration:
|
|
246
|
+
return False
|
|
247
|
+
|
|
248
|
+
def rewind_proof_steps(self) -> str:
|
|
249
|
+
# rewind the proof steps until the last lemma is found
|
|
250
|
+
current_lemma = None
|
|
251
|
+
while self.is_in_proof_mode():
|
|
252
|
+
if current_lemma is None:
|
|
253
|
+
current_lemma = self.coq.cur_lemma
|
|
254
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
255
|
+
# should call run_to_finish_lemma instead
|
|
256
|
+
self.coq.cancel_last(force_update_nonfg_goals=True)
|
|
257
|
+
self.line_num -= 1
|
|
258
|
+
return "Theorem " + current_lemma if current_lemma is not None else None
|
|
259
|
+
|
|
260
|
+
def run_till_next_lemma(self) -> typing.Tuple[bool, typing.Optional[str]]:
|
|
261
|
+
# Run the coq file until the next lemma is found
|
|
262
|
+
next_stmt = None
|
|
263
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
264
|
+
if in_proof_mode or self.execution_complete:
|
|
265
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
266
|
+
return False, next_stmt
|
|
267
|
+
prev_stmt = self.current_stmt
|
|
268
|
+
ran_last_cmd = self.run_next()
|
|
269
|
+
next_stmt = self.current_stmt
|
|
270
|
+
if not ran_last_cmd:
|
|
271
|
+
return False, None
|
|
272
|
+
assigned = False
|
|
273
|
+
while ran_last_cmd and not in_proof_mode:
|
|
274
|
+
if not assigned:
|
|
275
|
+
prev_stmt = next_stmt
|
|
276
|
+
ran_last_cmd = self.run_next()
|
|
277
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
278
|
+
if not assigned:
|
|
279
|
+
next_stmt = self.current_stmt
|
|
280
|
+
if in_proof_mode:
|
|
281
|
+
assigned = True
|
|
282
|
+
lemma_name = next_stmt if next_stmt.startswith("Theorem") or next_stmt.startswith("Lemma") else prev_stmt
|
|
283
|
+
return in_proof_mode, lemma_name
|
|
284
|
+
|
|
285
|
+
def run_till_next_lemma_return_exec_stmt(self) -> typing.Generator[str, None, None]:
|
|
286
|
+
# Run the coq file until the next lemma is found
|
|
287
|
+
next_stmt = None
|
|
288
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
289
|
+
if in_proof_mode or self.execution_complete:
|
|
290
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
291
|
+
yield from []
|
|
292
|
+
else:
|
|
293
|
+
ran_last_cmd = self.run_next()
|
|
294
|
+
next_stmt = self.current_stmt
|
|
295
|
+
if not ran_last_cmd:
|
|
296
|
+
yield from []
|
|
297
|
+
else:
|
|
298
|
+
yield next_stmt
|
|
299
|
+
while ran_last_cmd and not in_proof_mode:
|
|
300
|
+
ran_last_cmd = self.run_next()
|
|
301
|
+
next_stmt = self.current_stmt
|
|
302
|
+
if ran_last_cmd:
|
|
303
|
+
yield next_stmt
|
|
304
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
305
|
+
|
|
306
|
+
def run_to_finish_lemma_return_exec(self) -> typing.Generator[str, None, None]:
|
|
307
|
+
# Run the coq file until the next lemma is found
|
|
308
|
+
next_stmt = None
|
|
309
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
310
|
+
if not in_proof_mode or self.execution_complete:
|
|
311
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
312
|
+
yield from []
|
|
313
|
+
else:
|
|
314
|
+
ran_last_cmd = self.run_next()
|
|
315
|
+
next_stmt = self.current_stmt
|
|
316
|
+
if not ran_last_cmd:
|
|
317
|
+
yield from []
|
|
318
|
+
else:
|
|
319
|
+
yield next_stmt
|
|
320
|
+
while ran_last_cmd and in_proof_mode:
|
|
321
|
+
ran_last_cmd = self.run_next()
|
|
322
|
+
next_stmt = self.current_stmt
|
|
323
|
+
if ran_last_cmd:
|
|
324
|
+
yield next_stmt
|
|
325
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
326
|
+
|
|
327
|
+
def run_to_finish_lemma(self) -> bool:
|
|
328
|
+
# Run the coq file and finish the current lemma
|
|
329
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
330
|
+
if not in_proof_mode or self.execution_complete:
|
|
331
|
+
# If we are not in proof mode, then we are not finishing a lemma
|
|
332
|
+
return False
|
|
333
|
+
ran_last_cmd = self.run_next()
|
|
334
|
+
if not ran_last_cmd:
|
|
335
|
+
return False
|
|
336
|
+
while ran_last_cmd and in_proof_mode:
|
|
337
|
+
ran_last_cmd = self.run_next()
|
|
338
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
339
|
+
return not in_proof_mode
|
|
340
|
+
|
|
341
|
+
def run_till_line_num(self, line_num: int):
|
|
342
|
+
assert line_num >= self.line_num
|
|
343
|
+
ran_last_cmd = True
|
|
344
|
+
while ran_last_cmd and self.line_num < line_num:
|
|
345
|
+
ran_last_cmd = self.run_next()
|
|
346
|
+
return self.line_num
|
|
347
|
+
|
|
348
|
+
def run_to_finish(self):
|
|
349
|
+
ran_last_cmd = True
|
|
350
|
+
while ran_last_cmd:
|
|
351
|
+
ran_last_cmd = self.run_next()
|
|
352
|
+
|
|
353
|
+
def get_lemma_name_if_running(self) -> typing.Optional[str]:
|
|
354
|
+
if not self.is_in_proof_mode():
|
|
355
|
+
return None
|
|
356
|
+
else:
|
|
357
|
+
try:
|
|
358
|
+
return self.coq.cur_lemma_name
|
|
359
|
+
except:
|
|
360
|
+
return None
|
|
361
|
+
|
|
362
|
+
def get_lemma_stmt_if_running(self) -> typing.Optional[str]:
|
|
363
|
+
if not self.is_in_proof_mode():
|
|
364
|
+
return None
|
|
365
|
+
else:
|
|
366
|
+
try:
|
|
367
|
+
return self.coq.cur_lemma
|
|
368
|
+
except:
|
|
369
|
+
return None
|
|
370
|
+
|
|
371
|
+
def get_current_lemma_name(self) -> typing.Optional[str]:
|
|
372
|
+
if not self.is_in_proof_mode():
|
|
373
|
+
return None
|
|
374
|
+
try:
|
|
375
|
+
return self.coq.cur_lemma_name
|
|
376
|
+
except:
|
|
377
|
+
return None
|
|
378
|
+
|
|
379
|
+
def get_all_lemmas_in_file(coq_executor: CoqExecutor, logger: logging.Logger) -> typing.List[str]:
|
|
380
|
+
lemmas_to_prove = []
|
|
381
|
+
while not coq_executor.execution_complete:
|
|
382
|
+
assert not coq_executor.is_in_proof_mode(), "main_executor must not be in proof mode"
|
|
383
|
+
_ = list(coq_executor.run_till_next_lemma_return_exec_stmt())
|
|
384
|
+
if coq_executor.execution_complete:
|
|
385
|
+
break
|
|
386
|
+
lemma_name = coq_executor.get_lemma_name_if_running()
|
|
387
|
+
if lemma_name is None:
|
|
388
|
+
_ = list(coq_executor.run_to_finish_lemma_return_exec())
|
|
389
|
+
if coq_executor.execution_complete:
|
|
390
|
+
break
|
|
391
|
+
else:
|
|
392
|
+
logger.info(f"Discovered lemma: {lemma_name}")
|
|
393
|
+
lemmas_to_prove.append(lemma_name)
|
|
394
|
+
coq_executor.run_to_finish_lemma()
|
|
395
|
+
return lemmas_to_prove
|
|
396
|
+
|
|
397
|
+
class CoqStdInOutExecutor:
|
|
398
|
+
def __init__(self):
|
|
399
|
+
self.coq_stdin_reader = CoqStepByStepStdInReader()
|
|
400
|
+
self.coq_exec : CoqExecutor = CoqExecutor(
|
|
401
|
+
use_human_readable_proof_context=True,
|
|
402
|
+
proof_step_iter=self.coq_stdin_reader.instruction_step_generator())
|
|
403
|
+
|
|
404
|
+
def __enter__(self):
|
|
405
|
+
self.coq_exec.__enter__()
|
|
406
|
+
return self
|
|
407
|
+
|
|
408
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
409
|
+
self.coq_exec.__exit__(exc_type, exc_value, traceback)
|
|
410
|
+
|
|
411
|
+
def run_in_loop(self):
|
|
412
|
+
print("In> ", end="")
|
|
413
|
+
while True:
|
|
414
|
+
try:
|
|
415
|
+
cmd_ran = self.coq_exec.run_next()
|
|
416
|
+
if not cmd_ran:
|
|
417
|
+
break
|
|
418
|
+
print(f"Coq> {self.coq_exec.current_stmt}")
|
|
419
|
+
print(f"{self.coq_exec.coq.proof_context}")
|
|
420
|
+
print("In> ", end="")
|
|
421
|
+
except:
|
|
422
|
+
pass
|
|
423
|
+
pass
|
|
424
|
+
|
|
425
|
+
class CoqCustomFileExec:
|
|
426
|
+
def __init__(self, project_path: str, file_path: str, setup_cmds: typing.List[str] = []):
|
|
427
|
+
self.coq_stdin_reader = CoqLineByLineReader(file_path)
|
|
428
|
+
self.project_path = project_path
|
|
429
|
+
self.coq_exec : CoqExecutor = CoqExecutor(
|
|
430
|
+
project_root=self.project_path,
|
|
431
|
+
use_human_readable_proof_context=True,
|
|
432
|
+
proof_step_iter=self.coq_stdin_reader.instruction_step_generator(),
|
|
433
|
+
setup_cmds=setup_cmds)
|
|
434
|
+
|
|
435
|
+
def __enter__(self):
|
|
436
|
+
self.coq_exec.__enter__()
|
|
437
|
+
return self
|
|
438
|
+
|
|
439
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
440
|
+
self.coq_exec.__exit__(exc_type, exc_value, traceback)
|
|
441
|
+
|
|
442
|
+
def print_goals(self):
|
|
443
|
+
proof_context: ProofContext = self.coq_exec.coq.proof_context
|
|
444
|
+
if proof_context is None:
|
|
445
|
+
print("No goals to print")
|
|
446
|
+
else:
|
|
447
|
+
for idx, goal in enumerate(proof_context.all_goals):
|
|
448
|
+
print(f"Goal {idx + 1}:")
|
|
449
|
+
print(goal.goal)
|
|
450
|
+
if len(goal.hypotheses) > 0:
|
|
451
|
+
print(f"Hypotheses: {idx + 1}")
|
|
452
|
+
for hyp in goal.hypotheses:
|
|
453
|
+
print(hyp)
|
|
454
|
+
print("-" * 20)
|
|
455
|
+
print('=' * 20)
|
|
456
|
+
|
|
457
|
+
def run_in_loop(self):
|
|
458
|
+
print("In> Press 'Enter' for running next line and 'c' + 'Enter' to cancel the last command and 're-run'.", end="")
|
|
459
|
+
last_stmt = None
|
|
460
|
+
while True:
|
|
461
|
+
try:
|
|
462
|
+
opt = input()
|
|
463
|
+
if opt == "c" and last_stmt is not None:
|
|
464
|
+
if self.coq_exec.is_in_proof_mode():
|
|
465
|
+
print(f"Goals before cancelling")
|
|
466
|
+
self.print_goals()
|
|
467
|
+
else:
|
|
468
|
+
print("No goals before cancelling")
|
|
469
|
+
self.coq_exec.coq.cancel_last()
|
|
470
|
+
if self.coq_exec.is_in_proof_mode():
|
|
471
|
+
print(f"Goals after cancelling")
|
|
472
|
+
self.print_goals()
|
|
473
|
+
else:
|
|
474
|
+
print("No goals after cancelling")
|
|
475
|
+
print(f"Canceled last statement: {last_stmt}")
|
|
476
|
+
print(f"Re-running: {last_stmt}")
|
|
477
|
+
self.coq_exec.coq.run_stmt(last_stmt)
|
|
478
|
+
print(f"Coq> Ran {last_stmt} again")
|
|
479
|
+
continue
|
|
480
|
+
cmd_ran = self.coq_exec.run_next()
|
|
481
|
+
last_stmt = self.coq_exec.current_stmt
|
|
482
|
+
if self.coq_exec.is_in_proof_mode():
|
|
483
|
+
print(f"Goals after running {last_stmt}")
|
|
484
|
+
self.print_goals()
|
|
485
|
+
if not cmd_ran:
|
|
486
|
+
break
|
|
487
|
+
print(f"Coq> {self.coq_exec.current_stmt}")
|
|
488
|
+
self.print_goals()
|
|
489
|
+
print("In> ", end="")
|
|
490
|
+
except Exception as e:
|
|
491
|
+
print(f"Got an exception: {e}")
|
|
492
|
+
pass
|
|
493
|
+
pass
|
|
494
|
+
|
|
495
|
+
if __name__ == "__main__":
|
|
496
|
+
logging.basicConfig(filename='coq_executor.log', filemode='w', level=logging.INFO)
|
|
497
|
+
# with CoqStdInOutExecutor() as coq_exec:
|
|
498
|
+
# coq_exec.run_in_loop()
|
|
499
|
+
os.chdir(root_dir)
|
|
500
|
+
# with CoqCustomFileExec(".", "data/test/SimpleAlgebra.v") as coq_exec:
|
|
501
|
+
# coq_exec.run_in_loop()
|
|
502
|
+
project_path = "<root>/data/repos/math-comp/"
|
|
503
|
+
# Get <root> from os.environ
|
|
504
|
+
project_path = project_path.replace("<root>/", os.environ.get("ROOT", "").trim('/') + "/")
|
|
505
|
+
file_path = os.path.join(project_path, "mathcomp/solvable/primitive_action.v")
|
|
506
|
+
setup_cmds = ['opam env --switch=MathComp --set-switch']
|
|
507
|
+
with CoqCustomFileExec(project_path, file_path, setup_cmds) as coq_exec:
|
|
508
|
+
coq_exec.run_in_loop()
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
import typing
|
|
8
|
+
import uuid
|
|
9
|
+
import os
|
|
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 LocalDataGenerationTransform(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
|
+
no_dfns : bool = False,
|
|
24
|
+
no_thms : bool = False):
|
|
25
|
+
super().__init__(TrainingDataGenerationType.LOCAL, buffer_size, logger)
|
|
26
|
+
self.depth = depth
|
|
27
|
+
self.max_search_results = max_search_results
|
|
28
|
+
self.max_parallelism = max_parallelism
|
|
29
|
+
self.no_dfns = no_dfns
|
|
30
|
+
self.no_thms = no_thms
|
|
31
|
+
|
|
32
|
+
def get_meta_object(self) -> MergableCollection:
|
|
33
|
+
return TrainingDataMetadataFormat(training_data_buffer_size=self.buffer_size)
|
|
34
|
+
|
|
35
|
+
def get_data_collection_object(self) -> MergableCollection:
|
|
36
|
+
return TrainingDataCollection()
|
|
37
|
+
|
|
38
|
+
def load_meta_from_file(self, file_path) -> MergableCollection:
|
|
39
|
+
return TrainingDataMetadataFormat.load_from_file(file_path)
|
|
40
|
+
|
|
41
|
+
def load_data_from_file(self, file_path) -> MergableCollection:
|
|
42
|
+
return TrainingDataCollection.load_from_file(file_path, self.logger)
|
|
43
|
+
|
|
44
|
+
def __call__(self, training_data: TrainingData, project_id : str, coq_executor: CoqExecutor, print_coq_executor_callback: typing.Callable[[], CoqExecutor], theorems: typing.List[str] = None, other_args: dict = {}) -> TrainingData:
|
|
45
|
+
print_coq_executor = print_coq_executor_callback()
|
|
46
|
+
coq_context_helper = CoqContextHelper(print_coq_executor, self.depth, self.logger)
|
|
47
|
+
coq_context_helper.__enter__()
|
|
48
|
+
file_namespace = coq_executor.main_file.replace('/', '.')
|
|
49
|
+
self.logger.info(f"=========================Processing {file_namespace}=========================")
|
|
50
|
+
proof_running = False
|
|
51
|
+
cmd_ran = coq_executor.run_next()
|
|
52
|
+
cmd_exec = coq_executor.current_stmt
|
|
53
|
+
prev_goal : typing.List[Goal] = coq_context_helper.get_focussed_goals(coq_executor) if coq_executor.is_in_proof_mode() else []
|
|
54
|
+
line_number = coq_executor.line_num
|
|
55
|
+
lemma_name = coq_executor.get_lemma_name_if_running()
|
|
56
|
+
if lemma_name is None:
|
|
57
|
+
lemma_name = "__NONE__"
|
|
58
|
+
theorem_id = str(uuid.uuid4())
|
|
59
|
+
proof_id = theorem_id # self.get_proof_id(theorem_id, file_namespace, line_number, lemma_name)
|
|
60
|
+
local_lemma_refs_cnt = 0
|
|
61
|
+
external_lemma_refs_cnt = 0
|
|
62
|
+
theorems = set(theorems) if theorems is not None else None
|
|
63
|
+
while cmd_ran:
|
|
64
|
+
if coq_executor.is_in_proof_mode() and lemma_name != "__NONE__" and (theorems is None or lemma_name in theorems):
|
|
65
|
+
proof_running = True
|
|
66
|
+
prev_goal : typing.List[Goal] = [Goal(goal.hypotheses, goal.goal) for goal in prev_goal]
|
|
67
|
+
next_goal : typing.List[Goal] = coq_context_helper.get_focussed_goals(coq_executor)
|
|
68
|
+
if len(prev_goal) > 0 and cmd_exec != "Proof.":
|
|
69
|
+
training_data_format = TrainingDataFormat(
|
|
70
|
+
proof_id=proof_id,
|
|
71
|
+
all_useful_defns_theorems=[],
|
|
72
|
+
start_goals=prev_goal,
|
|
73
|
+
end_goals=next_goal,
|
|
74
|
+
proof_steps=[cmd_exec],
|
|
75
|
+
simplified_goals=[],
|
|
76
|
+
addition_state_info={},
|
|
77
|
+
file_path=coq_executor.main_file,
|
|
78
|
+
theorem_name=lemma_name,
|
|
79
|
+
project_id=project_id)
|
|
80
|
+
try:
|
|
81
|
+
if not self.no_dfns:
|
|
82
|
+
coq_context_helper.set_relevant_defns_in_training_data_point(training_data_format, print_coq_executor, self.logger)
|
|
83
|
+
if not self.no_thms:
|
|
84
|
+
coq_context_helper.set_local_thms_dfns(training_data_format, coq_executor, self.logger)
|
|
85
|
+
except Exception:
|
|
86
|
+
self.logger.warning(f"Ignoring error in getting useful defns for cmd: \"{cmd_exec}\"")
|
|
87
|
+
self.logger.warning(f"Killing print coq executor")
|
|
88
|
+
self.logger.exception("Exception occurred!!")
|
|
89
|
+
try:
|
|
90
|
+
coq_context_helper.__exit__(None, None, None)
|
|
91
|
+
except:
|
|
92
|
+
pass
|
|
93
|
+
print_coq_executor = print_coq_executor_callback()
|
|
94
|
+
coq_context_helper = CoqContextHelper(print_coq_executor, self.depth, self.logger)
|
|
95
|
+
coq_context_helper.__enter__()
|
|
96
|
+
self.logger.warning(f"Re-initialized print coq executor")
|
|
97
|
+
assert len(training_data_format.proof_steps) > 0, f"Proof steps cannot be empty for {proof_id}"
|
|
98
|
+
for goal in training_data_format.start_goals:
|
|
99
|
+
lemma_cnt = len(training_data_format.all_useful_defns_theorems)
|
|
100
|
+
assert all([0 <= lemma_ref.lemma_idx < lemma_cnt for lemma_ref in goal.used_theorems_local]), f"Invalid lemma idx in {proof_id}"
|
|
101
|
+
assert all([0 <= lemma_ref.lemma_idx < lemma_cnt for lemma_ref in goal.used_theorems_external]), f"Invalid lemma idx in {proof_id}"
|
|
102
|
+
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}"
|
|
103
|
+
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}"
|
|
104
|
+
training_data.merge(training_data_format)
|
|
105
|
+
local_lemma_refs_cnt += sum([len(goal.used_theorems_local) for goal in training_data_format.start_goals])
|
|
106
|
+
external_lemma_refs_cnt += sum([len(goal.used_theorems_external) for goal in training_data_format.start_goals])
|
|
107
|
+
prev_goal = next_goal
|
|
108
|
+
else:
|
|
109
|
+
prev_goal = []
|
|
110
|
+
cmd_ran = coq_executor.run_next()
|
|
111
|
+
cmd_exec = coq_executor.current_stmt
|
|
112
|
+
line_number = coq_executor.line_num
|
|
113
|
+
if proof_running and not coq_executor.is_in_proof_mode():
|
|
114
|
+
proof_running = False
|
|
115
|
+
self.logger.info(f"Finished processing lemma [{theorem_id}] {lemma_name}")
|
|
116
|
+
theorem_id = str(uuid.uuid4())
|
|
117
|
+
lemma_name = coq_executor.get_lemma_name_if_running()
|
|
118
|
+
if lemma_name is None:
|
|
119
|
+
lemma_name = "__NONE__"
|
|
120
|
+
proof_id = theorem_id # self.get_proof_id(theorem_id, file_namespace, line_number, lemma_name)
|
|
121
|
+
|
|
122
|
+
self.logger.info(f"===============Finished processing {file_namespace}=====================")
|
|
123
|
+
try:
|
|
124
|
+
coq_context_helper.__exit__(None, None, None)
|
|
125
|
+
except:
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
import os
|
|
131
|
+
import logging
|
|
132
|
+
import time
|
|
133
|
+
os.chdir(root_dir)
|
|
134
|
+
project_dir = "data/test/coq/custom_group_theory/theories"
|
|
135
|
+
file_name = "data/test/coq/custom_group_theory/theories/grpthm.v"
|
|
136
|
+
output_path = ".log/local_data_generation_transform/data/"
|
|
137
|
+
log_path = ".log/local_data_generation_transform/log/"
|
|
138
|
+
project_id = project_dir.replace('/', '.')
|
|
139
|
+
os.makedirs(output_path, exist_ok=True)
|
|
140
|
+
os.makedirs(log_path, exist_ok=True)
|
|
141
|
+
time_str = time.strftime("%Y%m%d-%H%M%S")
|
|
142
|
+
log_file = f"{log_path}/local_data_generation_transform-{time_str}.log"
|
|
143
|
+
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
|
|
144
|
+
logger = logging.getLogger(__name__)
|
|
145
|
+
def _print_coq_executor_callback():
|
|
146
|
+
search_coq_exec = CoqExecutor(project_dir, file_name, use_human_readable_proof_context=True, suppress_error_log=True)
|
|
147
|
+
search_coq_exec.__enter__()
|
|
148
|
+
return search_coq_exec
|
|
149
|
+
transform = LocalDataGenerationTransform(0, buffer_size=1000)
|
|
150
|
+
training_data = TrainingData(
|
|
151
|
+
output_path,
|
|
152
|
+
"training_metadata.json",
|
|
153
|
+
training_meta=transform.get_meta_object(),
|
|
154
|
+
logger=logger)
|
|
155
|
+
with CoqExecutor(project_dir, file_name, use_human_readable_proof_context=True, suppress_error_log=True) as coq_exec:
|
|
156
|
+
transform(training_data, project_id, coq_exec, _print_coq_executor_callback)
|
|
157
|
+
save_info = training_data.save()
|
|
158
|
+
logger.info(f"Saved training data to {save_info}")
|