Skip to content
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

Merged
merged 9 commits into from Oct 8, 2016
Merged

Conversation

marcogario
Copy link
Contributor

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:

  • MathSAT5Solver option 'debugFile' has been removed. 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.

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
@marcogario
Copy link
Contributor Author

This PR includes two additional changes:

  • CVC4 installer is more robust when installing on a system with multiple version of python
  • pyPicosat has been extended to better deal with flushing of the output log.

Copy link
Contributor

@mikand mikand left a 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'):
Copy link
Contributor

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.

Copy link
Contributor Author

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))
Copy link
Contributor

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):
Copy link
Contributor

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))
Copy link
Contributor

@mikand mikand Oct 7, 2016

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
Copy link
Contributor

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())
Copy link
Contributor

@mikand mikand Oct 7, 2016

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
Copy link
Contributor

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

Copy link
Contributor Author

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):
Copy link
Contributor

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....

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

@coveralls
Copy link

coveralls commented Oct 7, 2016

Coverage Status

Changes Unknown when pulling b45cb35 on i105/options into * on master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling b45cb35 on i105/options into * on master*.

@mikand mikand assigned marcogario and unassigned mikand Oct 7, 2016
@marcogario marcogario mentioned this pull request Oct 7, 2016
@marcogario marcogario assigned mikand and unassigned marcogario Oct 7, 2016
@mikand mikand merged commit 1fc9428 into master Oct 8, 2016
@mikand mikand deleted the i105/options branch October 8, 2016 12:31
nbailluet pushed a commit to nbailluet/pysmt that referenced this pull request Mar 14, 2024
Use solver_options to specify solver-dependent options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants