I use Z3Py to build large formulas (~1500 Bool
variables, ~90k assertions) and I am currently using Solver.add
to add the assertions, which are mostly small (eg. implications on 2 variables).
My code looks something like this, with about 10 outer for
loops in sequence. The loop nesting depth varies from 2 to 6.
s = Solver()
for i in range(A):
for j in range(B):
...
s.add(Implies(vars[i,j,...], vars[k,l,...]))
The problem is that building the solver takes ~11 seconds (with __debug__ == False
), while finding a solution only takes about 8.
Profiling shows that a lot of time is spent in Z3_sort_to_ast
, z3code.Elementaries.Check
(called by the former), and other methods which seem like they could be inlined at least, if not somehow eliminated.
How does one optimize the creation of the Z3 Solver
? Maybe there is a more low-level, internal interface which could speed things up?