-
Notifications
You must be signed in to change notification settings - Fork 129
Make use of ABC abstract class in unsequa module #1054
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
base: develop
Are you sure you want to change the base?
Conversation
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 does this PR achieve that was not possible before? The new abstract methods do not serve any purpose if they do not define an interface (through parameters). But defining an interface also means that derived methods must use the same parameters. The current structure of the unsequa module already violates this, and Jenkins complains, rightfully so. See https://pylint.pycqa.org/en/latest/user_guide/messages/warning/arguments-differ.html:
argument-differ denotes an issue with the Liskov Substitution Principle.
So, if you want derived classes to change the interface, you don't need an interface in the first place. On the other hand, we could make an effort here to define a proper interface for the unsequa base classes that conforms to all derived use cases.
@peanutfun Thanks for the feedback! I think the idea here was not to add a functionality, but to make use of abstract classes as it considers as "best practice"? But yes in theory you can implement other subclasses in the unsequa module without the use of an abstract class, as it has been done before for e.g. |
@@ -107,16 +108,20 @@ class UncOutput: | |||
"sensitivity_kwargs", | |||
] | |||
|
|||
# @abstractmethod |
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.
making __init__
abstract looks beyond the target to me. Is there a use case?
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 agree. You usually call inits of base classes from derived classes instead of overriding them.
"""Compute the uncertainty of the output values""" | ||
pass | ||
|
||
@abstractmethod |
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.
private and abstract seems somehow contradicting. if we go for it, compute_metrics
ought to be public.
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 disagree. An abstract method just means that "this implementation is to be defined in a derived class". Depending on the semantics of the class, the method in question may very well be private.
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.
@peanutfun Technically speaking, you're absolutely right. In this particular case I still think compute_metrics
ought to be public.
I kind of agree with Lukas. Up to this point the abstraction is not justified yet (and not yet according to all rules). |
@emanuel-schmid and @peanutfun I am not sure what you want to happen here. I think adding the abstract structure would make it much simpler for future developers to add functionalities, in the same way as @luseverin is currently doing. But happy to be corrected. |
@luseverin : small point, but it seems that some modification of the tutorial happened that might not have been intended (2,182 additions, 478 deletions) |
@chahank Please refer to my earlier comment: #1054 (review). The only way to make things simpler is to define a proper interface in the base class(es). But this is neither done here nor was it done originally. |
Thanks, but this does not answer the question: what do you want to happen here? I think the current comments do not allow @luseverin to either improve, or close this PR. Not sure what is best: put in the effort to make it into a proper abstract structure, or just close this. |
Sorry for not being clear. In order to continue with this PR, I would want
|
Changes proposed in this PR:
-Make use of ABC abstract class in the unsequa module
I updated the
unsequa
module so that it uses the abstract (ABC) class concept. The idea is to be able to readily adapt the unsequa module to other use cases, using the related abstract class. In my case I wanted to have unsequa work with the network module from petals. I splitted this task in two where 1) the unsequa module is made abstract (this PR); 2) the adaptation of the unsequa module to the network module use case is implemented (in branch feature/unsequa_cascade_abstract, work in progress).As @emanuel-schmid and @chahank nicely designed the unsequa module so that it is already quite abstract in the first place, this did not require too much work. However, I was not sure of whether the
__init__
of theUncOutput
class should be made abstract or not, as making it abstract is preventing__init__
to be used by subclasses usingsuper()
..PR Author Checklist
develop
)PR Reviewer Checklist