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,327 @@
|
|
|
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 logging
|
|
9
|
+
import typing
|
|
10
|
+
from itp_interface.tools.lean_cmd_executor import Lean3Executor
|
|
11
|
+
from itp_interface.tools.training_data_format import Goal, LemmaRefWithScore, LemmaReferences, TrainingDataFormat
|
|
12
|
+
from typing import List
|
|
13
|
+
|
|
14
|
+
class Lean3ContextHelper(object):
|
|
15
|
+
max_relevance_score = 0.95
|
|
16
|
+
def __init__(self, search_executor: Lean3Executor, depth : typing.Optional[int] = None, logger: logging.Logger = None) -> None:
|
|
17
|
+
assert search_executor is not None, "Search executor cannot be None"
|
|
18
|
+
assert depth is None or depth >= 0, "Depth should be greater than 0"
|
|
19
|
+
self.search_executor = search_executor
|
|
20
|
+
self.depth = depth if depth is not None else -1
|
|
21
|
+
self.logger = logger if logger is not None else logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
def __enter__(self):
|
|
24
|
+
# self.search_executor.__enter__() No search support in Lean as of now
|
|
25
|
+
# self.search_executor.run_to_finish()
|
|
26
|
+
# search_exec_local_lemmas_discovered_so_far = [lemma for lemma in self.search_executor.local_file_lemmas]
|
|
27
|
+
# self.search_exec_local_lemmas_discovered_so_far = set([l for l in search_exec_local_lemmas_discovered_so_far if len(l) > 0])
|
|
28
|
+
return self
|
|
29
|
+
|
|
30
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
31
|
+
# self.search_executor.__exit__(exc_type, exc_value, traceback)
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
# def _get_local_lemmas_discovered_so_far_set(self, lean_executor: Lean3Executor):
|
|
35
|
+
# local_lemmas_discovered_so_far = [lemma for lemma in lean_executor.local_file_lemmas][:-1]
|
|
36
|
+
# local_lemmas_discovered_so_far = set([l for l in local_lemmas_discovered_so_far if len(l) > 0])
|
|
37
|
+
# return local_lemmas_discovered_so_far
|
|
38
|
+
|
|
39
|
+
# def _search_exact_with_diff(self, lean_executor: Lean3Executor, tok: str):
|
|
40
|
+
# exact_search_res = self.search_executor.search_exact(tok)
|
|
41
|
+
# local_lemmas_discovered_so_far = self._get_local_lemmas_discovered_so_far_set(lean_executor)
|
|
42
|
+
# diff = self.search_exec_local_lemmas_discovered_so_far.difference(local_lemmas_discovered_so_far)
|
|
43
|
+
# # Remove future lemmas which are yet to be discovered
|
|
44
|
+
# exact_search_res = [res for res in exact_search_res if res[0] not in diff]
|
|
45
|
+
# return exact_search_res
|
|
46
|
+
|
|
47
|
+
# def _search_defn_with_diff(self, lean_executor: Lean3Executor, name: str, match_until: typing.Tuple[str, ...], max_search_res: typing.Optional[int] = None):
|
|
48
|
+
# search_defn_res = self.search_executor.search_defn(name, match_until, max_search_res=max_search_res)
|
|
49
|
+
# local_lemmas_discovered_so_far = self._get_local_lemmas_discovered_so_far_set(lean_executor)
|
|
50
|
+
# diff = self.search_exec_local_lemmas_discovered_so_far.difference(local_lemmas_discovered_so_far)
|
|
51
|
+
# # Remove future lemmas which are yet to be discovered
|
|
52
|
+
# search_defn_res = [res for res in search_defn_res if res[0] not in diff]
|
|
53
|
+
# return search_defn_res
|
|
54
|
+
|
|
55
|
+
# def _get_all_type_matching_defns_with_diff(self, lean_executor: Lean3Executor, tok: str):
|
|
56
|
+
# exact_search_res = self.search_executor.get_all_type_matching_defns(tok)
|
|
57
|
+
# local_lemmas_discovered_so_far = self._get_local_lemmas_discovered_so_far_set(lean_executor)
|
|
58
|
+
# diff = self.search_exec_local_lemmas_discovered_so_far.difference(local_lemmas_discovered_so_far)
|
|
59
|
+
# # Remove future lemmas which are yet to be discovered
|
|
60
|
+
# exact_search_res = [res for res in exact_search_res if res[0] not in diff]
|
|
61
|
+
# return exact_search_res
|
|
62
|
+
|
|
63
|
+
# def _get_variables_in_hyp(self, hyps: List[str], coq_exec: Lean3Executor) -> typing.Set[str]:
|
|
64
|
+
# variables = set()
|
|
65
|
+
# for hyp in hyps:
|
|
66
|
+
# hyp = hyp.strip()
|
|
67
|
+
# defn = hyp.split(":")
|
|
68
|
+
# defn_name = defn[0].strip()
|
|
69
|
+
# # tokenize defn_name
|
|
70
|
+
# possible_vars = set(coq_exec.get_tokens_in_given_stmt(defn_name, ignore_first_token=False))
|
|
71
|
+
# possible_vars = {var for var in possible_vars if var not in coq_exec.token_separator_set}
|
|
72
|
+
# variables.update(possible_vars)
|
|
73
|
+
# return variables
|
|
74
|
+
|
|
75
|
+
# def _get_changed_goal_idx(self, training_data_point: TrainingDataFormat) -> typing.List[int]:
|
|
76
|
+
# # Figure out the subset of start goals which were changed
|
|
77
|
+
# start_goals = dict()
|
|
78
|
+
# for goal in training_data_point.start_goals:
|
|
79
|
+
# if goal.goal in start_goals:
|
|
80
|
+
# start_goals[goal.goal] += 1
|
|
81
|
+
# else:
|
|
82
|
+
# start_goals[goal.goal] = 1
|
|
83
|
+
# end_goals = dict()
|
|
84
|
+
# for goal in training_data_point.end_goals:
|
|
85
|
+
# if goal.goal in end_goals:
|
|
86
|
+
# end_goals[goal.goal] += 1
|
|
87
|
+
# else:
|
|
88
|
+
# end_goals[goal.goal] = 1
|
|
89
|
+
# changed_goals = dict()
|
|
90
|
+
# for goal, cnt in start_goals.items():
|
|
91
|
+
# if goal in end_goals and end_goals[goal] < cnt:
|
|
92
|
+
# changed_goals[goal] = cnt - end_goals[goal]
|
|
93
|
+
# elif goal not in end_goals:
|
|
94
|
+
# changed_goals[goal] = 1
|
|
95
|
+
# else:
|
|
96
|
+
# # The goal was not changed
|
|
97
|
+
# pass
|
|
98
|
+
# changed_goals_idx = []
|
|
99
|
+
# for idx, goal in enumerate(training_data_point.start_goals):
|
|
100
|
+
# if goal.goal in changed_goals and changed_goals[goal.goal] > 0:
|
|
101
|
+
# changed_goals_idx.append(idx)
|
|
102
|
+
# changed_goals[goal.goal] -= 1
|
|
103
|
+
# return changed_goals_idx
|
|
104
|
+
|
|
105
|
+
def get_focussed_goals(self, lean_executor: Lean3Executor) -> List[Goal]:
|
|
106
|
+
# Only consider the foreground goals because we can handle the multi-line tactics
|
|
107
|
+
return [Goal(hypotheses=goal.hypotheses, goal=goal.goal) for goal in lean_executor.proof_context.fg_goals]
|
|
108
|
+
|
|
109
|
+
def get_unfocussed_goals(self, lean_executor: Lean3Executor) -> List[Goal]:
|
|
110
|
+
# Only consider the foreground goals because we can handle the multi-line tactics
|
|
111
|
+
other_goals = lean_executor.proof_context.bg_goals + lean_executor.proof_context.shelved_goals + lean_executor.proof_context.given_up_goals
|
|
112
|
+
return [Goal(hypotheses=goal.hypotheses, goal=goal.goal) for goal in other_goals]
|
|
113
|
+
|
|
114
|
+
def get_local_lemmas(self, lean_executor: Lean3Executor, logger: logging.Logger = None) -> List[typing.Tuple[str, str]]:
|
|
115
|
+
# Search is not supported in Lean as of now
|
|
116
|
+
raise Exception("Search is not supported in Lean as of now")
|
|
117
|
+
# # Since LOCAL retrieval is not intelligent enough to filter out the useless lemmas, we will not filter out the useless lemmas here, and let the model learn it
|
|
118
|
+
# logger = logger if logger is not None else self.logger
|
|
119
|
+
# lemmas = []
|
|
120
|
+
# for lemma_name, lemma_val in lean_executor.local_file_lemmas[:-1]:
|
|
121
|
+
# if len(lemma_name) > 0:
|
|
122
|
+
# lemmas.append((lemma_name, lemma_val))
|
|
123
|
+
# return lemmas
|
|
124
|
+
|
|
125
|
+
def set_relevant_defns_in_training_data_point(self, training_data_point: TrainingDataFormat, lean_executor: Lean3Executor, logger: logging.Logger = None, depth: int = None):
|
|
126
|
+
# Search is not supported in Lean as of now
|
|
127
|
+
raise Exception("Search is not supported in Lean as of now")
|
|
128
|
+
# logger = logger if logger is not None else self.logger
|
|
129
|
+
# depth = self.depth if depth is None else depth
|
|
130
|
+
# unique_defns = {defn: idx for idx, defn in enumerate(training_data_point.all_useful_defns_theorems)}
|
|
131
|
+
# for idx, goal in enumerate(training_data_point.start_goals):
|
|
132
|
+
# current_depth = 0
|
|
133
|
+
# query = training_data_point.get_human_readable_serialized_goal(idx, skip_special_tokens=True)
|
|
134
|
+
# possible_variables = self._get_variables_in_hyp(goal.hypotheses, lean_executor)
|
|
135
|
+
# query_toks = set(lean_executor.get_tokens_in_given_stmt(query, ignore_first_token=False))
|
|
136
|
+
# stack = [(current_depth, tok) for tok in query_toks if tok not in possible_variables]
|
|
137
|
+
# toks_executed = set()
|
|
138
|
+
# depth_map = {}
|
|
139
|
+
# useful_defns_maps : typing.Dict[str, str] = {}
|
|
140
|
+
# full_depth = depth == -1
|
|
141
|
+
# while len(stack) > 0:
|
|
142
|
+
# current_depth, tok = stack.pop()
|
|
143
|
+
# if current_depth > depth and not full_depth:
|
|
144
|
+
# continue
|
|
145
|
+
# if tok in toks_executed:
|
|
146
|
+
# continue
|
|
147
|
+
# else:
|
|
148
|
+
# toks_executed.add(tok)
|
|
149
|
+
# for defn, denf_val in self._search_exact_with_diff(lean_executor, tok):
|
|
150
|
+
# if defn in depth_map:
|
|
151
|
+
# depth_map[defn] = min(depth_map[defn], current_depth)
|
|
152
|
+
# useful_defns_maps[defn] = denf_val
|
|
153
|
+
# else:
|
|
154
|
+
# depth_map[defn] = current_depth
|
|
155
|
+
# useful_defns_maps[defn] = denf_val
|
|
156
|
+
# for stmt_tok in lean_executor.get_tokens_in_given_stmt(denf_val, ignore_first_token=False):
|
|
157
|
+
# if stmt_tok not in toks_executed:
|
|
158
|
+
# stack.append((current_depth + 1, stmt_tok))
|
|
159
|
+
# useful_defns = [(defn, defn_val, Lean3ContextHelper.max_relevance_score/(depth_map[defn] + 1)) for defn, defn_val in useful_defns_maps.items()]
|
|
160
|
+
# useful_defns.sort(key=lambda x: (x[2], x[0]), reverse=True) # sort by relevance
|
|
161
|
+
# for defn, defn_val, _ in useful_defns:
|
|
162
|
+
# if defn not in unique_defns:
|
|
163
|
+
# lemma_idx = len(training_data_point.all_useful_defns_theorems)
|
|
164
|
+
# unique_defns[defn] = lemma_idx
|
|
165
|
+
# training_data_point.all_useful_defns_theorems.append(LemmaReferences(lemma_idx, defn, defn_val, 0))
|
|
166
|
+
# useful_defns = [LemmaRefWithScore(unique_defns[defn], score) for defn, _, score in useful_defns]
|
|
167
|
+
# goal.relevant_defns = useful_defns
|
|
168
|
+
|
|
169
|
+
def set_all_type_matched_query_result(self, training_data_point: TrainingDataFormat, lean_executor: Lean3Executor, logger: logging.Logger = None, depth: int = None):
|
|
170
|
+
unique_thms = {defn.lemma_name: idx for idx, defn in enumerate(training_data_point.all_useful_defns_theorems)}
|
|
171
|
+
# query = training_data_point.get_human_readable_serialized_goal(idx, skip_special_tokens=True)
|
|
172
|
+
relevant_thms = self.search_executor.search_type_matching_defns("") # Here the search simply returns everything
|
|
173
|
+
# Add all lemma references to unique_defns
|
|
174
|
+
for thm in relevant_thms:
|
|
175
|
+
thm_name = f"{thm.namespace}.{thm.name}"
|
|
176
|
+
if thm.name not in unique_thms:
|
|
177
|
+
_idx = len(training_data_point.all_useful_defns_theorems)
|
|
178
|
+
unique_thms[thm_name] = _idx
|
|
179
|
+
training_data_point.all_useful_defns_theorems.append(LemmaReferences(_idx, thm_name, thm.dfn))
|
|
180
|
+
for _, goal in enumerate(training_data_point.start_goals):
|
|
181
|
+
goal.possible_useful_theorems_external = [LemmaRefWithScore(unique_thms[f"{thm.namespace}.{thm.name}"], 1.0) for thm in relevant_thms]
|
|
182
|
+
goal.possible_useful_theorems_local = []
|
|
183
|
+
# Use the hypothesis to find the definition
|
|
184
|
+
# Recursively find the definition of the definition to a fixed depth
|
|
185
|
+
# dump useful_hyps and current stmt into a stack
|
|
186
|
+
# logger = logger if logger is not None else self.logger
|
|
187
|
+
# depth = self.depth if depth is None else depth
|
|
188
|
+
# unique_thms = {defn.lemma_name: idx for idx, defn in enumerate(training_data_point.all_useful_defns_theorems)}
|
|
189
|
+
# for idx, goal in enumerate(training_data_point.start_goals):
|
|
190
|
+
# current_depth = 0
|
|
191
|
+
# query = training_data_point.get_human_readable_serialized_goal(idx, skip_special_tokens=True)
|
|
192
|
+
# possible_variables = self._get_variables_in_hyp(goal.hypotheses, lean_executor)
|
|
193
|
+
# query_toks = set(lean_executor.get_tokens_in_given_stmt(query, ignore_first_token=False))
|
|
194
|
+
# stack = [(current_depth, tok) for tok in query_toks if tok not in possible_variables]
|
|
195
|
+
# toks_executed = set()
|
|
196
|
+
# depth_map = {}
|
|
197
|
+
# useful_defns_maps : typing.Dict[str, str] = {}
|
|
198
|
+
# full_depth = depth == -1
|
|
199
|
+
# while len(stack) > 0:
|
|
200
|
+
# current_depth, tok = stack.pop()
|
|
201
|
+
# if current_depth > depth and not full_depth:
|
|
202
|
+
# continue
|
|
203
|
+
# if tok in toks_executed:
|
|
204
|
+
# continue
|
|
205
|
+
# else:
|
|
206
|
+
# toks_executed.add(tok)
|
|
207
|
+
# for defn, denf_val in self._get_all_type_matching_defns_with_diff(lean_executor, tok):
|
|
208
|
+
# if defn in depth_map:
|
|
209
|
+
# depth_map[defn] = min(depth_map[defn], current_depth)
|
|
210
|
+
# else:
|
|
211
|
+
# depth_map[defn] = current_depth
|
|
212
|
+
# useful_defns_maps[defn] = denf_val
|
|
213
|
+
# if current_depth + 1 <= depth or full_depth:
|
|
214
|
+
# for stmt_tok in lean_executor.get_tokens_in_given_stmt(denf_val, ignore_first_token=False):
|
|
215
|
+
# if stmt_tok not in toks_executed:
|
|
216
|
+
# stack.append((current_depth + 1, stmt_tok))
|
|
217
|
+
# useful_theorems = [(defn, defn_val, Lean3ContextHelper.max_relevance_score/(depth_map[defn] + 1)) for defn, defn_val in useful_defns_maps.items()]
|
|
218
|
+
# useful_theorems.sort(key=lambda x: (x[2], x[0]), reverse=True) # sort by relevance
|
|
219
|
+
# useful_local_theorems = []
|
|
220
|
+
# useful_external_theorems = []
|
|
221
|
+
# for defn, defn_val, score in useful_theorems:
|
|
222
|
+
# if defn not in unique_thms:
|
|
223
|
+
# lemma_idx = len(training_data_point.all_useful_defns_theorems)
|
|
224
|
+
# unique_thms[defn] = lemma_idx
|
|
225
|
+
# training_data_point.all_useful_defns_theorems.append(LemmaReferences(lemma_idx, defn, defn_val, 0))
|
|
226
|
+
# if defn in self.search_exec_local_lemmas_discovered_so_far:
|
|
227
|
+
# useful_local_theorems.append((defn, defn_val, score))
|
|
228
|
+
# else:
|
|
229
|
+
# useful_external_theorems.append((defn, defn_val, score))
|
|
230
|
+
# useful_local_theorems = [(unique_thms[defn], score) for defn, _, score in useful_local_theorems]
|
|
231
|
+
# useful_external_theorems = [(unique_thms[defn], score) for defn, _, score in useful_external_theorems]
|
|
232
|
+
# goal.used_theorems_local = []
|
|
233
|
+
# goal.used_theorems_external = []
|
|
234
|
+
# goal.possible_useful_theorems_external = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_external_theorems if score <= Lean3ContextHelper.max_relevance_score]
|
|
235
|
+
# goal.possible_useful_theorems_local = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_local_theorems if score <= Lean3ContextHelper.max_relevance_score]
|
|
236
|
+
|
|
237
|
+
def set_useful_defns_theorems_for_training_data_generation(self, current_stmt: str, training_data_point: TrainingDataFormat, lean_executor: Lean3Executor, logger: logging.Logger = None, depth: int = None, max_search_res: typing.Optional[int] = None):
|
|
238
|
+
# Search is not supported in Lean as of now
|
|
239
|
+
raise Exception("Search is not supported in Lean as of now")
|
|
240
|
+
# # Use the hypothesis to find the definition
|
|
241
|
+
# # Recursively find the definition of the definition to a fixed depth
|
|
242
|
+
# # dump useful_hyps and current stmt into a stack
|
|
243
|
+
# logger = logger if logger is not None else self.logger
|
|
244
|
+
# depth = self.depth if depth is None else depth
|
|
245
|
+
# current_stmt_toks = tuple(lean_executor.get_tokens_in_given_stmt(current_stmt, ignore_first_token=True))
|
|
246
|
+
# unique_thms = {defn: idx for idx, defn in enumerate(training_data_point.all_useful_defns_theorems)}
|
|
247
|
+
# changed_goal_idx = set(self._get_changed_goal_idx(training_data_point))
|
|
248
|
+
# for idx, goal in enumerate(training_data_point.start_goals):
|
|
249
|
+
# # if idx not in changed_goal_idx:
|
|
250
|
+
# # continue
|
|
251
|
+
# current_depth = 0
|
|
252
|
+
# query = training_data_point.get_human_readable_serialized_goal(idx, skip_special_tokens=True)
|
|
253
|
+
# possible_variables = self._get_variables_in_hyp(goal.hypotheses, lean_executor)
|
|
254
|
+
# query_toks = set(lean_executor.get_tokens_in_given_stmt(query, ignore_first_token=False))
|
|
255
|
+
# stack = [(current_depth, tok) for tok in query_toks if tok not in possible_variables]
|
|
256
|
+
# toks_executed = set()
|
|
257
|
+
# depth_map = {}
|
|
258
|
+
# useful_defns_maps : typing.Dict[str, str] = {}
|
|
259
|
+
# full_depth = depth == -1
|
|
260
|
+
# while len(stack) > 0:
|
|
261
|
+
# current_depth, tok = stack.pop()
|
|
262
|
+
# if current_depth > depth and not full_depth:
|
|
263
|
+
# continue
|
|
264
|
+
# if tok in toks_executed:
|
|
265
|
+
# continue
|
|
266
|
+
# else:
|
|
267
|
+
# toks_executed.add(tok)
|
|
268
|
+
# for defn, denf_val, is_used in self._search_defn_with_diff(lean_executor, tok, current_stmt_toks, max_search_res=max_search_res):
|
|
269
|
+
# if defn in depth_map:
|
|
270
|
+
# depth_map[defn] = min(depth_map[defn], current_depth)
|
|
271
|
+
# old_val, was_used_earlier = useful_defns_maps[defn]
|
|
272
|
+
# current_defn_val = None
|
|
273
|
+
# if was_used_earlier:
|
|
274
|
+
# current_defn_val = old_val
|
|
275
|
+
# else:
|
|
276
|
+
# current_defn_val = denf_val
|
|
277
|
+
# useful_defns_maps[defn] = (current_defn_val, was_used_earlier or is_used)
|
|
278
|
+
# else:
|
|
279
|
+
# depth_map[defn] = current_depth
|
|
280
|
+
# useful_defns_maps[defn] = (denf_val, is_used)
|
|
281
|
+
# if current_depth + 1 <= depth or full_depth:
|
|
282
|
+
# for stmt_tok in lean_executor.get_tokens_in_given_stmt(denf_val, ignore_first_token=False):
|
|
283
|
+
# if stmt_tok not in toks_executed:
|
|
284
|
+
# stack.append((current_depth + 1, stmt_tok))
|
|
285
|
+
# useful_theorems = [(defn, defn_val, 1.0 if is_used else Lean3ContextHelper.max_relevance_score/(depth_map[defn] + 1)) for defn, (defn_val, is_used) in useful_defns_maps.items()]
|
|
286
|
+
# useful_theorems.sort(key=lambda x: (x[2], x[0]), reverse=True) # sort by relevance
|
|
287
|
+
# useful_local_theorems = []
|
|
288
|
+
# useful_external_theorems = []
|
|
289
|
+
# for defn, defn_val, defn_score in useful_theorems:
|
|
290
|
+
# if defn not in unique_thms:
|
|
291
|
+
# lemma_idx = len(training_data_point.all_useful_defns_theorems)
|
|
292
|
+
# unique_thms[defn] = lemma_idx
|
|
293
|
+
# training_data_point.all_useful_defns_theorems.append(LemmaReferences(lemma_idx, defn, defn_val, 0))
|
|
294
|
+
# if defn in self.search_exec_local_lemmas_discovered_so_far:
|
|
295
|
+
# useful_local_theorems.append((defn, defn_val, defn_score))
|
|
296
|
+
# else:
|
|
297
|
+
# useful_external_theorems.append((defn, defn_val, defn_score))
|
|
298
|
+
# useful_local_theorems = [(unique_thms[defn], defn_score) for defn, _, defn_score in useful_local_theorems]
|
|
299
|
+
# useful_external_theorems = [(unique_thms[defn], defn_score) for defn, _, defn_score in useful_external_theorems]
|
|
300
|
+
# if idx in changed_goal_idx:
|
|
301
|
+
# # Only assign used theorems if it was in changed goals
|
|
302
|
+
# goal.used_theorems_local = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_local_theorems if score > Lean3ContextHelper.max_relevance_score]
|
|
303
|
+
# goal.used_theorems_external = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_external_theorems if score > Lean3ContextHelper.max_relevance_score]
|
|
304
|
+
# if len(goal.used_theorems_local) > 0:
|
|
305
|
+
# for lemma_ref in goal.used_theorems_local:
|
|
306
|
+
# training_data_point.all_useful_defns_theorems[lemma_ref.lemma_idx].ref_count += 1
|
|
307
|
+
# if len(goal.used_theorems_external) > 0:
|
|
308
|
+
# for lemma_ref in goal.used_theorems_external:
|
|
309
|
+
# training_data_point.all_useful_defns_theorems[lemma_ref.lemma_idx].ref_count += 1
|
|
310
|
+
# goal.possible_useful_theorems_local = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_local_theorems if score <= Lean3ContextHelper.max_relevance_score]
|
|
311
|
+
# goal.possible_useful_theorems_external = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_external_theorems if score <= Lean3ContextHelper.max_relevance_score]
|
|
312
|
+
|
|
313
|
+
def set_local_thms_dfns(self, training_data_point: TrainingDataFormat, lean_executor: Lean3Executor, logger: logging.Logger = None):
|
|
314
|
+
# Search is not supported in Lean as of now
|
|
315
|
+
raise Exception("Search is not supported in Lean as of now")
|
|
316
|
+
# local_lemmas = self.get_local_lemmas(lean_executor, logger)
|
|
317
|
+
# unique_thms = {defn.lemma_name: idx for idx, defn in enumerate(training_data_point.all_useful_defns_theorems)}
|
|
318
|
+
# useful_local_theorems = []
|
|
319
|
+
# for defn, defn_val in local_lemmas:
|
|
320
|
+
# if defn not in unique_thms:
|
|
321
|
+
# lemma_idx = len(training_data_point.all_useful_defns_theorems)
|
|
322
|
+
# unique_thms[defn] = lemma_idx
|
|
323
|
+
# training_data_point.all_useful_defns_theorems.append(LemmaReferences(lemma_idx, defn, defn_val, 0))
|
|
324
|
+
# if defn in self.search_exec_local_lemmas_discovered_so_far:
|
|
325
|
+
# useful_local_theorems.append((unique_thms[defn], Lean3ContextHelper.max_relevance_score))
|
|
326
|
+
# for goal in training_data_point.start_goals:
|
|
327
|
+
# goal.possible_useful_theorems_local = [LemmaRefWithScore(defn_idx, score) for defn_idx, score in useful_local_theorems if score <= Lean3ContextHelper.max_relevance_score]
|
|
@@ -0,0 +1,206 @@
|
|
|
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 typing
|
|
9
|
+
import json
|
|
10
|
+
import uuid
|
|
11
|
+
import yaml
|
|
12
|
+
from itp_interface.lean_server.lean_context import ProofContext
|
|
13
|
+
from itp_interface.lean_server.lean4_utils import Lean4Utils
|
|
14
|
+
from itp_interface.tools.training_data import TrainingData
|
|
15
|
+
from itp_interface.tools.training_data_format import Goal, MergableCollection, TrainingDataCollection, TrainingDataFormat, TrainingDataMetadataFormat
|
|
16
|
+
from itp_interface.tools.coq_training_data_generator import GenericTrainingDataGenerationTransform, TrainingDataGenerationType
|
|
17
|
+
|
|
18
|
+
class LocalDataGenerationTransform(GenericTrainingDataGenerationTransform):
|
|
19
|
+
def __init__(self,
|
|
20
|
+
depth = None,
|
|
21
|
+
max_search_results = None,
|
|
22
|
+
buffer_size : int = 10000,
|
|
23
|
+
logger = None,
|
|
24
|
+
max_parallelism : int = 4):
|
|
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
|
+
|
|
30
|
+
def get_meta_object(self) -> MergableCollection:
|
|
31
|
+
return TrainingDataMetadataFormat(training_data_buffer_size=self.buffer_size)
|
|
32
|
+
|
|
33
|
+
def get_data_collection_object(self) -> MergableCollection:
|
|
34
|
+
return TrainingDataCollection()
|
|
35
|
+
|
|
36
|
+
def load_meta_from_file(self, file_path) -> MergableCollection:
|
|
37
|
+
return TrainingDataMetadataFormat.load_from_file(file_path)
|
|
38
|
+
|
|
39
|
+
def load_data_from_file(self, file_path) -> MergableCollection:
|
|
40
|
+
return TrainingDataCollection.load_from_file(file_path, self.logger)
|
|
41
|
+
|
|
42
|
+
def dump_theorems_from_file(self, file_path: str, output_path: str, output_filename: str, logger = None):
|
|
43
|
+
assert file_path.endswith('.json'), f"Invalid file path {file_path}"
|
|
44
|
+
assert output_filename.endswith('.yaml'), f"Invalid output filename {output_filename}"
|
|
45
|
+
if logger is None:
|
|
46
|
+
logger = self.logger
|
|
47
|
+
logger.info(f"Dumping theorems from {file_path} to {output_path}/{output_filename}")
|
|
48
|
+
# 1. Load the Lean Dojo file formatted json
|
|
49
|
+
# 2. Extract theorems from the json
|
|
50
|
+
# The Lean Dojo json format is as follows:
|
|
51
|
+
# [
|
|
52
|
+
# {
|
|
53
|
+
# "url": "https://github.com/leanprover-community/mathlib",
|
|
54
|
+
# "commit": "8c1b484d6a214e059531e22f1be9898ed6c1fd47",
|
|
55
|
+
# "file_path": "src/linear_algebra/basis.lean",
|
|
56
|
+
# "full_name": "basis.sum_coords_self_apply",
|
|
57
|
+
# "traced_tactics":[
|
|
58
|
+
# {
|
|
59
|
+
# "tactic": "simpa ...",
|
|
60
|
+
# "state_before": "G : .....",
|
|
61
|
+
# "state_after": "no goals"
|
|
62
|
+
# },
|
|
63
|
+
# {
|
|
64
|
+
# "tactic": "simpa ...",
|
|
65
|
+
# "state_before": "G : .....",
|
|
66
|
+
# "state_after": "no goals"
|
|
67
|
+
# },
|
|
68
|
+
# ]
|
|
69
|
+
# }
|
|
70
|
+
# ]
|
|
71
|
+
with open(file_path, 'r') as f:
|
|
72
|
+
dojo_json = json.load(f)
|
|
73
|
+
output_filepath = os.path.join(output_path, output_filename)
|
|
74
|
+
output_dict = {
|
|
75
|
+
"name": output_filename[:-len('.yaml')],
|
|
76
|
+
"num_files": 0,
|
|
77
|
+
"language": "LEAN",
|
|
78
|
+
"few_shot_data_path_for_retrieval": None,
|
|
79
|
+
"few_shot_metadata_filename_for_retrieval": None,
|
|
80
|
+
"dfs_data_path_for_retrieval": None,
|
|
81
|
+
"dfs_metadata_filename_for_retrieval": None,
|
|
82
|
+
"datasets": []
|
|
83
|
+
}
|
|
84
|
+
datasets : list = output_dict['datasets']
|
|
85
|
+
projects = {}
|
|
86
|
+
for dojo_entry in dojo_json:
|
|
87
|
+
if dojo_entry['url'] not in projects:
|
|
88
|
+
project_details = {}
|
|
89
|
+
projects[dojo_entry['url']] = project_details
|
|
90
|
+
project_details['files_dict'] = {}
|
|
91
|
+
project_details['files'] = []
|
|
92
|
+
# Just use the last part of the url as the project name
|
|
93
|
+
datasets.append(
|
|
94
|
+
{
|
|
95
|
+
"project": f"data/benchmarks/{dojo_entry['url'].strip('/').split('/')[-1]}",
|
|
96
|
+
"files": project_details['files'],
|
|
97
|
+
})
|
|
98
|
+
logger.info(f"Processing project {dojo_entry['url']}")
|
|
99
|
+
else:
|
|
100
|
+
project_details = projects[dojo_entry['url']]
|
|
101
|
+
if dojo_entry['file_path'] not in project_details['files_dict']:
|
|
102
|
+
theorems_in_file = []
|
|
103
|
+
project_details['files_dict'][dojo_entry['file_path']] = theorems_in_file
|
|
104
|
+
output_dict['num_files'] += 1
|
|
105
|
+
project_details['files'].append(
|
|
106
|
+
{
|
|
107
|
+
"path": dojo_entry['file_path'],
|
|
108
|
+
"theorems": theorems_in_file
|
|
109
|
+
})
|
|
110
|
+
logger.info(f"Processing file {dojo_entry['file_path']}")
|
|
111
|
+
else:
|
|
112
|
+
theorems_in_file = project_details['files_dict'][dojo_entry['file_path']]
|
|
113
|
+
theorems_in_file.append(dojo_entry['full_name'])
|
|
114
|
+
with open(output_filepath, 'w') as f:
|
|
115
|
+
yaml.dump(output_dict, f, indent=2)
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
def __call__(self, training_data: TrainingData, project_id : str, executor, print_executor_callback, theorems: typing.List[str] = None) -> TrainingData:
|
|
119
|
+
assert isinstance(training_data, TrainingData)
|
|
120
|
+
assert isinstance(project_id, str)
|
|
121
|
+
json_path = project_id
|
|
122
|
+
assert json_path.endswith('.json'), f"Invalid json path {json_path}"
|
|
123
|
+
assert os.path.exists(json_path), f"Invalid json path {json_path}"
|
|
124
|
+
self.logger.info(f"Generating training data for {project_id}")
|
|
125
|
+
with open(json_path, 'r') as f:
|
|
126
|
+
json_data = json.load(f)
|
|
127
|
+
# Go over all the theorems in the json file and generate training data for them
|
|
128
|
+
for dojo_entry in json_data:
|
|
129
|
+
project_path = f"data/benchmarks/{dojo_entry['url'].strip('/').split('/')[-1]}"
|
|
130
|
+
file_path = dojo_entry['file_path']
|
|
131
|
+
theorem_name = dojo_entry['full_name']
|
|
132
|
+
theorem_id = str(uuid.uuid4())
|
|
133
|
+
for tactic in dojo_entry['traced_tactics']:
|
|
134
|
+
state_after = tactic['state_after']
|
|
135
|
+
state_before = tactic['state_before']
|
|
136
|
+
tactic = tactic['tactic']
|
|
137
|
+
try:
|
|
138
|
+
start_goals: ProofContext = Lean4Utils.parse_proof_context_human_readable(state_before)
|
|
139
|
+
end_goals: ProofContext = Lean4Utils.parse_proof_context_human_readable(state_after)
|
|
140
|
+
except Exception as e:
|
|
141
|
+
print(f"Error parsing proof context for {theorem_id} {theorem_name} \ntactic: {tactic}")
|
|
142
|
+
print("State before:")
|
|
143
|
+
print(state_before)
|
|
144
|
+
self.logger.error(f"Error parsing proof context for {theorem_id} {theorem_name} {tactic}")
|
|
145
|
+
self.logger.error(f"Error: \n{e}")
|
|
146
|
+
print("State after:")
|
|
147
|
+
print(state_after)
|
|
148
|
+
raise
|
|
149
|
+
if len(start_goals.all_goals) > 0:
|
|
150
|
+
# Create a training data object
|
|
151
|
+
training_data_format = TrainingDataFormat(
|
|
152
|
+
proof_id=theorem_id,
|
|
153
|
+
start_goals=[Goal(goal.hypotheses, goal.goal) for goal in start_goals.all_goals],
|
|
154
|
+
end_goals=[Goal(goal.hypotheses, goal.goal) for goal in end_goals.all_goals],
|
|
155
|
+
proof_steps=[tactic],
|
|
156
|
+
file_path=file_path,
|
|
157
|
+
project_id=project_path,
|
|
158
|
+
theorem_name=theorem_name
|
|
159
|
+
)
|
|
160
|
+
training_data.merge(training_data_format)
|
|
161
|
+
pass
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
if __name__ == "__main__":
|
|
165
|
+
import os
|
|
166
|
+
import logging
|
|
167
|
+
import time
|
|
168
|
+
import argparse
|
|
169
|
+
parser = argparse.ArgumentParser()
|
|
170
|
+
parser.add_argument("--input_json", type=str, default=f".log/benchmarks/leandojo_benchmark_4/leandojo_benchmark_4/random/val.json")
|
|
171
|
+
parser.add_argument("--output_dir", type=str, default=f"<root>/data/proofsteps/leandojo/random/val")
|
|
172
|
+
args = parser.parse_args()
|
|
173
|
+
if "<root>" in args.output_dir:
|
|
174
|
+
# Get root from os.environ
|
|
175
|
+
args.output_dir = args.output_dir.replace("<root>/", os.environ.get("ROOT", "").trim('/') + "/")
|
|
176
|
+
os.chdir(root_dir)
|
|
177
|
+
project_dir = "data/test/lean_proj"
|
|
178
|
+
file_name = "data/test/lean_proj/src/simple_solved.lean"
|
|
179
|
+
project_id = project_dir.replace('/', '.')
|
|
180
|
+
time_str = time.strftime("%Y%m%d-%H%M%S")
|
|
181
|
+
output_path = os.path.join(args.output_dir, time_str) # f".log/run_data_generation_transforms/data/{time_str}"
|
|
182
|
+
log_path = f".log/run_data_generation_transforms/log/{time_str}"
|
|
183
|
+
log_file = f"{log_path}/run_data_generation_transforms-{time_str}.log"
|
|
184
|
+
os.makedirs(output_path, exist_ok=True)
|
|
185
|
+
os.makedirs(log_path, exist_ok=True)
|
|
186
|
+
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
|
|
187
|
+
logger = logging.getLogger(__name__)
|
|
188
|
+
# Dump the files and theorems from the Lean Dojo benchmark
|
|
189
|
+
from itp_interface.tools.run_data_generation_transforms import RunDataGenerationTransforms
|
|
190
|
+
transform = LocalDataGenerationTransform(0, buffer_size=1000, logger=logger)
|
|
191
|
+
final_training_meta = transform.get_meta_object()
|
|
192
|
+
final_training_meta.training_data_buffer_size = transform.buffer_size
|
|
193
|
+
final_training_meta.data_filename_prefix = RunDataGenerationTransforms.get_data_filename_prefix(transform)
|
|
194
|
+
final_training_meta.data_filename_suffix = RunDataGenerationTransforms.get_data_filename_suffix(transform)
|
|
195
|
+
final_training_meta.lemma_ref_filename_prefix = RunDataGenerationTransforms.get_lemma_ref_filename_prefix(transform)
|
|
196
|
+
final_training_meta.lemma_ref_filename_suffix = RunDataGenerationTransforms.get_lemma_ref_filename_suffix(transform)
|
|
197
|
+
training_data = TrainingData(output_path, "local.meta.json", final_training_meta, logger=logger)
|
|
198
|
+
transform(training_data, args.input_json, None, None, None)
|
|
199
|
+
save_info = training_data.save()
|
|
200
|
+
logger.info(f"Saved training data to {save_info}")
|
|
201
|
+
# transform.dump_theorems_from_file(".log/benchmarks/leandojo_benchmark/random/test.json", "itp_interface/main/config/benchmark", "leandojo_random_test.yaml")
|
|
202
|
+
# transform.dump_theorems_from_file(".log/benchmarks/leandojo_benchmark/random/train.json", "itp_interface/main/config/benchmark", "leandojo_random_train.yaml")
|
|
203
|
+
# transform.dump_theorems_from_file(".log/benchmarks/leandojo_benchmark/random/val.json", "itp_interface/main/config/benchmark", "leandojo_random_val.yaml")
|
|
204
|
+
# transform.dump_theorems_from_file(".log/benchmarks/leandojo_benchmark/novel_premises/test.json", "itp_interface/main/config/benchmark", "leandojo_novel_premises_test.yaml")
|
|
205
|
+
# transform.dump_theorems_from_file(".log/benchmarks/leandojo_benchmark/novel_premises/train.json", "itp_interface/main/config/benchmark", "leandojo_novel_premises_train.yaml")
|
|
206
|
+
# transform.dump_theorems_from_file(".log/benchmarks/leandojo_benchmark/novel_premises/val.json", "itp_interface/main/config/benchmark", "leandojo_novel_premises_val.yaml")
|