-
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
Add default_memory_per_machine attribute to Computer. #5260
Add default_memory_per_machine attribute to Computer. #5260
Conversation
1f4af8d
to
c8e40ca
Compare
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.
We should normalise this to make sure that memory units are always treated as integers (currently there is a mix of float and int).
There is one outstanding question of whether to use MB or kB. Currently the code uses kB for the job options while here we are suggesting using MB. I don't think the loss of granularity is a problem, but the lack of consistency may be confusing. Any thoughts @sphuber ?
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.
Thanks @yakutovicha , I have given a first pass. Main thing is that I think mixing kB and MB is going to be confusing, both for the user and in the code.
Codecov Report
@@ Coverage Diff @@
## develop #5260 +/- ##
===========================================
+ Coverage 81.45% 81.46% +0.02%
===========================================
Files 530 530
Lines 37116 37139 +23
===========================================
+ Hits 30229 30253 +24
+ Misses 6887 6886 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
efb7fed
to
bc4ffe2
Compare
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.
Thanks @yakutovicha . Still are some remaining things to be fixed, but then this should be good to go.
aiida/orm/computers.py
Outdated
@@ -264,6 +264,20 @@ def _default_mpiprocs_per_machine_validator(cls, def_cpus_per_machine: Optional[ | |||
'do not want to provide a default value.' | |||
) | |||
|
|||
@classmethod | |||
def _default_memory_per_machine_validator(cls, def_memory_per_machine: Optional[int]) -> 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.
Don't think you are actually using this. Did you forget to add this to Computer.validate
?
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 comment still stands correct? This is not being called in the current code.
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 it was correct, but now I call it in set_default_memory_per_machine
as you suggest below. I also renamed it to default_memory_per_machine_validator
as, presumably, it will be called outside of the class. In case we want to do the validation elsewhere.
aiida/orm/computers.py
Outdated
""" | ||
if def_memory_per_machine is None: | ||
self.delete_property('default_memory_per_machine', raise_exception=False) | ||
elif not isinstance(def_memory_per_machine, int): |
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.
Instead of doing the validation here again, just call _default_memory_per_machine_validator
. This way you don't run the risk that the validation is inconsistent in different places (as is the case now: here you don't check that the int is positive non-zero). If you want to keep the TypeError
in case it is not a valid positive integer (which I agree is better than ValidationError
) you simply catch the ValidationError
and reraise as TypeError
.
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 it would be good to do the validation directly here. The same goes for the other set_
methods. See suggestion #5257.
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, I am not saying to not do the validation here, I am just saying to put the validation in one place (let's say a separate method) and have this method and the validate
method both call that validation. But then we are sure it is consistent
07f8e58
to
30a6b89
Compare
@yakutovicha I resolved the majority of outstanding conversations except one: the validation method is not called anywhere. Finally, I added three minor new comments: two small fixes to help strings/error messages and a test that should be removed. |
@yakutovicha there are still some outstanding things that weren't addressed. For your convenience, I created a commit on top of your branch and pushed it to my fork: sphuber@214cb24 If you agree with the changes, you can simply cherry-pick it and push it to your branch, and then after we update it, I will approve and merge. |
- The value is in kB. - `max_memory_kb option has the same effect, but is a higher priority.
for more information, see https://pre-commit.ci
Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
- Call `default_memory_per_machine_validator` in `Computer.validate` - Do not handle `0` in the `ComputerBuilder` - Correct `run_cli_command` usage.
13f8fd3
to
a38d025
Compare
fixes #4297
max_memory_kb
option has the same effect but is a higher priority