-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathproblem.py
More file actions
95 lines (59 loc) · 2.75 KB
/
Copy pathproblem.py
File metadata and controls
95 lines (59 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""Exceptions related with problem definition.
"""
from deephyper.core.exceptions import DeephyperError
class SpaceDimNameOfWrongType(DeephyperError):
"""Raised when a dimension name of the space is not a string."""
def __init__(self, value):
self.value = value
def __str__(self):
return f"Dimension name: '{self.value}' is of type == {type(self.value)} when should be 'str'!"
# ! NaProblemErrors
class NaProblemError(DeephyperError):
"""Raise when an error occurs in a NaProblem instance."""
def __init__(self, msg: str):
self.msg = msg
def __str__(self):
return self.msg
class SearchSpaceBuilderIsNotCallable(NaProblemError):
"""Raised when a search space builder is not a callable."""
def __init__(self, parameter):
self.parameter = parameter
def __str__(self):
raise f"The search space builder {self.parameter} should be a callable when it is not!"
class SearchSpaceBuilderMissingParameter(NaProblemError):
"""Raised when a missing parameter is detected in a callable which creates a Structure.
Args:
missing_parameter (str): name of the missing parameter.
"""
def __init__(self, missing_parameter):
self.missing_parameter = missing_parameter
def __str__(self):
return f"The callable which creates a Structure is missing a '{self.missing_parameter}' parameter!"
class SearchSpaceBuilderMissingDefaultParameter(NaProblemError):
"""Raised when a parameter of a search space builder is missing a default value."""
def __init__(self, parameter):
self.parameter = parameter
def __str__(self):
return f"The parameter {self.parameter} must have a default value!"
class ProblemPreprocessingIsNotCallable(NaProblemError):
"""Raised when the preprocessing parameter is not callable."""
def __init__(self, parameter):
self.parameter = parameter
def __str__(self):
return f"The parameter {self.parameter} must be a callable."
class ProblemLoadDataIsNotCallable(NaProblemError):
"""Raised when the load_data parameter is not callable."""
def __init__(self, parameter):
self.parameter = parameter
def __str__(self):
return f"The parameter {self.parameter} must be a callable."
class WrongProblemObjective(NaProblemError):
"""Raised when the objective parameter is neither a callable nor a string."""
def __init__(self, objective, possible_names=None):
self.objective = objective
self.possible_names = possible_names
def __str__(self):
output = f"The objective: {str(self.objective)} is not valid."
if self.possible_names is not None:
output += f" Possible objectives are: {self.possible_names}"
return output