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
Use solver_options to specify solver-dependent options #338
Conversation
Options that are shared by multiple solvers are handled as keywords arguments, but solver-dependent options are defined in the solver_options dictionary: Solver(name='picosat', generate_models=True, solver_options={'propagation_limit': 100}) The goal is to clearly separate these two type of configurations. The use of dictionary for solver_options, makes it simple to store multiple configurations: Solver(name=sname, solver_options=myoptions[sname]) All solvers have been ported to this new strategy, by using a custom SolverOptions object that is responsible for the definition, checking and setting of the options. This object is used (for example) to correctly setup the mathsat context. Option "random_seed" is now supported by all the solvers (that do support it). Deprecation: Backwards Incompatible Changes: * MathSAT5Solver option 'debugFile' has been removed deprecated. Use the solver option: "debug_api_call_trace_filename". * BddSolver used to have the options as keyword arguments (static_ordering, dynamic_reordering etc). This is not supported anymore.
CVC4 configure using the default path of the 'python' executable to compile the python bindings. On systems where multiple versions of python are installed, running install.py with a different version of python (e.g., python3.5) would lead to the creation of invalid bindings.
CVC4.OptionException is not a valid python 3 exception (since it does not inherit from BaseException). Therefore, in python 3, we cannot use a regular try/except to catch it. This should be fixed in the CVC4 wrapper, here we simply work around the issue.
This also upgrade to the latest wrapper
This PR includes two additional changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks great and solves the option issue in a very clean way. I marked few points to fix/discuss before accepting.
solver.set_option(":random-seed", str(self.random_seed)) | ||
|
||
for k,v in self.solver_options.items(): | ||
if k in (':print-success', 'diagnostic-output-channel'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the user pusts :produce-models
in the solver_options? Maybe we should avoid overriding all the pysmt-interpreted options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I understand this point.
@@ -86,13 +123,13 @@ def _send_silent_command(self, cmd): | |||
def _get_answer(self): | |||
"""Reads a line from STDOUT pipe""" | |||
res = self.solver_stdout.readline().strip() | |||
if self.dbg: print("Read: " + str(res)) | |||
if self.options.debug_interaction: print("Read: " + str(res)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use _debug
@@ -71,9 +104,13 @@ def set_option(self, name, value): | |||
def set_logic(self, logic): | |||
self._send_silent_command(SmtLibCommand(smtcmd.SET_LOGIC, [logic])) | |||
|
|||
def _debug(self, msg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To save a little bit of time you could change _debug
as follows.
def _debug(self, msg, *format_args):
if self.options.debug_interaction:
print(msg % format_args)
In this way, we can avoid the construction of the debug string if the debugging is not enabled.
return res | ||
|
||
def _get_value_answer(self): | ||
"""Reads and parses an assignment from the STDOUT pipe""" | ||
lst = self.parser.get_assignment_list(self.solver_stdout) | ||
if self.dbg: print("Read: " + str(lst)) | ||
if self.options.debug_interaction: print("Read: " + str(lst)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use _debug
|
||
def __init__(self, **base_options): | ||
SolverOptions.__init__(self, **base_options) | ||
# TODO: CVC4 Supports UnsatCore extraction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add reference to #349
@@ -98,7 +125,7 @@ def solve(self, assumptions=None): | |||
else: | |||
try: | |||
res = self.cvc4.checkSat() | |||
except CVC4.LogicException as ex: | |||
except: | |||
raise InternalSolverError(ex.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ex
variable is now unassigned!
class YicesOptions(SolverOptions): | ||
def __init__(self, **base_options): | ||
SolverOptions.__init__(self, **base_options) | ||
# TODO: Yices Supports UnsatCore extraction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK Yices does NOT support Unsat Core extraction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The manual explicitly says so.
self.converter = YicesConverter(environment) | ||
self.mgr = environment.formula_manager | ||
self.model = None | ||
self.failed_pushes = 0 | ||
return | ||
|
||
def _create_yices_context(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in a separate method? All the other solvers have this in their constructor, and this method is only called from there....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly because there is a bit of additional code to handle 1) the logic selection 2) setting of parameters (set_params) 3) freeing of configuration.
We can also probably just isolate the bit about the logic conversion.
@@ -15,6 +15,7 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
# | |||
from nose.plugins.attrib import attr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
Changes Unknown when pulling b45cb35 on i105/options into * on master*. |
1 similar comment
Changes Unknown when pulling b45cb35 on i105/options into * on master*. |
Use solver_options to specify solver-dependent options
Options that are shared by multiple solvers are handled as keywords
arguments, but solver-dependent options are defined in the
solver_options dictionary:
Solver(name='picosat', generate_models=True,
solver_options={'propagation_limit': 100})
The goal is to clearly separate these two type of configurations.
The use of dictionary for solver_options, makes it simple to store
multiple configurations:
Solver(name=sname, solver_options=myoptions[sname])
All solvers have been ported to this new strategy, by using a custom
SolverOptions object that is responsible for the definition, checking
and setting of the options. This object is used (for example) to
correctly setup the mathsat context.
Option "random_seed" is now supported by all the solvers (that do
support it).
Backwards Incompatible Changes:
solver option: "debug_api_call_trace_filename".
arguments (static_ordering, dynamic_reordering etc). This is not
supported anymore.