-
Notifications
You must be signed in to change notification settings - Fork 78
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
PwBaseWorkChain
: fix bug in validate_resources
validator
#683
Conversation
Thanks @sphuber, will review later, but just wanted to mention that I recognise the issue with the failing test: self = frozendict({'q2r': {'code': <Code: Remote code 'test.quantumespresso.q2r' on localhost-test, pk: 170, uuid: 96e8b36c-9...ored)>, 'metadata': {'options': {'resources': {'num_machines': 1}, 'max_wallclock_seconds': 1800, 'withmpi': False}}}})
args = ('_initialised', True), kwargs = {}
def _immutable(self, *args, **kwargs):
r"""
Function for not implemented method since the object is immutable
"""
> raise AttributeError(f"'{self.__class__.__name__}' object is read-only")
E AttributeError: 'AttributesFrozendict' object is read-only This issue was also raised by @asle85 on slack. She noticed that her |
The problem is that for Python 3.6, However, in So now that |
All clear now capt'n! @mbercx |
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 @sphuber! Gave the PR a pass and left some comments.
Now that we are touching this piece of the code, I'm wondering if in this PR we should perhaps also fix the fact that in case the user sets max_seconds
in the input parameters, this is silently ignored by both PwBaseWorkChain
and PhBaseWorkChain
, since:
aiida-quantumespresso/aiida_quantumespresso/workflows/pw/base.py
Lines 295 to 302 in 33cb11e
def set_max_seconds(self, max_wallclock_seconds): | |
"""Set the `max_seconds` to a fraction of `max_wallclock_seconds` option to prevent out-of-walltime problems. | |
:param max_wallclock_seconds: the maximum wallclock time that will be set in the scheduler settings. | |
""" | |
max_seconds_factor = self.defaults.delta_factor_max_seconds | |
max_seconds = max_wallclock_seconds * max_seconds_factor | |
self.ctx.inputs.parameters['CONTROL']['max_seconds'] = max_seconds |
Wouldn't it be better to only set max_seconds
based on delta_factor_max_seconds
in case the user hasn't specified max_seconds
in the input parameters, i.e. only call the set_max_seconds
method if 'max_seconds' not in self.ctx.inputs.parameters['CONTROL']
?
While browsing through the issues, I also found #528. Does this PR fix that one as well? |
The original issue should have been fixed indirectly by newer |
b669ed2
to
ec6b189
Compare
@mbercx thanks for the review. Have addressed everything except the question of |
You could add extra validation, but perhaps this isn't necessary. If the user specifies both It's strange that the |
Of course I could, but that was exactly the question: how do we want the validation to behave. Maybe we indeed just say that we only set
It probably isn't required on the |
ec6b189
to
9b8144b
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.
It's a good thing at least one of us test runs your implementations. 😏
That's the thing, you are so diligent at double-checking my shitty code, that it is making me even more sloppy. So really this is all your fault |
Haha, that comment turned my remark around on me so fast it gave me whiplash. 😅 |
9b8144b
to
0059c8c
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.
I do love me some extra testing, thanks @sphuber! Just some typos to fix and a question if we can't simplify the fixtures. Merge at your discretion!
|
||
def test_set_max_seconds(generate_workchain_ph): | ||
"""Test that `max_seconds` get sets in the parameters based on `max_wallclock_seconds` unless already set.""" | ||
inputs = generate_workchain_ph(return_inputs=True) |
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 not generate the inputs with the generate_inputs_ph
fixture instead of adding the return_inputs
input to the generate_workchain_ph
fixture and then calling it twice, once to get the inputs and once to actually get the work chain?
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.
Problem described for the comment on pw
is less pronounced for ph
but I want to keep it consistent and the input definition for the PhBasWorkChain
may become more complicated in the future
|
||
def test_set_max_seconds(generate_workchain_pw): | ||
"""Test that `max_seconds` get sets in the parameters based on `max_wallclock_seconds` unless already set.""" | ||
inputs = generate_workchain_pw(return_inputs=True) |
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 comment as for the ph.x
test.
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.
because the generate_inputs_pw
does not return all the minimally required inputs needed for the workchain. If you look at generate_workchain_pw
it needs to add the inputs to a namespace, and pop an input. I don't want to have to add these lines in every test.
tests/workflows/ph/test_base.py
Outdated
|
||
|
||
def test_set_max_seconds(generate_workchain_ph): | ||
"""Test that `max_seconds` get sets in the parameters based on `max_wallclock_seconds` unless already 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.
"""Test that `max_seconds` get sets in the parameters based on `max_wallclock_seconds` unless already set.""" | |
"""Test that `max_seconds` gets set in the parameters based on `max_wallclock_seconds` unless already set.""" |
tests/workflows/pw/test_base.py
Outdated
|
||
|
||
def test_set_max_seconds(generate_workchain_pw): | ||
"""Test that `max_seconds` get sets in the parameters based on `max_wallclock_seconds` unless already 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.
"""Test that `max_seconds` get sets in the parameters based on `max_wallclock_seconds` unless already set.""" | |
"""Test that `max_seconds` gets set in the parameters based on `max_wallclock_seconds` unless already set.""" |
The `validate_resources` outline step would check that the `metadata.options` namespace included at least the input `resources.num_machines` and `max_wallclock_seconds` as long as the automatic parallelization feature was not enabled. This was added when the workchain was first developed, because the scheduler resources were not validated on the base `CalcJob` in `aiida-core`. However, since `aiida-core==1.0.0` the scheduler resources are validated on the `CalcJob` base class. This means that a `PwBaseWorkChain` will now not even be instantiated if the resources for the `PwCalculation` are insufficient, so it is better to leave the validation up to the base class. What is worse, the logic in `validate_resources` is actually incorrect as it assumed that the resources always need to include `num_machines`. However, this is not the case as it is actually `Scheduler` implementation specific, and for example for the `SgeScheduler` this field is even prohibited and will raise when specified. This made that the `PwBaseWorkChain` was fundamentally incompatible with those schedulers before this fix. The `PhBaseWorkChain` suffered from the same bug and has also been fixed.
0059c8c
to
e1b6489
Compare
Fixes #682
The
validate_resources
outline step would check that themetadata.options
namespace included at least the inputresources.num_machines
andmax_wallclock_seconds
as long as theautomatic parallelization feature was not enabled. This was added when
the workchain was first developed, because the scheduler resources were
not validated on the base
CalcJob
inaiida-core
.However, since
aiida-core==1.0.0
the scheduler resources are validatedon the
CalcJob
base class. This means that aPwBaseWorkChain
willnow not even be instantiated if the resources for the
PwCalculation
are insufficient, so it is better to leave the validation up to the base
class.
What is worse, the logic in
validate_resources
is actually incorrectas it assumed that the resources always need to include
num_machines
.However, this is not the case as it is actually
Scheduler
implementation specific, and for example for the
SgeScheduler
thisfield is even prohibited and will raise when specified. This made that
the
PwBaseWorkChain
was fundamentally incompatible with thoseschedulers before this fix.
The
PhBaseWorkChain
suffered from the same bug and has also beenfixed.