Boolector / boolector

A Satisfiability Modulo Theories (SMT) solver for the theories of fixed-size bit-vectors, arrays and uninterpreted functions.
http://boolector.github.io
Other
334 stars 62 forks source link

Set timeout on the fly, using command line interface #18

Open Joool opened 6 years ago

Joool commented 6 years ago

I am currently in the process of migrating a project from z3 to boolector and was wondering if it offers a similar functionality to change timeout on the fly, e.g.:

(set-option :timeout 2000)

I searched the API docs and found this, however, I was wondering if there is exists a comparable feature when using boolector from the command line with the smt2 flag.

mpreiner commented 6 years ago

There is currently no such feature implemented in the SMT2 front-end. However, we can add this feature in the future via the terminate function callbacks in the SMT2 front-end.

Joool commented 6 years ago

Thank you very much for your quick response, much appreciated!

While you are at it, I'm also missing a feature to reset the solver, i.e., z3's (reset). My workflow is as follows:

However, I kind of want to avoid resetting them every time.

I hope I am not asking to much.

mpreiner commented 6 years ago

Can you provide a small SMT2 example for this workflow? That would be really helpful!

Joool commented 6 years ago

Sure:

(declare-const sub_1 (_ BitVec 256))
(declare-const sub_3 (_ BitVec 256))
(declare-const sub_2 (_ BitVec 256))
(assert (= sub_1 (_ bv1 256) ))
(assert (= sub_2 (_ bv0 256) ))
(assert (= sub_3 (ite (= sub_2 sub_1) (_ bv1 256) (_ bv0 256)) ))
(assert (= sub_3 (_ bv1 256) ))
(check-sat)
(reset)
(declare-const sub_1 (_ BitVec 256))
(declare-const sub_3 (_ BitVec 256))
(declare-const sub_2 (_ BitVec 256))
(assert (= sub_1 (_ bv0 256) ))
(assert (= sub_2 (_ bv0 256) ))
(assert (= sub_3 (ite (= sub_2 sub_1) (_ bv1 256) (_ bv0 256)) ))
(assert (= sub_3 (_ bv1 256) ))
(check-sat)

Maybe as context, I'm doing symbolic execution. However, in a multi threaded environment, i.e., I explore multiple paths simultaneously. I run multiple solver instances and tracking which solver has which symbols defined is too much of an overhead. Thus, I just cycle through the solvers, reseting them every time. Note (reset), is defined by z3 not by SMT2.

mpreiner commented 6 years ago

Have you tried using push/pop instead of a reset? Or are the queries not related at all so that you always want to query a "fresh" instance of the solver?

Here would be the version with push/pop:

(push 1)
(declare-const sub_1 (_ BitVec 256))
(declare-const sub_3 (_ BitVec 256))
(declare-const sub_2 (_ BitVec 256))
(assert (= sub_1 (_ bv1 256) ))
(assert (= sub_2 (_ bv0 256) ))
(assert (= sub_3 (ite (= sub_2 sub_1) (_ bv1 256) (_ bv0 256)) ))
(assert (= sub_3 (_ bv1 256) ))
(check-sat)
(pop 1)
(push 1)
(declare-const sub_1 (_ BitVec 256))
(declare-const sub_3 (_ BitVec 256))
(declare-const sub_2 (_ BitVec 256))
(assert (= sub_1 (_ bv0 256) ))
(assert (= sub_2 (_ bv0 256) ))
(assert (= sub_3 (ite (= sub_2 sub_1) (_ bv1 256) (_ bv0 256)) ))
(assert (= sub_3 (_ bv1 256) ))
(check-sat)
(pop 1)
Joool commented 6 years ago

Ohh yeah forgot about that mode, I tried it with z3, but performance really suffers (https://stackoverflow.com/questions/26416814/why-does-z3-check-slow-when-it-is-immediately-preceded-by-z3-push). Thanks! I will give it a try with boolector.

pointhi commented 5 years ago

Any update in the meantime?

According to the help message there is the possibility of a time limit, but its an absolute timeout starting with the program execution:

  -t <seconds>,
    --time=<seconds>                  set time limit

It would be nice to have the ability to set a timeout which applies to commands like (check-sat), and thus is meaningful when using boolector for iterative solving. A global time limit does not make sense in those cases.

aytey commented 5 years ago

Hi @pointhi,

This is definitely not an official answer, but I had a need for something like this, which ended-up with this branch:

https://github.com/Boolector/boolector/compare/smtcomp19...andrewvaughanj:timeouts_for_term?expand=1

This adds:

(all values are in millis).

Some important notes:

Let me know how you get on and, if it is successful, I can see about wrapping it up into an official PR.

Cheers,

Andrew

mpreiner commented 2 months ago

Boolector is not actively maintained and developed anymore. It was succeeded by Bitwuzla and the repository is now archived.