Skip to content

Commit 06ee04e

Browse files
authored
Merge pull request #12 from trishullab/usr/amit9oct/license-changes
Created pip instructions.
2 parents 328061c + ec22542 commit 06ee04e

File tree

3 files changed

+112
-9
lines changed

3 files changed

+112
-9
lines changed

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
# itp-interface
22
Generic interface for hooking up to any Interactive Theorem Prover (ITP) and collecting data for training ML models for AI in formal theorem proving.
33

4-
## Setup Steps:
4+
## Quick Setup for Lean 4:
5+
1. Install itp-interface using the following command:
6+
```bash
7+
pip install itp-interface
8+
```
9+
10+
2. Run the following command to prepare the REPL for Lean 4. (The default version is 4.7.0-rc2. You can change the version by setting the `LEAN_VERSION` environment variable. If no version is set, then 4.7.0-rc2 is used.)
11+
>NOTE: The Lean 4 version must match the version of the Lean 4 project you are working with.
12+
```bash
13+
export LEAN_VERSION="4.15.0"
14+
install-lean-repl
15+
```
16+
17+
3. Run the following command to build the REPL for Lean 4. Make sure that `lean --version` returns the correct version before running the command below. If not then check if `$HOME/.elan/bin` is in your path. Recommended to run `source $HOME/.elan/env` before running the command below.
18+
```bash
19+
install-itp-interface
20+
```
21+
22+
>NOTE: These steps are only tested on Linux. For Windows, you can use WSL. These steps will not setup the Coq interface.
23+
24+
# Full Setup for Coq and Lean:
525
1. Install OCaml first. Use the instructions here: https://opam.ocaml.org/doc/Install.html . The opam version used in this project is 2.1.3 (OCaml 4.14.0). Note that OCaml officially only supports Linux installations. One can use WSL on Windows machines.
626

727
2. Run the following to install Coq on Linux. The Coq version used in this project is <= 8.15.
@@ -17,25 +37,28 @@ export PATH="/home/$USER/.opam/default/bin:$PATH"
1737

1838
4. Create a `Miniconda` environment and activate it.
1939

40+
5. Run the commands for installing the Lean 4 interface as mentioned in [Quick Setup for Lean 4](#quick-setup-for-lean-4).
2041

21-
5. Change to the project root directory, and run the setup script i.e. `./src/scripts/setup.sh` from the root directory.
42+
6. Change to the project root directory, and run the setup script i.e. `./src/scripts/setup.sh` from the root directory.
2243

23-
6. Add the following to your `.bashrc` file for Lean:
44+
7. Add the following to your `.bashrc` file for Lean:
2445
```
2546
export PATH="/home/$USER/.elan/bin:$PATH"
2647
```
2748

28-
7. You need to run the following command to generate sample proof step data for Lean 4:
49+
## Generating Proof Step Data:
50+
51+
1.a. You need to run the following command to generate sample proof step data for Lean 4:
2952
```
3053
python src/itp_interface/main/run_tool.py --config-name simple_lean_data_gen
3154
```
3255
Check the `simple_lean_data_gen.yaml` configuration in the `src/itp_interface/configs` directory for more details. These config files are based on the `hydra` library (see [here](https://hydra.cc/docs/intro/)).
3356

34-
8. You need to run the following command to generate sample proof step data for Coq:
57+
1.b. You need to run the following command to generate sample proof step data for Coq:
3558
```
3659
python src/itp_interface/main/run_tool.py --config-name simple_coq_data_gen
3760
```
38-
Check the `simple_coq_data_gen.yaml` configuration in the `src/itp_interface/configs` directory for more details.
61+
Check the `simple_coq_data_gen.yaml` configuration in the `src/itp_interface/configs` directory for more details about where the generated data is stored and where the different ITP (Coq and Lean) projects are located in the file system.
3962

40-
## Important Notes:
63+
## Important Note:
4164
The ITP projects must be built before running proof step data generation. Make sure that the switch is set correctly while generating data for Coq projects because the Coq projects can be using different versions of Coq. Instructions for Coq project setup are listed in `src/itp_interface/main/config/repo/coq_repos.yaml` file.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ Homepage = "https://github.com/trishullab/itp-interface"
4545
Issues = "https://github.com/trishullab/itp-interface/issues"
4646

4747
[project.scripts]
48-
install-itp-interface = "itp_interface.main.install:install_itp_interface"
48+
install-itp-interface = "itp_interface.main.install:install_itp_interface"
49+
install-lean-repl = "itp_interface.main.install:install_lean_repl"

src/itp_interface/main/install.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,83 @@ def install_itp_interface():
1010
assert os.path.exists(os.path.join(repl_dir, "lean-toolchain")), f"lean-toolchain does not exist in {repl_dir}, build has failed"
1111
print("repl_dir: ", repl_dir)
1212
print("Building itp_interface")
13-
os.system(f"cd {repl_dir} && lake build repl")
13+
os.system(f"cd {repl_dir} && lake build repl")
14+
15+
def install_lean_repl():
16+
print("Updating Lean")
17+
itp_dir = os.path.dirname(os.path.dirname(file_path))
18+
tools_dir = os.path.join(itp_dir, "tools")
19+
repl_dir = os.path.join(tools_dir, "repl")
20+
assert os.path.exists(repl_dir), f"repl_dir: {repl_dir} does not exist"
21+
assert os.path.exists(os.path.join(repl_dir, "lean-toolchain")), f"lean-toolchain does not exist in {repl_dir}, build has failed"
22+
print("repl_dir: ", repl_dir)
23+
assert os.system("git --version") == 0, "git is not installed"
24+
print("[OK] git is installed")
25+
print("Checking if Lean version is set in environment variables as LEAN_VERSION")
26+
print("If not, defaulting to 4.7.0-rc2")
27+
lean_version = os.environ.get("LEAN_VERSION", "4.7.0-rc2")
28+
github_repo = "https://github.com/amit9oct/repl.git"
29+
if lean_version.strip() == "4.7.0-rc2":
30+
print("Lean version is set to 4.7.0-rc2, not cloning the REPL")
31+
else:
32+
# Clone the repl fresh
33+
print("Cloning the REPL fresh")
34+
os.system(f"rm -rf {repl_dir}")
35+
os.system(f"git clone {github_repo} {repl_dir}")
36+
# escape the version number
37+
lean_version_esc = lean_version.replace(".", "\.")
38+
print("Switching to the right REPL version", lean_version_esc)
39+
cmd_to_run = f"cd {repl_dir} && git log --grep \"v{lean_version_esc}\" --pretty=\"%h %s\""
40+
print("Running: ", cmd_to_run)
41+
output = os.popen(cmd_to_run).read()
42+
print("Output: ", output)
43+
if output == "":
44+
print(f"Could not find a commit with message containing {lean_version}")
45+
print("Probably this version does not exist in the git history of the REPL")
46+
lean_version = "4.7.0-rc2"
47+
print("Switching to v4.7.0-rc2 on commit 97182f0")
48+
os.system(f"cd {repl_dir} && git checkout 97182f0")
49+
else:
50+
# Split on first space
51+
for line in output.split("\n"):
52+
if line:
53+
commit, message = line.split(" ", 1)
54+
if lean_version in message:
55+
print(f"Switching to commit {commit}")
56+
os.system(f"cd {repl_dir} && git checkout {commit}")
57+
break
58+
# Make sure that .elan is installed
59+
print("Checking if .elan is installed")
60+
if os.path.exists(os.path.expanduser("~/.elan")):
61+
print("[OK] .elan is installed")
62+
else:
63+
print("Installing .elan")
64+
elan_url = "https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh"
65+
os.system(f"curl -sSL {elan_url} | sh")
66+
print("[OK] .elan installed")
67+
lean_repo = "leanprover-community/lean"
68+
# Create a temporary script to run
69+
shell_code = f"""
70+
source $HOME/.elan/env
71+
echo "Installing Lean 4 ({lean_repo}:{lean_version})..."
72+
elan toolchain install {lean_repo}:{lean_version}
73+
elan override set {lean_repo}:{lean_version}
74+
echo "Installed Lean 4 ({lean_repo}:{lean_version}) successfully!"
75+
export PATH=$PATH:$HOME/.elan/bin
76+
"""
77+
random_string = os.urandom(8).hex()
78+
with open(f"/tmp/{random_string}.sh", "w") as f:
79+
f.write(shell_code)
80+
os.system(f"chmod +x /tmp/{random_string}.sh")
81+
print("Running the script")
82+
os.system(f"bash /tmp/{random_string}.sh")
83+
print("Removing the script")
84+
os.system(f"rm /tmp/{random_string}.sh")
85+
assert os.system("lean --version") == 0, "Lean 4 is not installed aborting"
86+
print("[OK] Lean 4 installed successfully")
87+
print("NOTE: Please run `install-itp-interface` to finish the installation")
88+
89+
90+
91+
92+

0 commit comments

Comments
 (0)