2

I am using Java API of Z3 and I would like to get some statistics from the solver such as solving time, number of variables/symbols, memory usage. The post here (Z3py: how to get the list of variables from a formula?) claims that there is a utility implementation in Python but I was wondering if there is any for JavaAPI.

Thanks.

Community
  • 1
  • 1
fturkmen
  • 324
  • 3
  • 11

1 Answers1

2

Those particular utilities are an external contribution to Z3 and only available for the Python API. It should be possible to follow the same ideas in Java though.

The Solver object has a function called getStatistics() that returns Statistics object, which is essentially a collection of key/value pairs. Note that zero-valued statistical values are not reported (see e.g., also the discussion here).

There is currently no documentation for the statistical values reported (or the precision with which they are tracked), so all these values should be treated with care.

See also the following related questions:

Interpretation of Z3 Statistics

How to interpret statistics Z3

Which statistics indicate an efficient run of Z3?

Community
  • 1
  • 1
Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30
  • Thanks a lot for the reply! Perhaps we are using different versions. The Statistics object returns me the following (no time here): (:binary-propagations 3 :conflicts 1 :datatype-accessor-ax 2 :datatype-occurs-check 2 :decisions 5 :final-checks 1 :mk-clause 2 :propagations 3) – fturkmen Apr 14 '14 at 16:21
  • Yes that's quite possible. The `time` and `total-time` statistics are tracked outside of the Solver.check() command in the SMT2 command-interface, so they may not be present when called through the API. The same applies to the memory statistics. – Christoph Wintersteiger Apr 14 '14 at 17:11
  • Is it the same for memory usage? Do you have any straightforward suggestion for getting the allocated memory size? – fturkmen Apr 14 '14 at 18:00
  • At the moment there is no easy way to get that. If you absolutely need it, you could patch the source to insert this statistic upon the call to get_statistics (see src/cmd_context/cmd_context.cpp:1579; something similar would have to be inserted in many other places, but most importantly for the default solver in combined_solver.cpp:246) – Christoph Wintersteiger Apr 15 '14 at 11:01
  • Thanks. For the time being my workaround is to dump the formula to an smt2 file and execute z3 from the command line. – fturkmen Apr 15 '14 at 14:29