-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
parse_smt2_string() wastes time creating copies of symbols and functions #6123
Comments
sorry, this is very vague. To start with what is dict2sarray? |
I didn't use any profilers, but I think from just reading the definition of Here's where we call Line 9212 in ea2a843
And here's a reproducer that should hopefully demonstrate the problem:
|
Alright, this is about the python API (and not inside of z3) and the ask is to cache results. Maybe use attributes, setattr, getattr on the dictionary objects to cache the result and retrieve it if the dictionary didn't change. |
Caching translated symbols and functions unfortunately wouldn't help where we have to amend the dictionary. A better solution might be to introduce a couple classes that store symbols and functions in a form that can be passed to |
In that case, the underlying API is not suitable. |
Adding new API object to maintain state between calls to parser. The state is incremental: all declarations of sorts and functions are valid in the next parse. The parser produces an ast-vector of assertions that are parsed in the current calls. The following is a unit test: ``` from z3 import * pc = ParserContext() A = DeclareSort('A') pc.add_sort(A) print(pc.from_string("(declare-const x A) (declare-const y A) (assert (= x y))")) print(pc.from_string("(declare-const z A) (assert (= x z))")) print(parse_smt2_string("(declare-const x Int) (declare-const y Int) (assert (= x y))")) s = Solver() s.from_string("(declare-sort A)") s.from_string("(declare-const x A)") s.from_string("(declare-const y A)") s.from_string("(assert (= x y))") print(s.assertions()) s.from_string("(declare-const z A)") print(s.assertions()) s.from_string("(assert (= x z))") print(s.assertions()) ``` It produces results of the form ``` [x == y] [x == z] [x == y] [x == y] [x == y] [x == y, x == z] ``` Thus, the set of assertions returned by a parse call is just the set of assertions added. The solver maintains state between parser calls so that declarations made in a previous call are still available when declaring the constant 'z'. The same holds for the parser_context_from_string function: function and sort declarations either added externally or declared using SMTLIB2 command line format as strings are valid for later calls.
I have added a separate mechanism for parsing incrementally. |
Will give a try, thanks! Regarding using the API for building expressions, the aim is to serialise expressions and then load them back. I know there is If I take it right that |
you can parse multiple expressions by adding multiple assertions. Each assertion is an element in the vector that is returned. |
Closing, as feature is there to support incremental parsing. |
The definition of
parse_smt2_string()
reads like it calls_dict2sarray()
for the passed symbols and functions, which causes significant delays on large dictionaries -- a huge problem when you have hundreds of expressions to parse. Would it possible to introduce aDict2DArray
kind of class that implements storing such arrays in a ready-to-use form and allow its instances along with ordinary dictionaries for thesorts
anddecls
parameters soparse_smt2_string()
doesn't need to translate them on every call?The text was updated successfully, but these errors were encountered: