Skip to content

Commit eb7ae9d

Browse files
authored
restricting the use of Solver(): no specification of logic (#95)
Solves #93 in order to be compatible with z3.
1 parent ba96caf commit eb7ae9d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

cvc5_pythonic_api/cvc5_pythonic.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6011,16 +6011,16 @@ class Solver(object):
60116011
* get-model,
60126012
* etc."""
60136013

6014-
def __init__(self, logic=None, ctx=None, logFile=None):
6015-
# save logic so that we can re-build the solver if needed.
6016-
self.logic = logic
6014+
def __init__(self, ctx=None, logFile=None):
60176015
# ignore ctx (the paramter is kept for z3 compatibility)
60186016
self.solver = None
6017+
self.logic = None
60196018
self.initFromLogic()
60206019
self.scopes = 0
60216020
self.assertions_ = [[]]
60226021
self.last_result = None
60236022
self.resetAssertions()
6023+
assert ctx is None or type(ctx) == Context
60246024

60256025
def initFromLogic(self):
60266026
"""Create the base-API solver from the logic"""
@@ -6426,7 +6426,10 @@ def SolverFor(logic, ctx=None, logFile=None):
64266426
# sat
64276427
# >>> s.model()
64286428
# [x = 1]
6429-
return Solver(logic=logic, ctx=ctx, logFile=logFile)
6429+
s = Solver(ctx=ctx, logFile=logFile)
6430+
s.logic = logic
6431+
s.initFromLogic()
6432+
return s
64306433

64316434

64326435
def SimpleSolver(ctx=None, logFile=None):

test/pgm_outputs/multiple_solvers.py.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The logic was specified as QF_BV, which doesn't include THEORY_ARITH, but got a
55
The atom:
66
(= x (* 2 y))
77
Can't solve integer problems with QF_BV solver
8+
got an exception, which is good
89
unsat
910
unsat
1011
Can't eagerly BB with models and ALL

test/pgms/multiple_solvers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
print(e)
2222
print("Can't solve integer problems with QF_BV solver")
2323

24+
# Can't specify logic unless using `SolverFor`
25+
try:
26+
s = Solver("QF_BV")
27+
except Exception as e:
28+
print("got an exception, which is good")
29+
2430

2531
# QF_NIA
2632
s = SolverFor("QF_BV")

0 commit comments

Comments
 (0)