z3py: Is there a way to check configuration options in z3py? - z3

Suppose I define a solver in z3py as:
s = Then('qflia','skip').solver()
Is there way a to check the values of configuration options for s?

You can use the help function to get a list of parameters that the tactic is sensitive to, and if not set to anything else, they will have their default values. Note that tactics may change parameters internally, e.g., when the with tactic is used. Since tactics can override parameters multiple times, using different parameters at different points, there is in general not just a single value for a given parameter, and thus also no way to extract the current parameter settings.

Related

Is it possible to express rising/falling edge operators as SAT/SMT formula?

I am working on a satisfiability check for transition conditions of GRAFCET Diagrams (which is used to model the behaviour of a programmable logic controller). For this purpose I am using the Z3 SMT Solver.
In addition to normal operators (AND, OR, NOT and EQUALITY) the GRAFCET specification allows RISING and FALLING EDGE operators in its conditions.
Exemple: ↑a (RISING EDGE)
Explanation: The conditions is statisfied if the variable a changes its value from FALSE to TRUE.
My first thought would be to check, if there is a variable combination that statisfies a and also a variable combination that statisfies NOT(a). This way I could proof that the RISING EDGE could possibly occure.
[Q]: Is it possible to translate these operators directly in propositional logic or somthing similar to check satisfiablity in one forumula.
Raising/falling edges suggests change over time. In a SAT/SMT context, variables do not change. To model what you want, you’ll have to capture the value in successive points in different variables and check that the first is False and second is True for raising, etc.
You can also use an array indexed by an integer to represent the value. It all depends on how you translate these diagrams to SAT. In any case, the value of each variable will be constant in the model. (That is, checking a and Not(a) at the same time will always be unsatisfiable.)

When to use mlflow.set_tag() vs mlflow.log_params()?

I am confused about the usecase of mlflow.set_tag() vs mlflow.log_params() as both takes key and value pair. Currently, I use mlflow.set_tag() to set tags for data version, code version, etc and mlflow.log_params() to set model training parameters like loss, accuracy, optimizer, etc.
As teedak8s pointed out in the comments, tags and params are supposed to log different things. Params are something you want to tune based on the metrics, whereas tags are some extra information that doesn't necessarily associate with the model's performance. See how they use tags and params differently for sklearn, torch, and other packages in the Automatic Logging. That being said, as I understand it, there's no hard constraint on which to use to log which; they can be used interchangeably without error.

Display all values from Z3 model (Python)

When I want to get the values of all variables in an SMT2 instance, I use the command (set-option :auto-config false). In Z3py, setting this option doesn't work - the model doesn't display variables that I define but do not use in any constraints. If I ask for the values of these variables, I get None. I have tried these options but none of them produce the result that I want:
set_option('model_evaluator.completion', True)
set_option('smt.auto-config', False)
set_option('auto-config', False)
What should I do to get concrete values for these variables?
The auto-config option does not tell Z3 to print or omit parts of models; it just enables or disables automatic configuration of the solver (based on static formula features).
When a variable is not assigned a value in a model, it is simply irrelevant, i.e., you can make up any value for it, and it will still be a correct model. Depending on which solvers/tactics you use, the option model_evaluator.completion may solve that problem, but the safest way is to enable model completion at the time of model evaluation, i.e., use the eval(..) function with model_completion=True

z3py: How to set Tactic configuration options whose names contain "."?

The correct way of configuring tactics in z3.py is using "With".
E.g.
t = With(Tactic('simplify'), som=True)
However, some option names contain a "." in it, such as "arith.solver" in tactic "qflia". If we code in the same way
t = With(Tactic('qflia'), arith.solver=1)
The system gives an error "SyntaxError: keyword can't be an expression". I guess this is against the syntax rule for keyword in python.
How should I configure the options whose names contain "."? Or I am referring to a wrong list of tactics configuration options? The one I was using is output by command "(help-tactic)" on z3 not z3.py.
The trick is instead of using "With", we should use "set_param" or "set_option". E.g.
set_param('smt.phase_selection',5)

Using Z3's configuration API

Running z3 -p with the latest (unstable) Z3 shows a list of parameters grouped by module. The instructions read:
To set a module parameter, use <module-name>.<parameter-name>=value
Example: pp.decimal=true
In general, how do these instructions translate to the C API? In the current documentation, there seems to be a set of API calls dealing with "global" configuration, e.g., Z3_set_param_value, and another object-specific set of calls built around the Z3_params type, such as Z3_solver_set_params.
In particular, I was wondering if I can use Z3_set_param_value to globally set any parameter in any module. Other StackOverflow answers advertise the use of Z3_params objects even for global parameters, like timeout (or is it :timeout?), but it's not clear to me how this API maps to the module.parameter=value syntax.
The module/name parameters are mainly for the command-line version of Z3.
Global parameters are meant to be set once in the beginning and will then be valid for all subsequent calls. We introduced this parameter setting scheme together with the new strategies/goals/solvers/tactics/probes interface because we needed different configurations of tactics and the Z3_params object is meant to be used mainly for that. For instance, Z3_tactic_using_params creates a new tactic that is a reconfiguration of another tactic based on the options in the Z3_params object.
Note however, when creating tactics through the API, there are no modules (the tactic you create doesn't live in a Z3-internal `parameter module'). For example, in the strategies tutorial (see here), a tactic is constructed and applied as follows:
(check-sat-using (then (using-params simplify :arith-lhs true :som true)
normalize-bounds
lia2pb
pb2bv
bit-blast
sat))
So, the parameters "arith-lhs" and "som" are enabled for the simplifier. On the commandline, the same option is in the "rewriter" module, i.e., it would be rewriter.arith_lhs=true and if it is enabled on the commmand line, it will be enabled every time the simplifier is called.
A list of tactics and the list of parameters that it recognizes can be obtained by running (on Windows, Linux resp.)
echo (help-tactic) | z3 -in -smt2
echo "(help-tactic)" | z3 -in -smt2
Another thing to note is that parameters in a Z3_params object are not checked in any way, i.e., it is possible to provide a bogus parameter name and Z3 will not complain or issue a warning, the tactics will simply ignore that parameter.
The : in front of parameter names is a left-over of Lisp, which is the basis for the SMT2 format. See, e.g., here: Why colons precede variables in Common Lisp. They are only necessary when using the SMT2 input language. So, the SMT2 command
(set-option :timeout 2000)
is meant to be equivalent to the commandline parameter
timeout=2000
Since the question explicitly mentions the timeout parameter: We recently had some issues with timeout handling on OSX, it may be necessary to get the latest fixes, and of course there may be more bugs that we didn't find yet.
In the C API, the function Z3_global_param_set is used to set the global parameters, and also to set default module parameters. These parameters will be shared by all Z3_context objects created afterwards (i.e., pp.decimal) and they will be used if one of the built-in tactics is applied.

Resources