-
Notifications
You must be signed in to change notification settings - Fork 96
Typecheck forbidden p3 #16
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
mfeurer
left a comment
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 added some minor comments. Could you please work on them and also fix the conflict to the master branch?
ConfigSpace/forbidden.py
Outdated
| class AbstractForbiddenComponent(object): | ||
| __metaclass__ = ABCMeta | ||
|
|
||
| # todo : should absract methods be annotated with types? |
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.
From my point of view, this is not necessary here. Did mypy complain? If yes, we have to do something about it. Else, please remove the comment. The other abstract methods which should return something should be annotated though.
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.
no mypy didnt complain...removed this todo
ConfigSpace/forbidden.py
Outdated
|
|
||
| class AbstractForbiddenClause(AbstractForbiddenComponent): | ||
| def get_descendant_literal_clauses(self): | ||
| def get_descendant_literal_clauses(self) -> List['AbstractForbiddenClause']: |
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.
Wouldn't AbstractForbiddenComponent be more appropriate her? Also, why is this a string? Moreover, the definition further below suggests that this function return List[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.
changed.
also its different class so no need to declare it as str.
why string? http://stackoverflow.com/questions/33533148/how-do-i-specify-that-the-return-type-of-a-method-is-the-same-as-the-class-itsel
ConfigSpace/forbidden.py
Outdated
|
|
||
| class SingleValueForbiddenClause(AbstractForbiddenClause): | ||
| def __init__(self, hyperparameter, value): | ||
| # todo: possible types of hyperparameter valuees? |
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'm afraid we need to accept Any here. Please remove the comment.
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.
removed
ConfigSpace/forbidden.py
Outdated
| self.value = value | ||
|
|
||
| def is_forbidden(self, instantiated_hyperparameters, strict=True): | ||
| def is_forbidden(self, instantiated_hyperparameters: Hyperparameter, strict: bool=True) -> bool: |
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.
Please check the code by running it, but I think that instantiated_hyperparameters is a dict. Please also annotate _is_forbidden.
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 the type of instantiated_hyperparameters to Dict[str, Union[None, str, float, int]] .
all versions of _is_forbidden are annotated except abstract methods
ConfigSpace/forbidden.py
Outdated
|
|
||
| class MultipleValueForbiddenClause(AbstractForbiddenClause): | ||
| def __init__(self, hyperparameter, values): | ||
| # todo: type of vals of hp |
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.
Same as above.
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.
done
| class MultipleValueForbiddenClause(AbstractForbiddenClause): | ||
| def __init__(self, hyperparameter, values): | ||
| # todo: type of vals of hp | ||
| def __init__(self, hyperparameter: Hyperparameter, values: Any) -> None: |
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.
Same as above.
ConfigSpace/forbidden.py
Outdated
| pass | ||
|
|
||
| def get_descendant_literal_clauses(self): | ||
| def get_descendant_literal_clauses(self) -> List[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.
Please update this based on the comment above.
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.
mypy fails if set to AbstractForbiddenComponent or AbstractForbiddenConjunction at following lines:
dlcs = self.get_descendant_literal_clauses()
for dlc in dlcs:
if dlc.hyperparameter.name not in ihp_names:
ConfigSpace/forbidden.py
Outdated
| return children | ||
|
|
||
| def is_forbidden(self, instantiated_hyperparameters, strict=True): | ||
| def is_forbidden(self, instantiated_hyperparameters: Hyperparameter, strict: bool=True) -> bool: |
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.
Same as above.
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.
done
ConfigSpace/forbidden.py
Outdated
| for component in self.components: | ||
| e = component.is_forbidden(instantiated_hyperparameters, | ||
| strict=strict) | ||
| e = component.is_forbidden(instantiated_hyperparameters) |
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.
type of strict is bool so its value should be 'true' or 'false' and not 'strict'
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.
Yes, but strict is a boolean variable that is passed to is_forbidden in line 195; so it won't change till down here.
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
…ypecheck_forbidden_p3 # Conflicts: # ConfigSpace/hyperparameters.py
mfeurer
left a comment
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.
Two more things to do, then we can merge this.
ConfigSpace/forbidden.py
Outdated
| pass | ||
|
|
||
| def get_descendant_literal_clauses(self): | ||
| # todo: recheck is return type should be AbstractForbiddenComponent or AbstractForbiddenConjunction 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.
Could you please check this with the debugger?
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.
mypy accepts only List[hyperparameter] but according to debugger AbstractForbiddenComponent should also work
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 do you mean by also? Can both happen?
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.
from output of debugger it seems that the object of type forbidden has hyperparameter as its keys
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 by adding hyperparameter attribute to AbstractForbiddenComponent
ConfigSpace/forbidden.py
Outdated
| for component in self.components: | ||
| e = component.is_forbidden(instantiated_hyperparameters, | ||
| strict=strict) | ||
| e = component.is_forbidden(instantiated_hyperparameters) |
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.
Yes, but strict is a boolean variable that is passed to is_forbidden in line 195; so it won't change till down here.
…ypecheck_hyperparameter_p3 # Conflicts: # ConfigSpace/hyperparameters.py
No description provided.