"""Custom exceptions and warnings."""fromtypingimportAnyimportpandasaspdfromattr.validatorsimportinstance_offromattrsimportdefine,fieldfromtyping_extensionsimportoverride##### Warnings #####
[docs]classUnusedObjectWarning(UserWarning):""" A method or function was called with undesired arguments which indicates an unintended user fault. """
[docs]@defineclassSearchSpaceMatchWarning(UserWarning):""" When trying to match data to entries in the search space, something unexpected happened. """message:str=field(validator=instance_of(str))data:pd.DataFrame=field(validator=instance_of(pd.DataFrame))def__attrs_pre_init(self):super().__init__(self.message)@overridedef__str__(self):returnself.message
[docs]classMinimumCardinalityViolatedWarning(UserWarning):"""Minimum cardinality constraints are violated."""
##### Exceptions #####
[docs]classIncompatibilityError(Exception):"""Incompatible components are used together."""
[docs]classIncompatibleSearchSpaceError(IncompatibilityError):""" A recommender is used with a search space that contains incompatible parts, e.g. a discrete recommender is used with a hybrid or continuous search space. """
[docs]classIncompatibleSurrogateError(IncompatibilityError):"""An incompatible surrogate was selected."""
[docs]classIncompatibleAcquisitionFunctionError(IncompatibilityError):"""An incompatible acquisition function was selected."""
[docs]classIncompatibleExplainerError(IncompatibilityError):"""An explainer is incompatible with the data it is presented."""
[docs]classIncompatibleArgumentError(IncompatibilityError):"""An incompatible argument was passed to a callable."""
[docs]classInfeasibilityError(Exception):"""An optimization problem has no feasible solution."""
[docs]classNotEnoughPointsLeftError(Exception):""" More recommendations are requested than there are viable parameter configurations left in the search space. """
[docs]classNoMCAcquisitionFunctionError(Exception):""" A Monte Carlo acquisition function is required but an analytical acquisition function has been selected by the user. """
[docs]classEmptySearchSpaceError(Exception):"""The created search space contains no parameters."""
[docs]classNoMeasurementsError(Exception):"""A context expected measurements but none were available."""
[docs]classIncompleteMeasurementsError(Exception):"""A context expected complete measurements but none were available."""
[docs]classNothingToSimulateError(Exception):"""There is nothing to simulate because there are no testable configurations."""
[docs]classNoRecommendersLeftError(Exception):"""A recommender is requested by a meta recommender but there are no recommenders left. """
[docs]classNumericalUnderflowError(Exception):"""A computation would lead to numerical underflow."""
[docs]classOptionalImportError(ImportError):"""An attempt was made to import an optional but uninstalled dependency."""
[docs]def__init__(self,*args:Any,name:str|None=None,path:str|None=None,group:str|None=None,):super().__init__(*args,name=name,path=path)# If no message has been explicitly set, create it from the contextifself.msgisNoneandnameisnotNone:group_str=f"`pip install 'baybe[{group}]'` or "ifgroupelse""self.msg=(f"The requested functionality requires the optional "f"'{self.name}' package, which is currently not installed. "f"Please install the dependency and try again. "f"You can do so manually (e.g. `pip install {self.name}`) "f"or using an appropriate optional dependency group "f"(e.g. {group_str}`pip install 'baybe[extras]'`).")
[docs]classDeprecationError(Exception):"""Signals the use of a deprecated mechanism to the user, interrupting execution."""
[docs]classUnidentifiedSubclassError(Exception):"""A specified subclass cannot be found in the given class hierarchy."""
[docs]classModelNotTrainedError(Exception):"""A prediction/transformation is attempted before the model has been trained."""
[docs]classUnmatchedAttributeError(Exception):"""An attribute cannot be matched against a certain callable signature."""
[docs]classInvalidSurrogateModelError(Exception):"""An invalid surrogate model was chosen."""
[docs]classInvalidTargetValueError(Exception):"""A target value was entered that is not in the target space."""