Ejemplo n.º 1
0
 def test_most_generic(self):
     self.assertTrue(QF_LIA < LIA)
     self.assertTrue(LIA < UFLIRA)
     self.assertTrue(UFLIRA > QF_LIA)
     self.assertTrue(UFLIRA >= UFLIRA)
     self.assertFalse(LRA >= LIA)
     self.assertFalse(LRA <= LIA)
     mgl = most_generic_logic([QF_LIA, LIA, LRA, UFLIRA])
     self.assertEqual(mgl, UFLIRA)
     self.assertFalse(QF_BV >= QF_UFLIRA)
     self.assertFalse(QF_BV <= QF_UFLIRA)
     with self.assertRaises(NoLogicAvailableError):
         most_generic_logic(PYSMT_LOGICS)
Ejemplo n.º 2
0
 def test_most_generic(self):
     self.assertTrue(QF_LIA < LIA)
     self.assertTrue(LIA < UFLIRA)
     self.assertTrue(UFLIRA > QF_LIA)
     self.assertTrue(UFLIRA >= UFLIRA)
     self.assertFalse(LRA >= LIA)
     self.assertFalse(LRA <= LIA)
     mgl = most_generic_logic([QF_LIA, LIA, LRA, UFLIRA])
     self.assertEqual(mgl, UFLIRA)
     self.assertFalse(QF_BV >= QF_UFLIRA)
     self.assertFalse(QF_BV <= QF_UFLIRA)
     self.assertTrue(NRA > LRA)
     with self.assertRaises(NoLogicAvailableError):
         most_generic_logic(PYSMT_LOGICS)
Ejemplo n.º 3
0
def Solver(name: str, logic: tp.Optional[logics.Logic] = None) -> SolverT:
    '''
    Convience function for building a pysmt solver object with a switch backend.
    Similar to `pysmt.shortcuts.Solver`.
    '''
    try:
        cls = SWITCH_SOLVERS[name]
    except KeyError:
        raise NoSolverAvailableError(
            f"Solver '{name}' is not available") from None

    if isinstance(logic, str):
        logic = logics.convert_logic_from_string(logic)
    elif logic is None:
        # Try to use the most general logic supported
        try:
            logic = logics.most_generic_logic(cls.LOGICS)
        except NoLogicAvailableError:
            # supported logics do not have a single "upper bound"
            # Check for some reasonable ones
            if logics.QF_UFLIRA in cls.LOGICS:
                logic = logics.QF_UFLIRA
            elif logics.QF_AUFBV in cls.LOGICS:
                logic = logics.QF_AUFBV
            else:
                # use the first one
                logic = cls.LOGICS[0]

    return cls(environment=get_env(), logic=logic)
Ejemplo n.º 4
0
    def test_most_generic(self):
        self.assertTrue(QF_LIA < LIA)
        self.assertTrue(LIA < UFLIRA)
        self.assertTrue(UFLIRA > QF_LIA)
        self.assertTrue(UFLIRA >= UFLIRA)
        self.assertFalse(LRA >= LIA)
        self.assertFalse(LRA <= LIA)
        mgl = most_generic_logic([QF_LIA, LIA, LRA, UFLIRA])
        self.assertEqual(mgl, UFLIRA)
        self.assertFalse(QF_BV >= QF_UFLIRA)
        self.assertFalse(QF_BV <= QF_UFLIRA)
        self.assertTrue(NRA > LRA)
        self.assertTrue(QF_BOOL < QF_IDL)
        with self.assertRaises(NoLogicAvailableError):
            most_generic_logic(PYSMT_LOGICS)

        t = Theory(arrays=True, arrays_const=True, integer_arithmetic=True)
        self.assertIsNotNone(t)
Ejemplo n.º 5
0
    def test_most_generic(self):
        self.assertTrue(QF_LIA < LIA)
        self.assertTrue(LIA < UFLIRA)
        self.assertTrue(UFLIRA > QF_LIA)
        self.assertTrue(UFLIRA >= UFLIRA)
        self.assertFalse(LRA >= LIA)
        self.assertFalse(LRA <= LIA)
        mgl = most_generic_logic([QF_LIA, LIA, LRA, UFLIRA])
        self.assertEqual(mgl, UFLIRA)
        self.assertFalse(QF_BV >= QF_UFLIRA)
        self.assertFalse(QF_BV <= QF_UFLIRA)
        self.assertTrue(NRA > LRA)
        with self.assertRaises(NoLogicAvailableError):
            most_generic_logic(PYSMT_LOGICS)

        t = Theory(arrays=True,
                   arrays_const=True,
                   integer_arithmetic=True)
        self.assertIsNotNone(t)
Ejemplo n.º 6
0
    def _get_solver_class(self,
                          solver_list,
                          solver_type,
                          preference_list,
                          default_logic,
                          name=None,
                          logic=None):
        if len(solver_list) == 0:
            raise NoSolverAvailableError("No %s is available" % solver_type)

        logic = convert_logic_from_string(logic)
        if name is not None:
            if name not in solver_list:
                raise NoSolverAvailableError("%s '%s' is not available" % \
                                             (solver_type, name))

            if logic is not None and \
               name not in self._filter_solvers(solver_list, logic=logic):
                raise NoSolverAvailableError(
                    "%s '%s' does not support logic %s" %
                    (solver_type, name, logic))

            SolverClass = solver_list[name]
            if logic is None:
                try:
                    logic = most_generic_logic(SolverClass.LOGICS)
                except NoLogicAvailableError:
                    if default_logic in SolverClass.LOGICS:
                        logic = default_logic
                    else:
                        raise NoLogicAvailableError(
                            "Cannot automatically select a logic")

            closer_logic = get_closer_logic(SolverClass.LOGICS, logic)

            return SolverClass, closer_logic

        if logic is None:
            logic = default_logic

        solvers = self._filter_solvers(solver_list, logic=logic)

        if solvers is not None and len(solvers) > 0:
            # Pick the first solver based on preference list
            SolverClass = self._pick_favorite(preference_list, solver_list,
                                              solvers)
            closer_logic = get_closer_logic(SolverClass.LOGICS, logic)
            return SolverClass, closer_logic

        else:
            raise NoSolverAvailableError("No %s is available for logic %s" %
                                         (solver_type, logic))
Ejemplo n.º 7
0
    def _get_solver_class(self, solver_list, solver_type, preference_list,
                          default_logic, name=None, logic=None):
        if len(solver_list) == 0:
            raise NoSolverAvailableError("No %s is available" % solver_type)

        logic = convert_logic_from_string(logic)
        if name is not None:
            if name not in solver_list:
                raise NoSolverAvailableError("%s '%s' is not available" % \
                                             (solver_type, name))

            if logic is not None and \
               name not in self._filter_solvers(solver_list, logic=logic):
                raise NoSolverAvailableError("%s '%s' does not support logic %s"%
                                             (solver_type, name, logic))

            SolverClass = solver_list[name]
            if logic is None:
                try:
                    logic = most_generic_logic(SolverClass.LOGICS)
                except NoLogicAvailableError:
                    if default_logic in SolverClass.LOGICS:
                        logic = default_logic
                    else:
                        raise NoLogicAvailableError("Cannot automatically select a logic")

            closer_logic = get_closer_logic(SolverClass.LOGICS, logic)

            return SolverClass, closer_logic

        if logic is None:
            logic = default_logic

        solvers = self._filter_solvers(solver_list, logic=logic)

        if solvers is not None and len(solvers) > 0:
            # Pick the first solver based on preference list
            SolverClass = self._pick_favorite(preference_list, solver_list, solvers)
            closer_logic = get_closer_logic(SolverClass.LOGICS, logic)
            return SolverClass, closer_logic

        else:
            raise NoSolverAvailableError("No %s is available for logic %s" %
                                         (solver_type, logic))
Ejemplo n.º 8
0
    def get_solver(self, quantified=False, name=None, logic=None):
        assert quantified is False or logic is None, \
            "Cannot specify both quantified and logic."

        if quantified is True:
            logic = self.default_logic.get_quantified_version

        if name is not None:
            if name in self._all_solvers:
                if logic is None:
                    SolverClass = self._all_solvers[name]
                    logic = most_generic_logic(SolverClass.LOGICS)
                else:
                    if name in self.all_solvers(logic=logic):
                        SolverClass = self._all_solvers[name]
                    else:
                        raise NoSolverAvailableError("Solver '%s' does not" \
                                                     " support logic %s" %
                                                     (name, logic))

                closer_logic = get_closer_logic(SolverClass.LOGICS, logic)
                return SolverClass(environment=self.environment,
                                   logic=closer_logic,
                                   options=None)
            else:
                raise NoSolverAvailableError("Solver %s is not available" %
                                             name)

        if logic is None:
            logic = self.default_logic

        solvers = self.all_solvers(logic=logic)

        if solvers is not None and len(solvers) > 0:
            # Pick the first solver based on preference list
            SolverClass = self.pick_favorite_solver(solvers)
            closer_logic = get_closer_logic(SolverClass.LOGICS, logic)
            return SolverClass(environment=self.environment,
                               logic=closer_logic,
                               options=None)
        else:
            raise NoSolverAvailableError("No solver is available for logic %s" %\
                                         logic)