def most_generic_logic(logics): """Given a set of logics, return the most generic one. If a unique most generic logic does not exists, throw an error. """ res = [l for l in logics if all(l >= x for x in logics)] if len(res) != 1: raise NoLogicAvailableError("Could not find the most generic " "logic for %s." % str(logics)) return res[0]
def get_closer_logic(supported_logics, logic): """ Returns the smaller supported logic that is greater or equal to the given logic. Raises NoLogicAvailableError if the solver does not support the given logic. """ res = [l for l in supported_logics if logic <= l] if len(res) == 0: raise NoLogicAvailableError("Logic %s is not supported" % logic) return min(res)
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))