-
Notifications
You must be signed in to change notification settings - Fork 332
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
Feature: restructure Parameter and Metadata and create non-saved input-fields #1036
base: master
Are you sure you want to change the base?
Feature: restructure Parameter and Metadata and create non-saved input-fields #1036
Conversation
534ac72
to
445fec0
Compare
3a3e955
to
aebb0d9
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1036 +/- ##
==========================================
+ Coverage 58.26% 58.32% +0.05%
==========================================
Files 258 258
Lines 17874 17901 +27
==========================================
+ Hits 10414 10440 +26
- Misses 7460 7461 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
aebb0d9
to
bff6fb1
Compare
@BenediktBurger, @bilderbuchi, and/or @msmttchr: what do you think of a structure like what I proposed here? I'm not sure now what I think of having all these classes (a lot of which are just inheritances without any changes, just to be able to 'dispatch' on the class-type). Maybe it's fine like this, but am not sure yet, so I'm curious what you think of this structure and, if you don't like it, if you have any other/better suggestions? |
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.
A few comments (mainly regarding documentation typos).
I see the introduction of many very similar classes, just different in type.
Another idea: what about a "type" parameter for the Input Field?
Valid arguments could be native types (float, int...) or an enum member (especially for those additional types).
So it would be steps = InputField(type=int)
(or Parameter or Metadata instead of InputField) or type=Types.INT
using an enum.
That is easy, but reduces the number of classes drastically.
:var value: The value of the parameter | ||
:class:`.InputField` serves as a parent-class to :class:`.Parameter` and :class:`.Metadata` (and | ||
their respective subclasses). These classes differ in whether (and if yes, when) their value is | ||
writen to the data-file, and whether the value is applied when getting parameters from a file. |
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.
writen to the data-file, and whether the value is applied when getting parameters from a file. | |
written to the data-file, and whether the value is applied when getting parameters from a file. |
the name of the fields to be documented or a tuple with (helps_string, | ||
field) | ||
- index 2: type | ||
""" | ||
return (self.default, self._help_fields, self.convert) | ||
|
||
def is_set(self): | ||
""" Returns True if the Parameter value is set | ||
""" Returns True if the InputField value is 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.
""" Returns True if the InputField value is set | |
""" Return True if the InputField value is set |
|
||
:var value: The value of the parameter | ||
The data dat is stored in a parameter is written to the parameters section of the data file |
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 data dat is stored in a parameter is written to the parameters section of the data file | |
The data that is stored in a parameter is written to the parameters section of the data file |
""" Encapsulates the information for metadata of the experiment with | ||
information about the name, the fget function and the units, if supplied. | ||
If no fget function is specified, the value property will return the | ||
latest set value of the parameter (or default if never set). | ||
Subclass of :class:`.InputField` |
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.
Is it necessary to state the parent class?
In the api documentation you can toggle "show_inheritance" to show that information.
That makes the actual inheritance the single point of truth.
|
||
|
||
class IntegerMetadata(Metadata, IntegerInputField): | ||
pass |
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 do you have lengthy docstrings for the parameters, but not for the Metadata?
Naive, I would not add docstrings to either one.
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 simply did not get around to doing that. I was not yet completely finished with this, but mainly wondered about the structure with all the classes.
I would be inclined to add docstrings since the classes are handled differently, so I think, for clarity, it would be good to mention their purpose and how they are handled in the docstrings.
I chose the classes approach for symmetry to the existing set of Parameter classes (IntParameter, FloatParameter and such). Hmmm, that is maybe cleaner. However, I do not want to break backwards compatibility, so I'm not sure if we want to remove the parameter classes. An option would be to rewrite it with the types as you suggest, and add the set of Parameter classes for backwards compatibility? |
Reading the email, I wanted to suggest exactly that, just to note, that you added it yourself 😁 |
Mainly as a note to myself (though feel free to criticize) One challenge I saw with having a single parameter class was the fact that all the different subclasses now have custom A solution might be composition: have a Parameter class, which is effectively a type agnostic container, but holds a Value class that serves the different types. The If going this way, I'm also inclined to not make I am starting to wonder now if this is not an overly complicated solution for something simple... Maybe the original proposal #1013 is cleaner after all...??? |
Composition over inheritance is often recommended in principle, so the sketched approach sounds reasonable to me. 👍 I can't judge the relative merits of the other proposal, I've never been deeply immersed in that part of the codebase. |
I like that solution in favor of complicated methods.
Sounds good.
The final decision on the approach you have to do yourself, maybe with @msmttchr, as neither I am an expert in that part of the codebase |
A suggested implemented for #1014 (and PR #1013).