Zulip Chat Archive
Stream: lean4
Topic: Execute monad with timeout
Leni Aniva (Sep 10 2024 at 06:51):
Is there a simple way to run a monad based on CoreM
with a timeout?
e.g.
def runWithTimeout (t: Nat) (m: CoreM a): CoreM (Except Timeout a) := ...
where runWithTimeout t m
would return .ok a
if the monad finished in time, and otherwise .error
with some timeout object.
I know there's a field for max heartbeats, but can I just use withCoreContext { maxHeartbeats := ... }
to achieve this effect?
Mario Carneiro (Sep 10 2024 at 07:59):
no, this is a long standing open issue
Mario Carneiro (Sep 10 2024 at 07:59):
Sebastian Ullrich (Sep 10 2024 at 09:33):
Leni Aniva said:
I know there's a field for max heartbeats, but can I just use
withCoreContext { maxHeartbeats := ... }
to achieve this effect?
Yes, that should work as it is effectively what the Lean elaborator does. Someone in the called code just has to call Core.checkSystem
sufficiently often, which all the fundamental meta functions do
Eric Wieser (Sep 10 2024 at 11:00):
Could we have a MonadCheckSystem
typeclass to make it possible to generalize this? Is there a version of checkSystem
for CommandElabM
?
import Lean
run_cmd do
Lean.Core.checkSystem "foo" -- fails, wrong type
Eric Wieser (Sep 10 2024 at 11:03):
(the actual application I have in mind is being able to create a no-op implementation of MonadCheckSystem Id
, so that you can write a function and prove things about it for m := Id
, but then invoke it with interruptibility with m := CoreM
)
Sebastian Ullrich (Sep 10 2024 at 11:46):
That sounds like something that would be best to introduce locally in your project for now :) . CoreM is currently the only core monad with any heartbeats concept.
Leni Aniva (Sep 10 2024 at 17:59):
Mario Carneiro said:
no, this is a long standing open issue
that issue refers to the frontend interface. If I just want to run some random TermElabM
with a timeout I could just use a heartbeat, right?
Eric Wieser (Sep 10 2024 at 18:36):
CoreM is currently the only core monad with any heartbeats concept.
I now remember that I wanted to abstract over docs#IO.checkCanceled as well
Eric Wieser (Sep 10 2024 at 18:37):
The context is #16666, where it would be better if the gaussian elimination algorithm used by linarith
didn't have to live in CoreM
Last updated: May 02 2025 at 03:31 UTC