### Install ReProver Starting Retriever Model Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This command downloads the model checkpoint for ReProver's Starting Retriever from Google Drive and instructs where to place the downloaded file. ```Bash gdown https://drive.google.com/uc?id=1aRd1jQPu_TX15Ib5htzn3wZqHYowl3ax # Move the downloaded file to: # {RAID_DIR}/checkpoints/ # {RAID_DIR}/{CHECKPOINT_DIR}/ ``` -------------------------------- ### Setup LeanAgent Environment Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This snippet demonstrates how to create and activate a Conda environment for LeanAgent, install dependencies from requirements.txt, and set up the GITHUB_ACCESS_TOKEN environment variable. ```Bash conda create -n "LeanAgent" python=3.10 conda activate LeanAgent pip install -r requirements.txt export GITHUB_ACCESS_TOKEN= ``` -------------------------------- ### Download Starting FIM for Mathlib Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This command downloads the starting Fisher Information Matrix (FIM) for mathlib, which is required for Elastic Weight Consolidation (EWC) in LeanAgent. ```Bash gdown https://drive.google.com/uc?id=1Q8yHq7XTAaHXGCiCGmhwZhTfkhHhN1cP # Move the downloaded file to your FISHER_DIR. ``` -------------------------------- ### Run LeanAgent Main Script Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This command executes the main LeanAgent script after all setup and configuration steps have been completed. ```Bash bash run_leanagent.sh ``` -------------------------------- ### Install ReProver Tactic Generator Model Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This sequence installs the gdown utility and downloads the model checkpoint for ReProver's Tactic Generator from Google Drive, then moves it to the specified directory. ```Bash pip install gdown gdown https://drive.google.com/uc?id=11DXxixg6S4-hUA-u-78geOxEB7J7rCoX mv downloaded_file {RAID_DIR}/ ``` -------------------------------- ### Install Latest LeanAgent Checkpoint Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This command downloads the latest LeanAgent checkpoint from Google Drive, intended for use with the framework. ```Bash gdown https://drive.google.com/uc?id=1plkC7Y5n0OVCJ0Ad6pH8_mwbALKYY_FY # Move the downloaded file to {RAID_DIR}/checkpoints/ ``` -------------------------------- ### Fisher Information Matrix (FIM) Computation Source: https://github.com/lean-dojo/leanagent/blob/main/README.md The Fisher Information Matrix (FIM) is computed using forward passes through the model with training data. Gradients of the model's log-likelihood with respect to parameters are calculated, squared, and averaged across training examples. The FIM is saved by the global zero process to prevent redundant writes. ```Python # Conceptual steps for FIM computation (implementation details omitted) # 1. Perform forward passes with training data # 2. Compute gradients of log-likelihood w.r.t. parameters # 3. Square gradients and average across examples # 4. Save FIM by the global zero process ``` -------------------------------- ### Configure EWC Fisher Computation Script Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This outlines the configuration steps for the run_compute_fisher.sh script, including setting the RAID_DIR and GITHUB_ACCESS_TOKEN environment variables for EWC computations. ```Bash # Set the RAID_DIR variable to your desired directory path # Update the Conda path in the source command to match your installation # Add your GitHub personal access token as the environment variable GITHUB_ACCESS_TOKEN ``` -------------------------------- ### Run LeanAgent Unit Tests Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This command sequence activates the LeanAgent Conda environment and then executes the project's unit tests using pytest. ```Bash conda activate LeanAgent python -m pytest tests/ ``` -------------------------------- ### Run LeanAgent with EWC Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This describes the iterative process of using Elastic Weight Consolidation (EWC) for lifelong learning by alternating between running the LeanAgent and computing the Fisher Information Matrix. ```Bash # Run LeanAgent for one epoch (or until EWC is triggered) bash run_leanagent.sh # Compute the FIM for EWC bash run_compute_fisher.sh # Repeat for the next epoch ``` -------------------------------- ### LeanAgent Theorem Proving Process Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Details the steps LeanAgent takes to prove theorems marked with 'sorry' in Lean files. This includes building a knowledge base, constructing a dependency graph, retrieving relevant premises, generating tactic candidates via beam search, and applying tactics to search for a proof. ```Python def prove_theorem(theorem_id): # 1. Process premise corpus to build knowledge base knowledge_base = build_knowledge_base(theorem_id) # 2. Construct dependency graph dependency_graph = build_dependency_graph(theorem_id) # 3. Proof search for each proof state proof_found = False for proof_state in get_proof_states(theorem_id): relevant_premises = retrieve_premises(proof_state, knowledge_base) filtered_premises = filter_premises(relevant_premises) tactic_candidates = beam_search_tactics(proof_state, filtered_premises) for tactic in tactic_candidates: next_state = apply_tactic(proof_state, tactic, dependency_graph) if is_proof_complete(next_state): save_proof(theorem_id, next_state) proof_found = True break add_to_search_tree(proof_state, next_state, tactic) select_next_tactic(tactic) if proof_found: break return proof_found ``` -------------------------------- ### Extracting Theorem and Premise Data with LeanDojo Trace Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This snippet describes the process of using LeanDojo's `trace` function to extract theorem definitions, proofs, premises, and their dependencies from Lean repositories. It involves parsing Lean files, identifying theorems and proofs, and building dependency graphs. ```Python from leandojo.trace import trace # Assuming 'repo_path' is the path to a cloned Lean repository # and 'output_dir' is where the traced data will be saved trace(repo_path, output_dir) ``` -------------------------------- ### Configure LeanAgent Python Script Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This describes the necessary global variable modifications within the leanagent.py script to configure data directories, checkpoint paths, and evaluation file locations. It also mentions adjusting options for different training configurations. ```Python # Set the following global variables: repo_dir = "/path/to/your/repository" DATA_DIR = "/path/to/data" CHECKPOINT_DIR = "/path/to/checkpoints" EVAL_RESULTS_FILE_PATH = "/path/to/evaluation_results.txt" DB_FILE_NAME = "leanagent.db" PROOF_LOG_FILE_NAME = "proof_log.txt" ENCOUNTERED_THEOREMS_FILE = "encountered_theorems.txt" # Optional: FISHER_DIR = "/path/to/fisher_matrices" ``` -------------------------------- ### LeanAgent Repository Contribution Workflow Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Outlines the process for integrating a successfully generated proof into a Lean repository. This involves creating a new branch, replacing 'sorry' keywords with the proof text, committing the changes, and submitting a pull request. ```Python def contribute_proof(repository_path, theorem_id, proof_text): # 1. Create a temporary branch create_branch(repository_path, f"leanagent-proof-{theorem_id}") # 2. Locate and replace 'sorry' keywords replace_sorry_with_proof(repository_path, theorem_id, proof_text) # 3. Commit and push changes commit_changes(repository_path, f"feat: Add LeanAgent proof for theorem {theorem_id}") push_branch(repository_path, f"leanagent-proof-{theorem_id}") # 4. Create a pull request create_pull_request( repository_path, f"LeanAgent Proof for Theorem {theorem_id}", f"This PR adds a proof for theorem {theorem_id} generated by LeanAgent." ) ``` -------------------------------- ### LeanAgent Database Persistence (Python) Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Demonstrates how LeanAgent's database components are serialized to and deserialized from a JSON format using `to_dict` and `from_dict` methods. This enables persistence between runs and distribution across computing resources. ```Python class LeanObject: def to_dict(self): # Implementation to convert object to dictionary pass @classmethod def from_dict(cls, data): # Implementation to create object from dictionary pass # Example usage with a Theorem object # theorem_data = theorem_instance.to_dict() # new_theorem = Theorem.from_dict(theorem_data) ``` -------------------------------- ### Lean Repository Compatibility Check Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This snippet outlines the logic for checking Lean repository compatibility by examining the `lean-toolchain` file for supported Lean versions, ranging from `4.3.0-rc2` to `4.8.0-rc1`. ```Lean -- Example of checking lean-toolchain content (conceptual) -- In a real scenario, this would involve file I/O and version parsing in Python. -- For demonstration, imagine a function that reads the toolchain file: -- check_lean_version(repo_path) -> bool ``` -------------------------------- ### LeanAgent Curriculum Complexity Calculation (Conceptual) Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Illustrates the conceptual calculation of theorem complexity using an exponential function of proof steps ($e^S$) for LeanAgent's curriculum learning strategy. ```Python # Conceptual representation of complexity calculation def calculate_complexity(num_proof_steps): if num_proof_steps == float('inf'): # For 'sorry' theorems return float('inf') return math.exp(num_proof_steps) # Example usage: # complexity = calculate_complexity(theorem.num_proof_steps) ``` -------------------------------- ### Exporting Theorem Proofs and Metadata Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This snippet details the structure of exported theorem data, including the theorem statement, proof tactics, annotated tactics, and proof states. It also mentions the export of premise definitions in a topologically sorted order. ```Python # Conceptual representation of exported theorem data structure exported_theorem = { "statement": "...", "proof_tactics": ["tactic1", "tactic2"], "annotated_tactics": [{"tactic": "tactic1", "premises_used": ["premise1"] }], "proof_states": [{"before": "state1", "after": "state2"}] } # Conceptual representation of exported premise data structure exported_premise = { "full_name": "...", "code": "...", "source_position": {...}, "kind": "theorem" | "lemma" | "definition" } # Conceptual representation of dataset metadata metadata = { "creation_timestamp": "...", "source_repository": { "url": "...", "commit": "..." }, "leandojo_version": "..." } ``` -------------------------------- ### Lean Premise File Representation Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Defines the structure for representing a Lean source file containing premises. It includes the file path, imported modules, and a list of premises. ```Lean structure PremiseFile := ( filePath : String, -- Path to the Lean source file imports : List String, -- List of imported modules premises : List Premise -- List of premises defined in the file ) ``` -------------------------------- ### Lean Repository Representation Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Defines the structure for representing a Lean GitHub repository. It includes metadata, categorized theorems, and premise files. ```Lean structure Repository := ( url : String, -- URL of the GitHub repository name : String, -- Name of the repository commit : String, -- Current commit SHA leanVersion : String, -- Lean version used provenTheorems : List Theorem, -- Theorems with complete proofs sorryTheorems : List Theorem, -- Theorems marked with 'sorry' unprovenTheorems : List Theorem, -- Theorems previously unproven, now proven by LeanAgent premiseFiles : List PremiseFile -- List of premise files in the repository ) ``` -------------------------------- ### Adjust Lean Toolchain Paths Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This Python code snippet shows how to dynamically set Lean toolchain paths, which is crucial for ensuring the correct version of Lean is used by the agent. ```Python lean_dir2 = f"/.elan/toolchains/leanprover--lean4--{v}" lean_dir3 = f"~/.elan/toolchains/leanprover--lean4--{v}" ``` -------------------------------- ### Update File Paths with Bash Source: https://github.com/lean-dojo/leanagent/blob/main/README.md This command executes a bash script to update file paths, likely for configuring project directories. ```Bash bash replace_files.sh ``` -------------------------------- ### Distributed Training with PyTorch Lightning DDP Source: https://github.com/lean-dojo/leanagent/blob/main/README.md LeanAgent utilizes PyTorch Lightning's Distributed Data Parallel (DDP) strategy for efficient multi-GPU training. This approach ensures synchronized gradient updates across devices, maintaining model consistency during progressive learning. Custom timeout settings are employed to manage lengthy operations. ```Python from pytorch_lightning.strategies import DDPStrategy # Example configuration within a PyTorch Lightning Trainer trainer = Trainer( accelerator="gpu", devices=4, # Example: 4 NVIDIA A100s strategy=DDPStrategy(timeout=timedelta(seconds=3600)) # Custom timeout ) ``` -------------------------------- ### Lean Premise Representation Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Defines the structure for representing a mathematical premise (fact) in Lean. It includes its name, code, source positions, and type. ```Lean structure Premise := ( name : String, -- Fully qualified name of the premise code : String, -- The Lean code defining the premise startPos : SourcePos, -- Start source code position endPos : SourcePos, -- End source code position premiseType : String -- Type of premise (e.g., theorem, definition, axiom) ) ``` -------------------------------- ### Lean Theorem Representation Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Defines the structure for representing a Lean theorem within the LeanAgent system. It includes metadata, the theorem statement, and traced tactics, along with a difficulty rating for curriculum learning. ```Lean structure Theorem := ( name : String, -- Fully qualified name of the theorem filePath : String, -- Path to the file defining the theorem sourcePos : SourcePos, -- Source code positions of the theorem definition url : String, -- URL of the repository commit : String, -- Commit SHA of the repository statement : String, -- The theorem statement tracedTactics : List Tactic, -- Sequence of tactics proving the theorem difficulty : Float -- Difficulty rating for curriculum learning ) ``` -------------------------------- ### LeanAgent Citation Source: https://github.com/lean-dojo/leanagent/blob/main/README.md Citation details for the LeanAgent research paper, including title, authors, and conference information. ```BibTeX @inproceedings{kumarappan2025leanagent, title={{LeanAgent}: Lifelong Learning for Formal Theorem Proving}, author={Kumarappan, Adarsh and Tiwari, Mo and Song, Peiyang and George, Robert Joseph and Xiao, Chaowei and Anandkumar, Anima}, booktitle={International Conference on Learning Representations (ICLR)}, year={2025} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.