lean-interact 0.8.0__tar.gz → 0.8.2__tar.gz

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.
Files changed (47) hide show
  1. {lean_interact-0.8.0 → lean_interact-0.8.2}/PKG-INFO +2 -2
  2. {lean_interact-0.8.0 → lean_interact-0.8.2}/README.md +1 -1
  3. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/contributing.md +6 -4
  4. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/index.md +2 -2
  5. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/basic-usage.md +2 -5
  6. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/custom-lean-configuration.md +24 -32
  7. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/examples.md +7 -4
  8. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/getting-started.md +4 -13
  9. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/installation.md +6 -3
  10. lean_interact-0.8.2/docs/user-guide/multi-processing.md +164 -0
  11. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/tactic-mode.md +2 -2
  12. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/user-guide/troubleshooting.md +1 -1
  13. lean_interact-0.8.2/examples/multi_processing.py +60 -0
  14. {lean_interact-0.8.0 → lean_interact-0.8.2}/mkdocs.yml +1 -0
  15. {lean_interact-0.8.0 → lean_interact-0.8.2}/pyproject.toml +1 -1
  16. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/utils.py +1 -1
  17. {lean_interact-0.8.0 → lean_interact-0.8.2}/tests/test_server.py +1 -1
  18. {lean_interact-0.8.0 → lean_interact-0.8.2}/uv.lock +1 -1
  19. {lean_interact-0.8.0 → lean_interact-0.8.2}/.devcontainer/devcontainer.json +0 -0
  20. {lean_interact-0.8.0 → lean_interact-0.8.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  21. {lean_interact-0.8.0 → lean_interact-0.8.2}/.github/copilot-instructions.md +0 -0
  22. {lean_interact-0.8.0 → lean_interact-0.8.2}/.github/workflows/ci.yml +0 -0
  23. {lean_interact-0.8.0 → lean_interact-0.8.2}/.github/workflows/docs.yml +0 -0
  24. {lean_interact-0.8.0 → lean_interact-0.8.2}/.github/workflows/publish-to-pypi.yml +0 -0
  25. {lean_interact-0.8.0 → lean_interact-0.8.2}/.gitignore +0 -0
  26. {lean_interact-0.8.0 → lean_interact-0.8.2}/LICENSE +0 -0
  27. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/.nojekyll +0 -0
  28. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/api/config.md +0 -0
  29. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/api/interface.md +0 -0
  30. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/api/project.md +0 -0
  31. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/api/server.md +0 -0
  32. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/api/sessioncache.md +0 -0
  33. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/api/utils.md +0 -0
  34. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/generate_changelog.py +0 -0
  35. {lean_interact-0.8.0 → lean_interact-0.8.2}/docs/theme/main.html +0 -0
  36. {lean_interact-0.8.0 → lean_interact-0.8.2}/examples/beq_plus.py +0 -0
  37. {lean_interact-0.8.0 → lean_interact-0.8.2}/examples/proof_generation_and_autoformalization.py +0 -0
  38. {lean_interact-0.8.0 → lean_interact-0.8.2}/examples/type_check.py +0 -0
  39. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/__init__.py +0 -0
  40. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/config.py +0 -0
  41. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/interface.py +0 -0
  42. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/project.py +0 -0
  43. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/server.py +0 -0
  44. {lean_interact-0.8.0 → lean_interact-0.8.2}/src/lean_interact/sessioncache.py +0 -0
  45. {lean_interact-0.8.0 → lean_interact-0.8.2}/tests/test_concurrency.py +0 -0
  46. {lean_interact-0.8.0 → lean_interact-0.8.2}/tests/test_git_functionality.py +0 -0
  47. {lean_interact-0.8.0 → lean_interact-0.8.2}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lean-interact
3
- Version: 0.8.0
3
+ Version: 0.8.2
4
4
  Summary: LeanInteract is a Python package that allows you to interact with the Lean theorem prover.
5
5
  Author-email: Auguste Poiroux <auguste.poiroux@epfl.ch>
6
6
  License: MIT License
@@ -53,7 +53,7 @@ Check the [documentation](https://augustepoiroux.github.io/LeanInteract/) for de
53
53
  - **🔗 Interactivity**: Execute Lean code and files directly from Python.
54
54
  - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
55
55
  - **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems.
56
- - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-rc4`.
56
+ - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.23.0-rc2`.
57
57
  - We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
58
58
  - **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
59
59
  - Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4).
@@ -15,7 +15,7 @@ Check the [documentation](https://augustepoiroux.github.io/LeanInteract/) for de
15
15
  - **🔗 Interactivity**: Execute Lean code and files directly from Python.
16
16
  - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
17
17
  - **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems.
18
- - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-rc4`.
18
+ - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.23.0-rc2`.
19
19
  - We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
20
20
  - **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
21
21
  - Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4).
@@ -61,10 +61,12 @@ uv run mkdocs serve
61
61
 
62
62
  ## Reporting Issues & Getting Help
63
63
 
64
- - **Bugs/Feature requests:**
65
- 1. Check [GitHub issues](https://github.com/augustepoiroux/LeanInteract/issues) first (open or closed).
66
- 2. If new, open an issue with a clear description and steps to reproduce.
67
- - **Contact:** For questions, contact the [maintainer](mailto:auguste.poiroux@epfl.ch).
64
+ **Bugs/Feature requests:**
65
+
66
+ 1. Check [GitHub issues](https://github.com/augustepoiroux/LeanInteract/issues) first (open or closed).
67
+ 2. If new, open an issue with a clear description and steps to reproduce.
68
+
69
+ **Contact:** For questions, contact the [maintainer](mailto:auguste.poiroux@epfl.ch).
68
70
 
69
71
  ---
70
72
 
@@ -17,7 +17,7 @@ hide:
17
17
  - **🔗 Interactivity**: Execute Lean code and files directly from Python
18
18
  - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction
19
19
  - **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems
20
- - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-rc4`
20
+ - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.23.0-rc2`
21
21
  - We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
22
22
  - **📦 Temporary Projects**: Easily instantiate temporary Lean environments
23
23
  - Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4)
@@ -30,7 +30,7 @@ hide:
30
30
  pip install lean-interact
31
31
  ```
32
32
 
33
- Install Lean 4 (if not already installed):
33
+ Install Lean 4 (if not already installed) using the following command coming with LeanInteract:
34
34
 
35
35
  ```bash
36
36
  install-lean
@@ -24,7 +24,7 @@ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id"))
24
24
  The response contains:
25
25
 
26
26
  - An environment state (`env`) that can be used for subsequent commands
27
- - Messages returned by Lean (errors, information, etc.)
27
+ - Messages returned by Lean if any (errors, information, etc.)
28
28
 
29
29
  ### Working with Environment States
30
30
 
@@ -59,6 +59,7 @@ Both `Command` and `FileCommand` support several options:
59
59
  - `all_tactics`: Get information about tactics used
60
60
  - `root_goals`: Get information about goals in theorems and definitions
61
61
  - `infotree`: Get Lean infotree containing various informations about declarations and tactics
62
+ - `env`: The environment from a previous command to be used as context. If `env = None`, starts from scratch.
62
63
 
63
64
  Example with options:
64
65
 
@@ -87,8 +88,6 @@ This response will include a list of `Sorry` objects, each containing:
87
88
 
88
89
  ## Error Handling
89
90
 
90
- It's good practice to handle errors that might occur during execution:
91
-
92
91
  ```python tags=["execute"]
93
92
  from lean_interact.interface import LeanError
94
93
 
@@ -104,8 +103,6 @@ except Exception as e:
104
103
 
105
104
  ## Next Steps
106
105
 
107
- Now that you understand basic operations, you can:
108
-
109
106
  - Learn about [tactic mode](tactic-mode.md) for step-by-step proof interaction
110
107
  - Configure [custom Lean environments](custom-lean-configuration.md)
111
108
  - Explore the [API Reference](../api/interface.md) for more command options
@@ -14,11 +14,11 @@ config = LeanREPLConfig(lean_version="v4.7.0")
14
14
  server = LeanServer(config)
15
15
  ```
16
16
 
17
+ ## Working with Existing Projects
18
+
17
19
  !!! note
18
20
  When using a project through the `project` attribute, the Lean version is automatically inferred from the project. You cannot specify both `lean_version` and `project` parameters.
19
21
 
20
- ## Working with Existing Projects
21
-
22
22
  ### Local Lean Projects
23
23
 
24
24
  To work with a local Lean project, create a `LocalProject` instance:
@@ -53,7 +53,7 @@ project = GitProject(
53
53
  url="https://github.com/yangky11/lean4-example",
54
54
  rev="main", # Optional: specific branch, tag, or commit
55
55
  directory="/custom/cache/path", # Optional: custom directory where the project will be cloned
56
- force_pull=False # Optional: force update from remote. Useful in case you already have the project cloned.
56
+ force_pull=False # Optional: force update from remote. Useful in case you already have the project cloned and the branch has been updated.
57
57
  )
58
58
  config = LeanREPLConfig(project=project)
59
59
  server = LeanServer(config)
@@ -61,34 +61,16 @@ server = LeanServer(config)
61
61
 
62
62
  The `GitProject` will automatically:
63
63
 
64
- - Clone the repository if it doesn't exist
64
+ - Clone the repository if it doesn't exist (including submodules if present)
65
65
  - Update to the specified revision
66
- - Build the project using Lake
67
- - Handle submodules if present
68
-
69
- ### Using a Local REPL Installation
70
-
71
- If you're developing the Lean REPL or have a custom version, you can use your local copy instead of downloading from the Git repository:
72
-
73
- ```python
74
- from lean_interact import LeanREPLConfig, LeanServer
75
-
76
- config = LeanREPLConfig(local_repl_path="path/to/your/local/repl", build_repl=True)
77
- server = LeanServer(config)
78
- ```
79
-
80
- !!! note
81
- When using `local_repl_path`, any specified `repl_rev`, and `repl_git` parameters are ignored as the local REPL is used directly.
82
-
83
- !!! note
84
- You are responsible for using a compatible Lean version between your local REPL and the project you will interact with.
66
+ - Build the project with `lake build`
85
67
 
86
68
  !!! tip
87
- Setting `build_repl=False` will skip building the local REPL, which can be useful if you've already built it and want to avoid rebuilding.
69
+ Use the `directory` parameter to control where projects are cached
88
70
 
89
71
  ## Working with Temporary Projects
90
72
 
91
- LeanInteract allows you to create temporary projects with dependencies for experimentation without affecting your local environment.
73
+ LeanInteract allows you to create temporary projects with dependencies for quick experimentation and automated reproducible setups.
92
74
 
93
75
  ### Simple Temporary Projects with Dependencies
94
76
 
@@ -151,7 +133,7 @@ Alternatively, you can define the lakefile content using the TOML format by sett
151
133
 
152
134
  ## Using Custom REPL Revisions
153
135
 
154
- LeanInteract uses a Lean REPL (Read-Eval-Print Loop) from a Git repository to interact with Lean. By default, it uses a specific version (`v1.0.9`) of the REPL from the default repository (`https://github.com/augustepoiroux/repl`). However, you can customize this by specifying a different REPL revision or repository:
136
+ LeanInteract uses the Lean REPL from a git repository to interact with Lean. By default, it uses a specific version of the REPL from the default forked repository (`https://github.com/augustepoiroux/repl`) which manages compatibility with Lean versions. However, you can customize this by specifying a different REPL revision or repository:
155
137
 
156
138
  ```python
157
139
  from lean_interact import LeanREPLConfig, LeanServer
@@ -172,19 +154,29 @@ When you specify a `repl_rev`, LeanInteract will try to:
172
154
 
173
155
  This approach allows for better matching between REPL versions and Lean versions, ensuring compatibility.
174
156
 
175
- - Always check `config.is_setup()` before creating servers
176
157
  !!! warning
177
- Custom/older REPL implementations may have interfaces that are incompatible with LeanInteract's standard commands. If you encounter issues, consider using the `run_dict` method from `LeanServer` to communicate directly with the REPL:
158
+ Custom/older REPL implementations may have interfaces that are incompatible with LeanInteract's current commands. If you encounter issues, consider using the `run_dict` method from `LeanServer` to communicate directly with the REPL:
178
159
 
179
160
  ```python
180
- # Using run_dict instead of the standard commands
181
161
  result = server.run_dict({"cmd": "your_command_here"})
182
162
  ```
183
163
 
184
164
  !!! note
185
165
  The `repl_rev` and `repl_git` parameters are ignored if you specify `local_repl_path`.
186
166
 
187
- ## Best Practices
167
+ ### Using a Local REPL Installation
168
+
169
+ If you are developing the Lean REPL or have a custom version, you can use your local copy instead of downloading from a git repository:
170
+
171
+ ```python
172
+ from lean_interact import LeanREPLConfig, LeanServer
173
+
174
+ config = LeanREPLConfig(local_repl_path="path/to/your/local/repl", build_repl=True)
175
+ server = LeanServer(config)
176
+ ```
177
+
178
+ !!! note
179
+ When using `local_repl_path`, any specified `repl_rev`, and `repl_git` parameters are ignored as the local REPL is used directly.
188
180
 
189
- - **Custom Directories**: Use the `directory` parameter to control where projects are cached
190
- - **Build Control**: Use `auto_build=False` to skip building if you've already built a project
181
+ !!! note
182
+ Make sure you are using a compatible Lean version between your local REPL and the project you will interact with.
@@ -4,7 +4,7 @@ execute: true
4
4
 
5
5
  # Examples
6
6
 
7
- This page provides practical examples of using LeanInteract in different scenarios. You can find the full examples in the [`examples`](https://github.com/augustepoiroux/LeanInteract/tree/main/examples) directory of the repository.
7
+ This page provides practical examples of using LeanInteract in different scenarios. You can find a few full example scripts in the [`examples`](https://github.com/augustepoiroux/LeanInteract/tree/main/examples) directory of the repository.
8
8
 
9
9
  ## Basic Theorem Proving
10
10
 
@@ -77,11 +77,14 @@ print(result) # Example raw output from the REPL
77
77
 
78
78
  For more comprehensive examples, check out the following scripts in the examples directory:
79
79
 
80
- 1. [**proof_generation_and_autoformalization.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/proof_generation_and_autoformalization.py)
80
+ 1. [**multi_processing.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/multi_processing.py)
81
+ Shows how to use multiprocessing with LeanInteract for parallel proof checking.
82
+
83
+ 2. [**proof_generation_and_autoformalization.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/proof_generation_and_autoformalization.py)
81
84
  Shows how to use models like DeepSeek-Prover-V1.5 and Goedel-Prover on MiniF2F and ProofNet# benchmarks.
82
85
 
83
- 2. [**beq_plus.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/beq_plus.py)
86
+ 3. [**beq_plus.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/beq_plus.py)
84
87
  Demonstrates how to run the autoformalization BEq+ metric on the ProofNetVerif benchmark.
85
88
 
86
- 3. [**type_check.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/type_check.py)
89
+ 4. [**type_check.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/type_check.py)
87
90
  Shows how to optimize type checking using environment states.
@@ -4,8 +4,6 @@ execute: true
4
4
 
5
5
  # Getting Started with LeanInteract
6
6
 
7
- This guide will help you take your first steps with LeanInteract and understand its core concepts.
8
-
9
7
  ## Overview
10
8
 
11
9
  LeanInteract provides a Python interface to the Lean 4 theorem prover via the Lean REPL (Read-Evaluate-Print Loop). It enables you to:
@@ -13,12 +11,9 @@ LeanInteract provides a Python interface to the Lean 4 theorem prover via the Le
13
11
  - Execute Lean code from Python
14
12
  - Process Lean files
15
13
  - Interact with proofs step by step
16
- - Save and restore proof states
17
14
 
18
15
  ## Quick Example
19
16
 
20
- Here's a minimal example to help you get started:
21
-
22
17
  ```python tags=["execute"]
23
18
  from lean_interact import LeanREPLConfig, LeanServer, Command
24
19
 
@@ -37,14 +32,12 @@ print(response)
37
32
 
38
33
  This will:
39
34
 
40
- 1. Initialize a Lean REPL configuration
35
+ 1. Initialize a Lean REPL configuration: downloads and initializes the Lean environment
41
36
  2. Start a Lean server
42
37
  3. Execute a simple Lean theorem
43
38
  4. Return a response containing the Lean environment state and any messages
44
39
 
45
- ## Understanding Core Components
46
-
47
- Let's break down the key components:
40
+ ## Core Components
48
41
 
49
42
  ### LeanREPLConfig
50
43
 
@@ -52,7 +45,7 @@ Let's break down the key components:
52
45
 
53
46
  ```python
54
47
  config = LeanREPLConfig(
55
- lean_version="v4.19.0", # Specify Lean version (optional)
48
+ lean_version="v4.19.0", # Specify Lean version (optional, default is latest)
56
49
  verbose=True, # Print detailed logs
57
50
  )
58
51
  ```
@@ -83,13 +76,11 @@ LeanInteract provides several types of commands:
83
76
  Basic command execution:
84
77
 
85
78
  ```python
86
- response = server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id"))
79
+ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id"))
87
80
  ```
88
81
 
89
82
  ## Next Steps
90
83
 
91
- Now that you understand the basics, you can:
92
-
93
84
  - Learn about [basic usage patterns](basic-usage.md)
94
85
  - Explore [tactic mode](tactic-mode.md) for step-by-step proof interaction
95
86
  - Configure [custom Lean environments](custom-lean-configuration.md)
@@ -26,13 +26,16 @@ pip install lean-interact
26
26
 
27
27
  ### 2. Install Lean 4 (if not already installed)
28
28
 
29
- LeanInteract provides a convenient command to install Lean 4 via the Elan version manager:
29
+ LeanInteract provides a convenient command to install Lean 4 along with its official [Elan](https://github.com/leanprover/elan) version manager:
30
30
 
31
31
  ```
32
32
  install-lean
33
33
  ```
34
34
 
35
- This command will install Elan, which manages Lean versions. Your Elan version should be at least 4.0.0.
35
+ This command will install Elan, which manages Lean versions.
36
+
37
+ !!! warning "Elan Version"
38
+ Your Elan version should be at least 4.0.0.
36
39
 
37
40
  ## Verifying Installation
38
41
 
@@ -55,7 +58,7 @@ print(response)
55
58
  If everything is set up correctly, the script should output a successful response.
56
59
 
57
60
  !!! note
58
- The first time you run LeanInteract, it might take some time as it downloads and builds Lean REPL. Subsequent runs will be significantly faster due to caching.
61
+ The first time you run LeanInteract, it might take some time as it downloads the requested Lean version and builds Lean REPL. Subsequent runs will be significantly faster due to caching.
59
62
 
60
63
  ## System-Specific Notes
61
64
 
@@ -0,0 +1,164 @@
1
+ ---
2
+ execute: false
3
+ ---
4
+
5
+ # Multi-processing Guide
6
+
7
+ LeanInteract is designed with multi-processing in mind, allowing you to leverage multiple CPU cores for parallel theorem proving and verification tasks. This guide covers the best practices, patterns, and potential pitfalls when using LeanInteract in multi-process environments.
8
+
9
+ We recommend using `AutoLeanServer`.
10
+ It is specifically designed for multi-process environments with
11
+ automated restart on fatal Lean errors, timeouts, and when memory limits are reached.
12
+ On automated restarts, only commands run with `add_to_session_cache=True` (attribute of the `AutoLeanServer.run` method) will be preserved.
13
+
14
+ `AutoLeanServer` is still experimental, any feedback or issues encountered while using it are welcome.
15
+
16
+ ## Best Practices Summary
17
+
18
+ 1. **Always pre-instantiate** `LeanREPLConfig` before multiprocessing
19
+ 2. **One lean server per process**
20
+ 3. **Use `AutoLeanServer`**
21
+ 4. **Configure memory limits** to prevent system overload
22
+ 5. **Set appropriate timeouts** for long-running operations
23
+ 6. **Use session caching** to keep context between requests
24
+ 7. **Consider using `maxtasksperchild`** to limit memory accumulation
25
+
26
+ ## Quick Start
27
+
28
+ Here is a minimal example of using LeanInteract with multiple processes:
29
+
30
+ ```python
31
+ import multiprocessing as mp
32
+ from lean_interact import LeanREPLConfig, AutoLeanServer, Command
33
+
34
+ def worker(config: LeanREPLConfig, task_id):
35
+ """Worker function that runs in each process"""
36
+ server = AutoLeanServer(config)
37
+ result = server.run(Command(cmd=f"#eval {task_id} * {task_id}"))
38
+ return f"Task {task_id}: {result.messages[0].data if hasattr(result, 'messages') else 'Error'}"
39
+
40
+ if __name__ == "__main__":
41
+ # Pre-instantiate config before multiprocessing
42
+ # LeanREPLConfig downloads and initializes resources
43
+ config = LeanREPLConfig(verbose=True)
44
+
45
+ # Create processes
46
+ ctx = mp.get_context("spawn")
47
+ with ctx.Pool(processes=4) as pool:
48
+ tasks = range(5)
49
+ results = pool.starmap(worker, [(config, task_id) for task_id in tasks])
50
+
51
+ for result in results:
52
+ print(result)
53
+ ```
54
+
55
+ For more examples, check the [examples directory](https://github.com/augustepoiroux/LeanInteract/tree/main/examples).
56
+
57
+ ## Core Principles
58
+
59
+ ### 1. Pre-instantiate Configuration
60
+
61
+ Always create your `LeanREPLConfig` instance **before** starting multiprocessing:
62
+
63
+ ```python
64
+ from lean_interact import LeanREPLConfig, AutoLeanServer
65
+ import multiprocessing as mp
66
+
67
+ # ✅ CORRECT: Config created in main process
68
+ def correct_approach():
69
+ config = LeanREPLConfig() # Pre-setup in main process
70
+
71
+ def worker(cfg):
72
+ server = AutoLeanServer(cfg) # Use pre-configured config
73
+ # ... your work here
74
+ pass
75
+
76
+ ctx = mp.get_context("spawn")
77
+ with ctx.Pool() as pool:
78
+ pool.map(worker, [config] * 4)
79
+
80
+ # ❌ INCORRECT: Config created in each process
81
+ def incorrect_approach():
82
+ def worker():
83
+ config = LeanREPLConfig()
84
+ server = AutoLeanServer(config)
85
+ # ... your work here
86
+ pass
87
+
88
+ ctx = mp.get_context("spawn")
89
+ with ctx.Pool() as pool:
90
+ pool.map(worker, range(4))
91
+ ```
92
+
93
+ ### 2. One Server Per Process
94
+
95
+ Each process should have its own `LeanServer` or `AutoLeanServer` instance.
96
+
97
+ ```python
98
+ def worker(config, task_data):
99
+ # Each process gets its own server
100
+ server = AutoLeanServer(config)
101
+
102
+ # Process your tasks
103
+ for task in task_data:
104
+ result = server.run(task)
105
+ # Handle result
106
+
107
+ return results
108
+ ```
109
+
110
+ ## Thread Safety
111
+
112
+ ### Within a Single Process
113
+
114
+ `LeanServer` and `AutoLeanServer` are thread-safe within a single process thanks to internal locking mechanisms.
115
+ All concurrent requests will be processed sequentially.
116
+
117
+ ### Across Processes
118
+
119
+ Servers are **NOT** safe to share across processes. Each process must have its own server instance:
120
+
121
+ ```python
122
+ import multiprocessing as mp
123
+ from lean_interact import AutoLeanServer, LeanREPLConfig
124
+
125
+ # ✅ CORRECT: Each process creates its own server
126
+ def correct_multiprocess_worker(config: LeanREPLConfig, worker_id: int):
127
+ server = AutoLeanServer(config) # New server per process
128
+ # ... work with server
129
+
130
+ # ❌ INCORRECT: Don't share servers across processes
131
+ def incorrect_multiprocess_pattern():
132
+ config = LeanREPLConfig()
133
+ server = AutoLeanServer(config)
134
+
135
+ def worker(worker_id):
136
+ # This will cause issues - server can't be pickled/shared
137
+ result = server.run(Command(cmd="..."))
138
+
139
+ with mp.Pool() as pool:
140
+ pool.map(worker, range(4)) # Will fail!
141
+ ```
142
+
143
+ ## Memory Management
144
+
145
+ ```python
146
+ from lean_interact import AutoLeanServer, LeanREPLConfig
147
+
148
+ # Configure memory limits for multi-process safety
149
+ config = LeanREPLConfig(memory_hard_limit_mb=8192) # 8GB per server, works on Linux only
150
+
151
+ server = AutoLeanServer(
152
+ config,
153
+ max_total_memory=0.8, # Restart when system uses >80% memory
154
+ max_process_memory=0.8, # Restart when process uses >80% of limit
155
+ max_restart_attempts=5 # Allow up to 5 restart attempts per command
156
+ )
157
+ ```
158
+
159
+ ### Memory Configuration Options
160
+
161
+ - `max_total_memory`: System-wide memory threshold (0.0-1.0)
162
+ - `max_process_memory`: Per-process memory threshold (0.0-1.0)
163
+ - `memory_hard_limit_mb`: Hard memory limit in MB (Linux only)
164
+ - `max_restart_attempts`: Maximum consecutive restart attempts
@@ -7,7 +7,7 @@ execute: true
7
7
  Tactic mode in LeanInteract allows you to work with Lean's proof tactics step-by-step, providing an interactive way to develop and explore proofs.
8
8
 
9
9
  !!! warning "Experimental Feature"
10
- The tactic mode feature is experimental in Lean REPL and may not work as expected in all situations. Some valid proofs might be incorrectly rejected. Please report any issues you encounter on the [Lean REPL GitHub repository](https://github.com/leanprover-community/repl/issues).
10
+ The tactic mode feature is experimental may not work as expected in all situations. Some valid proofs might be incorrectly rejected.
11
11
 
12
12
  ## Getting Started with Tactics
13
13
 
@@ -28,7 +28,7 @@ config = LeanREPLConfig()
28
28
  server = LeanServer(config)
29
29
 
30
30
  # Define a theorem with sorry
31
- response = server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := sorry"))
31
+ response = server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := by sorry"))
32
32
  print(response.sorries[0])
33
33
  ```
34
34
 
@@ -19,7 +19,7 @@ This guide covers common issues you might encounter when using LeanInteract.
19
19
 
20
20
  ```python
21
21
  from lean_interact import AutoLeanServer, LeanREPLConfig
22
- server = AutoLeanServer(LeanREPLConfig(memory_hard_limit_mb=1000)) # Limit to 1GB
22
+ server = AutoLeanServer(LeanREPLConfig(memory_hard_limit_mb=8192)) # Limit to 8GB
23
23
  ```
24
24
 
25
25
  - If you are working with large files or complex proofs in a single session, consider breaking them into smaller, more manageable pieces.
@@ -0,0 +1,60 @@
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = ["lean-interact"]
4
+ # ///
5
+ """
6
+ Example demonstrating multi-processing with LeanInteract.
7
+
8
+ This example shows the correct pattern for using LeanInteract with multiple processes:
9
+ 1. Pre-instantiate the config before starting multiprocessing
10
+ 2. Use spawn context for cross-platform compatibility
11
+ 3. Each process gets its own server instance
12
+
13
+ Run this example with: python examples/multiprocessing_example.py
14
+ """
15
+
16
+ import multiprocessing as mp
17
+
18
+ from lean_interact import AutoLeanServer, LeanREPLConfig
19
+ from lean_interact.interface import Command, LeanError
20
+
21
+
22
+ def worker(config: LeanREPLConfig, task_id: int) -> str:
23
+ """Worker function that runs in each process"""
24
+ try:
25
+ # Each process gets its own server instance
26
+ server = AutoLeanServer(config)
27
+ result = server.run(Command(cmd=f"#eval {task_id} * {task_id}"))
28
+ if isinstance(result, LeanError):
29
+ return f"Task {task_id}: LeanError - {result}"
30
+ return f"Task {task_id}: {task_id}² = {result.messages[0].data}"
31
+ except Exception as e:
32
+ return f"Task {task_id}: Exception - {e}"
33
+
34
+
35
+ def main():
36
+ """Main function demonstrating correct multiprocessing setup"""
37
+ print("LeanInteract Multi-processing Example")
38
+ print("=" * 40)
39
+
40
+ # CRITICAL: Pre-instantiate config before multiprocessing as it downloads and initializes resources
41
+ print("Setting up LeanREPLConfig (may take a few minutes the first time)...")
42
+ config = LeanREPLConfig(verbose=True)
43
+ print("Config setup complete.")
44
+
45
+ # Dummy tasks
46
+ tasks = range(1, 6)
47
+ print(f"\nProcessing {len(tasks)} tasks in parallel...")
48
+
49
+ ctx = mp.get_context("spawn")
50
+ with ctx.Pool(processes=min(4, len(tasks))) as pool:
51
+ results = pool.starmap(worker, [(config, task_id) for task_id in tasks])
52
+
53
+ print("\nResults:")
54
+ print("-" * 40)
55
+ for result in results:
56
+ print(result)
57
+
58
+
59
+ if __name__ == "__main__":
60
+ main()
@@ -143,6 +143,7 @@ nav:
143
143
  - Getting Started: user-guide/getting-started.md
144
144
  - Basic Usage: user-guide/basic-usage.md
145
145
  - Tactic Mode: user-guide/tactic-mode.md
146
+ - Multi-processing: user-guide/multi-processing.md
146
147
  - Examples: user-guide/examples.md
147
148
  - Custom Lean Configuration: user-guide/custom-lean-configuration.md
148
149
  - Troubleshooting: user-guide/troubleshooting.md
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lean-interact"
3
- version = "0.8.0"
3
+ version = "0.8.2"
4
4
  description = "LeanInteract is a Python package that allows you to interact with the Lean theorem prover."
5
5
  keywords = ["Lean", "theorem proving", "autoformalization", "REPL"]
6
6
  license = { file = "LICENSE" }
@@ -22,7 +22,7 @@ logger.addHandler(handler)
22
22
  ROOT_DIR = Path(__file__).resolve().parent
23
23
  DEFAULT_CACHE_DIR = ROOT_DIR / "cache"
24
24
  DEFAULT_REPL_GIT_URL = "https://github.com/augustepoiroux/repl"
25
- DEFAULT_REPL_VERSION = "v1.0.13"
25
+ DEFAULT_REPL_VERSION = "v1.0.15"
26
26
 
27
27
  os.makedirs(DEFAULT_CACHE_DIR, exist_ok=True)
28
28
 
@@ -508,7 +508,7 @@ lean_exe "dummy" where
508
508
  with self.assertRaises(TimeoutError):
509
509
  server.run(
510
510
  Command(
511
- cmd="theorem amc12a_2003_p1 (u v : ℕ) (h₀ : n, u n = 2 * n + 2) (h₁ : n, v n = 2 * n + 1) :\n ((∑ k in Finset.range 2003, u k) - ∑ k in Finset.range 2003, v k) = 2003 := by simp only [h₀, h₁, Finset.sum_range_succ, Finset.sum_range_zero]; rfl",
511
+ cmd="def fib : NatNat\n | 0 => 0\n | 1 => 1\n | n + 2 => fib (n + 1) + fib n\n\n#eval fib 40",
512
512
  env=root_env,
513
513
  ),
514
514
  timeout=2,
@@ -561,7 +561,7 @@ wheels = [
561
561
 
562
562
  [[package]]
563
563
  name = "lean-interact"
564
- version = "0.8.0"
564
+ version = "0.8.2"
565
565
  source = { editable = "." }
566
566
  dependencies = [
567
567
  { name = "filelock" },
File without changes
File without changes