-
Notifications
You must be signed in to change notification settings - Fork 58
add garbage collection option #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
What is this meant to do? This needs documentation! |
|
I just updated the readme. Setting |
|
The code modifications for I've tested these changes using statements from MiniF2F. Here are the test samples: {"cmd": "import Mathlib\nopen BigOperators Real Nat Topology Rat"}
-- tactic mode
{"cmd": theorem algebra_amgm_faxinrrp2msqrt2geq2mxm1div2x :\n ∀ x > 0, 2 - Real.sqrt 2 ≥ 2 - x - 1 / (2 * x) := by sorry", "env": 0}
-- command mode
{"cmd": "theorem algebra_amgm_faxinrrp2msqrt2geq2mxm1div2x :\n ∀ x > 0, 2 - Real.sqrt 2 ≥ 2 - x - 1 / (2 * x) := by", "env": 0}
-- gc for tactic mode
{"cmd": "theorem algebra_amgm_faxinrrp2msqrt2geq2mxm1div2x :\n ∀ x > 0, 2 - Real.sqrt 2 ≥ 2 - x - 1 / (2 * x) := by sorry", "env": 0, "gc": true}
-- gc for command mode
{"cmd": "theorem algebra_amgm_faxinrrp2msqrt2geq2mxm1div2x :\n ∀ x > 0, 2 - Real.sqrt 2 ≥ 2 - x - 1 / (2 * x) := by", "env": 0, "gc": true}And the test results:
|
|
we also want to avoid saving the proofSnapshots too |
|
The ADD: However, the command that creates the |
|
Just a question of aesthetics. I would prefer the option to be called Other than that, I think this is a useful feature 👍 |
You mean As for |
The whole point of garbage collecting a command is that you never interact with its state again. So you won't apply tactics on its proof state |
|
@augustepoiroux I think using
We'd better set |
|
Nice 👍 I agree with you about keeping backward compatibiliy. Regarding
The full sentence is
It is just a change of point of view. Instead of discarding commands, we record them. My naming was bad, but the idea was essentially to replace |
|
The proofSnapshots are stored in Lines 61 to 74 in 506a6f3
For verification, you can check the test cases in this PR: |
|
then there should be an option to discard proof states as well. For example if you are doing proof repair, then you don't every use the tactic thing |
@FrederickPu I've implemented similar command mode features for tactic mode and am currently testing how these features reduce memory usage. Also, note that setting btw, deleting goals could disrupt the
You can still interact with the state even after garbage collecting the command. This could address the issue you posted earlier. |
|
@kim-em I think this PR is ready. Setting Additionally, it can serve as a health check command. For example: Thanks for your time and effort for reviewing these changes. |
| {"sorries": | ||
| [{"proofState": 0, | ||
| "pos": {"line": 1, "column": 93}, | ||
| "goal": "⊢ (2000 + 2001 + 2002 + 2003 + 2004 + 2005 + 2006) % 7 = 0", | ||
| "endPos": {"line": 1, "column": 98}}], | ||
| "messages": | ||
| [{"severity": "warning", | ||
| "pos": {"line": 1, "column": 8}, | ||
| "endPos": {"line": 1, "column": 30}, | ||
| "data": "declaration uses 'sorry'"}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand here: if we're generating proofState: 0 here, and it is actually usable, then the environment has been transitively captured, and the record: false wasn't really respected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rex said that you can garbage collect the command that created the proof snapshot without garbage collecting the proof snapshot itself. I'm not sure what the use case for this would be tho. Also I think having each proof snapshot connected to a command would make it easier to garbage collect all the snapshots after you are done with tactic mode for a particular problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the green(garbage collected) and yellow lines in the diagram above. Here are the relevant commands:
# By default, this consumes about 83 MB
[{'cmd': 'import Mathlib'},
{'cmd': 'theorem womp0 (a0 b c : Nat) : (a0 + b) + c = c + a0 + b := by sorry', 'env': 0},
{'cmd': 'theorem womp1 (a1 b c : Nat) : (a1 + b) + c = c + a1 + b := by sorry', 'env': 0},
# ...
]
# With record=False, this consumes about 21 MB
[{'cmd': 'import Mathlib'},
{'cmd': 'theorem womp0 (a0 b c : Nat) : (a0 + b) + c = c + a0 + b := by sorry', 'env': 0, 'record': False},
{'cmd': 'theorem womp1 (a1 b c : Nat) : (a1 + b) + c = c + a1 + b := by sorry', 'env': 0, 'record': False},
# ...
]The ProofSnapshot is independent of the cmdSnapshot once created. The structure provides sufficient information for interactions and pickles.
structure ProofSnapshot where
coreState : Core.State
coreContext : Core.Context
metaState : Meta.State
metaContext : Meta.Context
termState : Term.State
termContext : Term.Context
tacticState : Tactic.State
tacticContext : Tactic.Context
rootGoals : List MVarIdThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the
record: false wasn't really respected
We can view it this way: in Cmd mode, record is intended for cmdSnapshot-gc, while in Tactic mode, it's for proofSnapshot.
And it can be used as default config for tactic-based interactions, as the generated cmdSnapshots are rarely used since they contain sorry.
If someone wishes to obtain the state while discarding both the cmdSnapshot and proofSnapshot, they can use the File mode like:
{"cmd": "example : 1 = 1 := by", "env": 0, "record": false}And then extract the states from errors.
btw, this feature is beneficial for File-mode-based interactions like itp-interfaces, where most generated cmdStates are wasted due to incomplete errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh so command snapshots are only necessary to create additional command states. Which rarely happens for a single proof. Like usually u would only want to snapshot import headers and stuff
desaxce
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, that's a nice feature, I don't see anything preventing the merge apart from refreshing the branch and tests.
test/record_cmd2.expected.out
Outdated
| "pos": {"line": 3, "column": 0}, | ||
| "endPos": {"line": 3, "column": 6}, | ||
| "data": "Try this: exact h2 (h1 p)"}, | ||
| {"severity": "info", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update your fork and update your branch to be on 4.22.0-rc3?
Then you can remove the "Goals accomplished!" below, it's not returned anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review. I have merged the latest code and updated the test script.
=== Test Summary ===
Failed tests:
✗ record_cmd2
Total: 1 failed
==================|
@kim-em Do you think we could merge this development? |
|
Can someone make a summary of what |
|
In the following example The The only state that is transitively saved in the proofSnapshot is the |
|
I think it would be nice to have a way of discarding proofsnapshots once they are no longer being used. Ie you've finished with your proof search for a particular problem. |

Add a
recordoption to optimize memory usage. The reference-counting issue is fixed by @ohyeat as discussed here.