Skip to content
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

CVC5 timeout implementation #419

Open
Avgor46 opened this issue Dec 26, 2024 · 4 comments
Open

CVC5 timeout implementation #419

Avgor46 opened this issue Dec 26, 2024 · 4 comments

Comments

@Avgor46
Copy link

Avgor46 commented Dec 26, 2024

Hi!

I am trying to implement timeout on query to CVC5 solver. I am aware of non-existence of such interface in library (there is ShutdownManager, but it does not implement timeout by itself). If I want to timeout solver, I need to run it in separate thread. So, according to the description of SolverContext, I have to create new SolverContext and transfer formulas from original context to the new one using translateFrom method. This method uses parse method which it is not implemented for CVC5...

I also tried to pass formulas to new context prover without conversion and got error io.github.cvc5.CVC5ApiException: Given term is not associated with the term manager of this solver. And also tried to call isUnsat from old context in new thread which resulted in error in native code.

So, is it real to implement timeout for CVC5 solver? Maybe I am missing something...

@kfriedberger
Copy link
Member

Hi.

There’s no need to create a second SolverContext to implement a timeout for a solver. You can use the ShutdownManager to handle this. While the ShutdownManager itself doesn’t provide a built-in timeout mechanism, it can still be effectively used for this purpose by triggering it from a separate thread that monitors the timeout.

There is an example for this in the test files:

private void testBasicProverTimeout(
Supplier<BasicProverEnvironment<?>> proverConstructor, BooleanFormula instance)
throws InterruptedException, SolverException {
Thread t =
new Thread(
() -> {
try {
Thread.sleep(delay);
shutdownManager.requestShutdown("Shutdown Request");
} catch (InterruptedException exception) {
throw new UnsupportedOperationException("Unexpected interrupt", exception);
}
});
try (BasicProverEnvironment<?> pe = proverConstructor.get()) {
pe.push(instance);
t.start();
assertThrows(InterruptedException.class, pe::isUnsat);
}
}

There is a limitation: we currently do not support "timeout per prover instance", because the ShutdownManager is shared across the whole solver instance. Thus, all running SAT-checks are aborted.

@Avgor46
Copy link
Author

Avgor46 commented Dec 26, 2024

Could I use corresponding SolverContext after shutdown and try to solve other set of constraints with new prover?

@kfriedberger
Copy link
Member

That’s a great question! While I haven’t personally tried this, it appears that once the ShutdownManager is triggered, it sends an interrupt signal to all associated components. Since the shutdown operation is currently designed to be a one-time action, attempting to reuse the SolverContext and shutting it down again might lead to unexpected behaviour. You might need an independent SolverContext for such cases.

@Avgor46
Copy link
Author

Avgor46 commented Dec 26, 2024

I'll definitely try to use the same context tomorrow) And if it doesn't work, it seems impossible to reuse previously generated constraints in new CVC5 context due to the unimplemented parse method( Or is there some way to do it even after shutdown? (I hope so)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants