def solve(fname, n, printConstraints, withSmt, withPrint): # Do the initializations. cglb.init() erlSolver = cz3.ErlangZ3() if not withSmt else cSMT.ErlangSMT() # Load the trace. r = cIO.JsonReader(fname, n) for entry, rev in r: if printConstraints: cpt.print_cmd(entry, rev) if cc.is_interpretable(entry): erlSolver.command_toSolver(entry, rev) # Load the axioms to the solver. erlSolver.add_axioms() # Solve the model. if withPrint: print "Solving the model ...", slv = erlSolver.solve() if withPrint: print slv if cc.is_sat(slv): m = erlSolver.model if withPrint: print m return (slv, str(m)) return slv
def solve(fname, n, printConstraints, withPrint): # Do the initializations. cglb.init() erlz3 = cz3.ErlangZ3() # Load the trace. r = cIO.JsonReader(fname, n) for tp, tag, x, rev in r: if printConstraints: cpt.print_cmd(tp, tag, x, rev) if cc.is_interpretable(tp): erlz3.command_toZ3(tp, x, rev) # Load the axioms to the solver. erlz3.add_axioms() # Solve the model. if withPrint: print "Solving the model ...", slv = erlz3.solve() if withPrint: print slv if slv == "sat": m = erlz3.model if withPrint: print m ps = erlz3.encode_parameters() return (slv, str(m))
def solve(fname, n, printConstraints, withPrint): # Do the initializations. cglb.init() erlSolver = cSMT.ErlangSMT(1) # Load the trace. r = cIO.JsonReader(fname, n) for entry, rev in r: if printConstraints: cpt.print_cmd(entry, rev) if cc.is_interpretable(entry): erlSolver.command_toSolver(entry, rev) # Load the axioms to the solver. erlSolver.add_axioms() # Solve the model. if withPrint: print("Solving the model ...", ) slv = erlSolver.solve() if withPrint: print(slv) if cc.is_sat(slv): m = erlSolver.encode_model() if withPrint: print(m) values = [e.value.value for e in m.model.entries] return (slv, values) return slv
def test_reader(): fname = "tmp" es = sample_entries() try: # Prepare the sample file. fd = gzip.open(fname, "wb") for e in es: write_byte(fd, e["kind"]) write_byte(fd, e["opcode"]) write_bytes(fd, integer_to_i32(e["tag"])) data = json.dumps(e["data"]) write_bytes(fd, integer_to_i32(len(data))) fd.write(data) fd.close() # Test the JsonReader. i = 0 for tp, tag, data, _ in JsonReader(fname, 10000): e = es[i] assert tp == e["opcode"], "Opcode of entry {} is {} instead of {}".format(i, tp, e["opcode"]) assert tag == e["tag"], "Tag of entry {} is {} instead of {}".format(i, tag, e["tag"]) assert data == e["data"], "Data of entry {} is {} instead of {}".format(i, data, e["data"]) i += 1 finally: os.remove(fname) if __name__ == '__main__': import os cglb.init() test_reader()
chk = slv.check() assert chk == sat, "Model in unsatisfiable" m = slv.model() encoder = TermEncoder(erl, m, fmap, arity) x_sol, f_sol = [encoder.encode(m[v]) for v in [x, f]] # Create the result f_exp = encoder.defaultFun(1) compare_solutions(f_exp, f_sol) def fun_scenarios(): """ Runs all the scenarios with funs. """ fun_scenario1() fun_scenario2() fun_scenario3() fun_scenario4() fun_scenario5() fun_scenario6() fun_scenario7() fun_scenario8() fun_scenario9() if __name__ == '__main__': import json cglb.init() test_encoder() test_decoder_simple() test_decoder_complex() fun_scenarios()
parser.add_argument("-s", "--smt", action='store_true', help="use the SMTv2 backend") parser.add_argument( "-t", "--timeout", metavar="N", type=int, default=2, help="set the timeout N for the SMT solver (default: %(default)s)") args = parser.parse_args() ## Main Program cglb.init(debug=args.debug) # Initialize the communication with Erlang erlport = cp.ErlangPort() # Initialize the Solver interface erlSolver = cSMT.ErlangSMT(args.timeout) try: while cglb.__RUN__: data = erlport.receive() clg.data_received(data) cmd = cp.decode_command(erlport, erlSolver, data) clg.clean_empty_logs() except: e = traceback.format_exc() erlport.send(e)