Ejemplo n.º 1
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.º 2
0
    def get_quantifier_eliminator(self, name=None):
        if len(self._all_qelims) == 0:
            raise NoSolverAvailableError(
                "No quantifier eliminator is available")

        if name is None:
            QElimClass = self.pick_favorite_qelim(self._all_qelims)
        elif name in self._all_qelims:
            QElimClass = self._all_qelims[name]
        else:
            raise NoSolverAvailableError("No quantifier eliminator %s" % name)

        return QElimClass(self.environment)
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 _pick_favorite(self, preference_list, solver_list, solvers):
     for candidate in preference_list:
         if candidate in solvers:
             return solver_list[candidate]
     raise NoSolverAvailableError(
         "Cannot find a matching solver in the preference list: %s " %
         solvers)
Ejemplo n.º 5
0
 def pick_favorite_solver(self, solvers):
     for candidate in self.solver_preference_list:
         if candidate in solvers:
             return self._all_solvers[candidate]
     raise NoSolverAvailableError(
         "Cannot find a matching solver in the preference list: %s " %
         solvers)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def pick_favorite_qelim(self, qelims):
     for candidate in self.qelim_preference_list:
         if candidate in qelims:
             return self._all_qelims[candidate]
     raise NoSolverAvailableError("Cannot find a matching quantifier " \
                                  "eliminator in the preference list")