def initZ3(): ''' first set the Z3 configs ''' assert z3.get_version() >= (4, 8, 6, 0) #set version z3.set_option('smt.string_solver', 'z3str3') # tell what string solver you will use z3.set_option('timeout', 120 * 1000 ) ### 120 seconds = 2 minutes
def get_installed_version(self): with TemporaryPath([self.bindings_dir]): try: import z3 (major, minor, ver, _) = z3.get_version() return "%d.%d.%d" % (major, minor, ver) except ImportError: if "z3" in sys.modules: del sys.modules["z3"] return None return None
def get_installed_version(self): with TemporaryPath([self.bindings_dir]): version = None try: import z3 (major, minor, ver, _) = z3.get_version() version = "%d.%d.%d" % (major, minor, ver) finally: if "z3" in sys.modules: del sys.modules["z3"] # Return None, without raising an exception # pylint: disable=lost-exception return version
def check_version(module): try: if module == "z3": import z3 (major, minor, ver, _) = z3.get_version() version = "%d.%d.%d" % (major, minor, ver) elif module == "msat": import mathsat version_str = mathsat.msat_get_version() m = re.match(r"^MathSAT5 version (\d+\.\d+\.\d+) .*$", version_str) if m is not None: version = m.group(1) elif module == "cudd": import repycudd doc = repycudd.DOCSTRING m = re.match(r"^PyCUDD (\d+\.\d+\.\d+).*", doc) if m is not None: version = m.group(1) elif module == "btor": import pyboolector version = "OK" # Just checking if import succeeds elif module == "cvc4": import CVC4 version = CVC4.Configuration_getVersionString() elif module == "picosat": import picosat version = picosat.picosat_version() elif module == "yices": import yicespy v = yicespy.__dict__['__YICES_VERSION'] m = yicespy.__dict__['__YICES_VERSION_MAJOR'] p = yicespy.__dict__['__YICES_VERSION_PATCHLEVEL'] version = "%d.%d.%d" % (v, m, p) else: print("Invalid argument '%s'" % module) exit(-2) except ImportError: version = None return version
def check_version(module): try: if module == "z3": import z3 (major, minor, ver, _) = z3.get_version() version = "%d.%d.%d" % (major, minor, ver) elif module == "msat": import mathsat version_str = mathsat.msat_get_version() m = re.match(r"^MathSAT5 version (\d+\.\d+\.\d+) .*$", version_str) if m is not None: version = m.group(1) elif module == "cudd": import repycudd doc = repycudd.DOCSTRING m = re.match(r"^PyCUDD (\d+\.\d+\.\d+).*", doc) if m is not None: version = m.group(1) elif module == "btor": import boolector version = "OK" # Just checking if import succeeds elif module == "cvc4": import CVC4 version = CVC4.Configuration_getVersionString() elif module == "picosat": import picosat version = picosat.picosat_version() elif module == "yices": import yicespy v = yicespy.__dict__['__YICES_VERSION'] m = yicespy.__dict__['__YICES_VERSION_MAJOR'] p = yicespy.__dict__['__YICES_VERSION_PATCHLEVEL'] version = "%d.%d.%d" % (v, m, p) else: print("Invalid argument '%s'" % module) exit(-2) except ImportError: version = None return version
def doZ3ForConcolicFuzzing(): ''' first set the Z3 configs ''' assert z3.get_version() >= (4, 8, 6, 0) #set version z3.set_option('smt.string_solver', 'z3str3') # tell what string solver you will use z3.set_option('timeout', 60 * 1000) ### 60 seconds = 1 minute ''' declare symbolic variables ''' z_inp = z3.Int('inp') ''' add constraints ''' z_inp < 0 # correpsonds to one branch of `inp < 0` z3.Not(z_inp < 0) # correpsonds to the other branch of `inp < 0` ''' solve() only gives a solution ''' soln = z3.solve(z_inp < 0) print(soln, dir(soln)) print('=' * 50) predicates = [z3.Not(z_inp < 0), z3.Not(z_inp == 0), z3.Not(z_inp == 1)] ''' As solve() only gives a solution , we need more using Solver() ''' solverObj = z3.Solver() # solverObj.add( z3.Not( z_inp < 0 ) , z3.Not( z_inp == 0 ), z3.Not( z_inp == 1 ) ) solverObj.add(predicates[0:-1] + [z3.Not(predicates[-1])]) print(solverObj.check()) if solverObj.check() == z3.sat and solverObj.check() != z3.unknown: m_ = solverObj.model() for decl_ in m_.decls(): print("Constraint variable(%s)=%s" % (decl_.name(), m_[decl_])) else: print("Solution not found. Oops!")
show_cfg(check_triangle) if __name__ == '__main__': paths = { '<path 1>': ([1, 2, 3, 4, 5], 'Equilateral'), '<path 2>': ([1, 2, 3, 4, 7], 'Isosceles'), '<path 3>': ([1, 2, 3, 9], 'Isosceles'), '<path 4>': ([1, 2, 11, 12, 13], 'Isosceles'), '<path 5>': ([1, 2, 11, 12, 15], 'Scalene'), '<path 6>': ([1, 2, 11, 17], 'Isosceles'), } import z3 # type: ignore if __name__ == '__main__': z3_ver = z3.get_version() print(z3_ver) if __name__ == '__main__': assert z3_ver >= (4, 8, 6, 0), "Please check z3 version" def get_annotations(fn): sig = inspect.signature(fn) return ([(i.name, i.annotation) for i in sig.parameters.values()], sig.return_annotation) if __name__ == '__main__': params, ret = get_annotations(check_triangle) params, ret
("iommu_isolation", "iommu_pgwalk"), ] if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--interactive', type=bool, nargs='?', default=INTERACTIVE, const=True) parser.add_argument('--model-hi', type=bool, nargs='?', default=MODEL_HI, const=True) args, unknown = parser.parse_known_args(sys.argv) INTERACTIVE = args.interactive MODEL_HI = args.model_hi del sys.argv[:] sys.argv.extend(unknown) if INTERACTIVE: Solver = z3.Solver print "Using z3 v" + '.'.join(map(str, z3.get_version())) unittest.main()
def get_z3_version(as_str=False): import z3 print( 'WARN: deprecated, use z3.get_version() or z3.get_version_string() directly' ) return z3.get_version_string() if as_str else z3.get_version()
import os import sys from setuptools import setup, find_packages def die(msg): print(msg, file=sys.stderr) sys.exit(1) if sys.version_info < (3, 4): die("Need Python >= 3.4; found {}".format(sys.version)) try: import z3 if z3.get_version() < (4, 5): die("Need Z3 >= 4.5; found {}".format(z3.get_version_string())) except ImportError: die("Z3 Python module was not found") with open(os.path.join(os.path.dirname(__file__), "requirements.txt")) as f: reqs = [line.strip() for line in f] setup( name='Cozy', version='2.0a1', description='Data Structure Synthesizer', author='Calvin Loncaric', author_email='*****@*****.**', url='https://cozy.uwplse.org/', packages=find_packages(),