Exemplo n.º 1
0
 def is_unsat(self, formula, solver_name=None, logic=None, portfolio=None):
     if portfolio is not None:
         solver = Portfolio(solvers_set=portfolio,
                            environment=self.environment,
                            logic=logic,
                            generate_models=False, incremental=False)
     else:
         solver = self.Solver(name=solver_name, logic=logic,
                              generate_models=False, incremental=False)
     with solver:
         return solver.is_unsat(formula)
Exemplo n.º 2
0
 def is_unsat(self, formula, solver_name=None, logic=None, portfolio=None):
     if logic is None or logic == AUTO_LOGIC:
         logic = get_logic(formula, self.environment)
     if portfolio is not None:
         solver = Portfolio(solvers_set=portfolio,
                            environment=self.environment,
                            logic=logic,
                            generate_models=False, incremental=False)
     else:
         solver = self.Solver(name=solver_name, logic=logic,
                              generate_models=False, incremental=False)
     with solver:
         return solver.is_unsat(formula)
Exemplo n.º 3
0
 def is_valid(self, formula, solver_name=None, logic=None, portfolio=None):
     if logic is None or logic == AUTO_LOGIC:
         logic = get_logic(formula, self.environment)
     if portfolio is not None:
         solver = Portfolio(solvers_set=portfolio,
                            environment=self.environment,
                            logic=logic,
                            generate_models=False, incremental=False)
     else:
         solver = self.Solver(name=solver_name, logic=logic,
                              generate_models=False, incremental=False)
     with solver:
         return solver.is_valid(formula)
Exemplo n.º 4
0
    def test_smtlib_multi_msat(self):
        from pysmt.test.smtlib.parser_utils import SMTLIB_TEST_FILES, SMTLIB_DIR

        # On some platforms (Windows x64) the internal pickling process requires
        # quite a lot of recursion...
        old_recursion_limit = sys.getrecursionlimit()
        sys.setrecursionlimit(999999)

        for (logic, f, expected_result) in SMTLIB_TEST_FILES:
            smtfile = os.path.join(SMTLIB_DIR, f)
            if logic <= QF_UFLIRA:
                env = reset_env()
                formula = get_formula_fname(smtfile, env)
                # Simplifying the formula to reduce its depth to avoid errors on some
                # platforms until issue #455 for details.
                formula = formula.simplify()
                with Portfolio([("msat", {
                        "random_seed": 1
                }), ("msat", {
                        "random_seed": 17
                }), ("msat", {
                        "random_seed": 42
                })],
                               logic=logic,
                               environment=env,
                               incremental=False,
                               generate_models=False) as s:
                    res = s.is_sat(formula)
                    self.assertEqual(expected_result, res, smtfile)

        #reset recursion limit
        sys.setrecursionlimit(old_recursion_limit)
Exemplo n.º 5
0
 def run_smtlib(self, smtfile, logic, expected_result):
     env = reset_env()
     formula = get_formula_fname(smtfile, env)
     with Portfolio(["cvc4", "msat", "yices"],
                    logic=logic,
                    environment=env,
                    incremental=False,
                    generate_models=False) as s:
         res = s.is_sat(formula)
         self.assertEqual(expected_result, res, smtfile)
Exemplo n.º 6
0
 def test_basic(self):
     with Portfolio(["z3", "msat", "cvc4"],
                    environment=self.env,
                    logic="QF_LRA") as p:
         for example in get_example_formulae():
             if not example.logic <= QF_LRA: continue
             res = p.is_sat(example.expr)
             self.assertEqual(res, example.is_sat, example.expr)
             if res:
                 self.assertTrue(p.get_model().get_value(
                     example.expr).is_true())
Exemplo n.º 7
0
 def test_get_value(self):
     with Portfolio(["msat", "picosat", "btor", "bdd"],
                    logic=QF_UFLIRA,
                    environment=self.env,
                    incremental=False,
                    generate_models=True) as s:
         x, y = Symbol("x"), Symbol("y")
         s.add_assertion(Implies(x, y))
         s.add_assertion(x)
         res = s.solve()
         self.assertTrue(res)
         v = s.get_value(x)
         self.assertTrue(v, TRUE())
Exemplo n.º 8
0
    def test_exceptions(self):
        with Portfolio(["bdd", "z3"],
                       logic=QF_BOOL,
                       environment=self.env,
                       incremental=True,
                       generate_models=True,
                       solver_options={"exit_on_exception": False}) as s:
            s.add_assertion(Equals(Symbol("r", REAL), Symbol("r", REAL)))
            res = s.solve()
            self.assertTrue(res)

            # TODO: How can we make this test more robust?
            # It assumes that bdd will raise an error before z3.
            # It should be so, but this is non-deterministic by nature
            with Portfolio(["bdd", "z3"],
                           logic=QF_BOOL,
                           environment=self.env,
                           incremental=True,
                           generate_models=True,
                           solver_options={"exit_on_exception": True}) as s:
                s.add_assertion(Equals(Symbol("r", REAL), Symbol("r", REAL)))
                with self.assertRaises(Exception):
                    s.solve()
Exemplo n.º 9
0
 def test_incrementality(self):
     with Portfolio(["cvc4", "msat", "yices"],
                    logic=QF_UFLIRA,
                    environment=self.env,
                    incremental=True,
                    generate_models=True) as s:
         x, y = Symbol("x"), Symbol("y")
         s.add_assertion(Implies(x, y))
         s.push()
         s.add_assertion(x)
         res = s.solve()
         self.assertTrue(res)
         v = s.get_value(y)
         self.assertTrue(v, TRUE())
         s.pop()
         s.add_assertion(x)
         res = s.solve()
         self.assertTrue(res)
         v = s.get_value(x)
         self.assertTrue(v, FALSE())
Exemplo n.º 10
0
    def test_smtlib_multi_msat(self):
        from pysmt.test.smtlib.parser_utils import SMTLIB_TEST_FILES, SMTLIB_DIR

        for (logic, f, expected_result) in SMTLIB_TEST_FILES:
            smtfile = os.path.join(SMTLIB_DIR, f)
            if logic <= QF_UFLIRA:
                env = reset_env()
                formula = get_formula_fname(smtfile, env)
                with Portfolio([("msat", {
                        "random_seed": 1
                }), ("msat", {
                        "random_seed": 17
                }), ("msat", {
                        "random_seed": 42
                })],
                               logic=logic,
                               environment=env,
                               incremental=False,
                               generate_models=False) as s:
                    res = s.is_sat(formula)
                    self.assertEqual(expected_result, res, smtfile)