-
Notifications
You must be signed in to change notification settings - Fork 192
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
Set the properties of KpointsData
class in the constructor.
#5942
Set the properties of KpointsData
class in the constructor.
#5942
Conversation
@unkcpz Would you be able to review 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.
@AhmedBasem20, thanks for your contribution. This class is more complex than it looks like, can you look at the https://github.com/aiidateam/aiida-quantumespresso/blob/01e759319552645072b7a89dd0347225ab14d635/src/aiida_quantumespresso/calculations/functions/create_kpoints_from_distance.py#L7, an implementation of how we use it in production use case and come back to the PR.
The new change however not address the original issue #3287. |
69096ee
to
31cdb8d
Compare
Hi @unkcpz I'm sorry for the delay. I modified the |
Hi both, and thanks a lot @AhmedBasem20 for the contribution! The Since I just did quite a rant on data types and their constructors in the discussions, I also wanted to join in here for the review. Let me begin with the most important points from that discussion, adapted for this PR:
And adapt point 4. from the TL;DR 1 of that discussion's OP:
So to respond to Jusong's comments:
I'm 💯% on board when it comes to creating a
Your comment immediately highlights one of the reasons I'm against adding superfluous input arguments to a constructor's signature: you have to somehow deal with all the cases, and often it's not entirely clear how to set precedence. Let's avoid that "complex logic" and simply add Minimal but complete inputsNow how can we define the set of minimal and complete inputs for
I think it's already clear what I'm going to say here:
Looking at these I'm getting more and more convinced we should have two separate classes, but I will stop my moaning. @unkcpz what do you think? Since we still have to deal with both kpoints "list" and "mesh" being the same class, we should add some validatation. From the three groups above, the first needs to be set for both "list' and "mesh", the second should only be set for "mesh" and the third only for "list". Not to beat a dead horse, but this validation again reaffirms my belief that we should separate the two concepts in different classes. I'm frankly confused myself: do we also want an ConclusionIn short, in this PR I think we should:
I also think we should add type hinting, but I'm happy to do that in a separate PR. Sorry for the long read, let me know if you have any questions, objections, suggestions! Footnotes
|
Hi @mbercx, thanks a lot for the detailed explanation and suggestions. I don't really get why we should keep the |
for more information, see https://pre-commit.ci
@mbercx Thanks a lot for the long reading comment, very helpful!
What do you mean by validation? I think for the class it self the type hint should be enough for developers. For users, maybe validate on is the mesh and offset is a three elements list/tuple? |
@AhmedBasem20 good point, I think this is why @mbercx suggest combining the empty constructor call with |
@unkcpz I'm sorry, I don't seem to get it. shouldn't the I'm struggling a bit with this PR. I got from you and @mbercx 's detailed review that:
I attempt to apply what @mbercx proposed in my last commit but it seems that I made some mistakes. So I think a thorough code review would be helpful. |
Thanks for all the work you have done so far. I agree with @mbercx that the real problem here is the fact that a single class is serving two different purposes. But we cannot and should not change that here and now. This should be left for v3.0 since it will be backwards incompatible. This is being tracked in #2686 and aiidateam/team-compass#21 That being said, I think we can move forward with the changes proposed in this PR if the following conditions are met:
I think 1 is pretty clearly satisfied and I think so is 2, since only classmethods are added. The constructor being overridden should also be fine. That leaves 3. The only potential problem that I can see is that we are now adding new methods, that will have to be deprecated and changed in the future. Are these new methods really necessary? Would the improved constructor not be sufficient for most cases?
I think we should maybe keep this PR to the minimum scope of the original issue and just allow complete initialization through the constructor. As it stands, the current constructor in this PR is not complete I think. There are two varieties that should be constructable:
Both cases require the
So maybe a better constructor would be: def __init__(
self,
cell: list[int | float],
pbc: list[bool] | bool = True,
mesh: list[int | float] | None = None,
offset: list[int] | None = None,
kpoints: list[list[int | float]] = None,
cartesian: bool | None = None,
labels: list[str] | None = None,
weights: list[int | float] | None = None,
fill_values: int | None = None
):
if mesh is None and kpoints is None:
raise ValueError('either `mesh` or `kpoints` should be specified.')
blocked_args_kpoints = ('offset',)
if kpoints is not None and and any(arg is not None for arg in blocked_args_kpoints):
raise ValueError(
f'following arguments cannot be specified when `kpoints` is defined: {", ".join(blocked_args_kpoints)}.'
)
blocked_args_mesh = ('cartesian', 'labels', 'weights', 'fill_values')
if mesh is not None and any(arg is not None for arg in blocked_args_mesh):
raise ValueError(
f'following arguments cannot be specified when `mesh` is defined: {", ".join(blocked_args_mesh)}.'
) I think that would be all the validation that would be necessary. The defaults of the arguments besides @AhmedBasem20 I suggest you don't change the code now, but we first discuss and agree on what we want. Only once we have made a decision, should we continue implementing or you might end up doing work for nothing going back and forth. |
Thanks for the comments, @sphuber! Going back through my own comment above, it seems I was indeed tripped up a bit by the design of the Although I still believe the At first glance the constructor and validation you propose seems good. 👍 We should of course also still add a clear but as-succinct-as-possible docstring, as well as adapt/extend the documentation of @AhmedBasem20 apologies for complicating the merging of this PR, but I did say it was a bold choice to tackle |
@mbercx No worries, you're right it seems like it is not a very good first issue xD |
Shall we close this PR for the time being then? @mbercx do we have a design document where we can summarize discussions like this? This will be important for the planning of the redesign and don't want to loose the insights from this thread. |
I agree to close the PR for the moment, @AhmedBasem20 is focusing more on the GSoC project which has high priority. I discussed this with him yesterday and we want to set a discussion and pair coding to come back to this PR when he got spare time from GSoC.
Maybe discourse is a good place to put all such things together when we have one 😉 |
Ah, I thought I was clear that I think adapting the constructor is still a valuable contribution? Not sure why we wouldn't just go ahead with this now?
Not sure I agree with that, but that's a discussion for another day. ^^ It does remind me I still have to start that free trial! 🚀 |
Fixes #3287