-
Notifications
You must be signed in to change notification settings - Fork 96
Typecheck configuration p3 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ypecheck_configuration_p3 # Conflicts: # ConfigSpace/hyperparameters.py
…ypecheck_configuration_p3 # Conflicts: # ConfigSpace/hyperparameters.py
ConfigSpace/configuration_space.py
Outdated
| # no guarantee that the parent of a condition was evaluated before | ||
| self._conditionsals = OrderedDict() | ||
| self.forbidden_clauses = [] | ||
| self._conditionsals = OrderedDict() # type: OrderedDict[str, str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 169 suggests that this maps for str to Condition or Hyperparameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 169 is
self._conditionsals[child_node] = child_node
from here it appears that key and value are equal. debugger also says the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, let's discuss this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it a set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still open, right?
| return hyperparameter | ||
|
|
||
| def add_condition(self, condition): | ||
| def add_condition(self, condition: ConditionComponent) -> ConditionComponent: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this accept and return an abstract condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first line of this function raises error if input is not of type conditioncomponent
if not isinstance(condition, ConditionComponent):
raise TypeError("The method add_condition must be called "
"with an instance of "
"HPOlibConfigSpace.condition.ConditionComponent.")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type changed to abstractcondition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, ConditionComponent is a parent class of AbstractCondition; accepting and returning a ConditionComponent is totally correct.
ConfigSpace/configuration_space.py
Outdated
| to_visit.appendleft(current) | ||
|
|
||
| by_level = defaultdict(list) | ||
| by_level = defaultdict(list) # type: Dict['int', List[str]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not #type: defaultdict[int, List[str]]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
ConfigSpace/configuration_space.py
Outdated
|
|
||
| def add_configuration_space(self, prefix, configuration_space, | ||
| delimiter=":", parent_hyperparameter=None): | ||
| def add_configuration_space(self, prefix: str, configuration_space: ConfigSpace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should accept and return ConfigurationSpace, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| def get_child_conditions_of(self, name: Union[str, Hyperparameter]) -> List[AbstractCondition]: | ||
| if isinstance(name, Hyperparameter): | ||
| name = name.name | ||
| name = name.name # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about # type: str?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought so too but mypy gives following error which doesnt make any sense
configuration_space.py:413: error: Some element of union has no attribute "name"
ConfigSpace/configuration_space.py
Outdated
| self._num_hyperparameters = len(self.configuration_space._hyperparameters) | ||
| self.origin = origin | ||
| self._keys = None | ||
| self._keys = None # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to Union[None, List[str]]
ConfigSpace/configuration_space.py
Outdated
| # hyperparameters in the configuration are sorted in the same way as | ||
| # they are sorted in the configuration space | ||
| self._values = dict() | ||
| self._values = dict() # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
ConfigSpace/configuration_space.py
Outdated
| return self._values[item] | ||
|
|
||
| def get(self, item, default=None): | ||
| # todo: find return type of get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is correct.
ConfigSpace/configuration_space.py
Outdated
| return default | ||
|
|
||
| def __contains__(self, item): | ||
| # todo: recheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be bool I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type changed to bool
ConfigSpace/configuration_space.py
Outdated
|
|
||
| def get_dictionary(self): | ||
| # todo: recheck | ||
| def get_dictionary(self) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns a dictionary ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to Dict[str, Union[str, float, int]]
|
Could you please also make the sorting in line 648 deterministic to prevent stochastic failure of unit tests? |
ConfigSpace/configuration_space.py
Outdated
| return hyperparameter | ||
|
|
||
| def add_condition(self, condition: ConditionComponent) -> ConditionComponent: | ||
| def add_condition(self, condition: ConditionComponent) -> AbstractCondition: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was correct before, please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
|
Please also remove all TODOs that you added regarding types; together with the two changes to go, this will be ready to merge. |
No description provided.