Skip to content
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

RecommendedCutoffMixin: set only one stringency with set_cutoffs #72

Merged
merged 6 commits into from
Apr 13, 2021

Conversation

mbercx
Copy link
Member

@mbercx mbercx commented Apr 12, 2021

Fixes #68

Currently the behaviour of the set_cutoffs and get_cutoffs methods of the
RecommendedCutoffMixin class is different. The first sets the cutoffs for all
stringencies along with a default stringency, the second only retrieves the
cutoffs for a specified stringency. This can be somewhat confusing for the
user, and means that the user cannot easily set the cutoffs for a single
stringency.

Here we change the set_cutoffs method so it only sets the recommended
cutoffs for a single stringency, which has to be specified as an input
argument. The stringency is automatically set to be the default in case
it is the only stringency specified, and a set_default_stringency
method is added to the user can still change the default stringency at
any time after setting multiple stringencies.

We also allow the user to specify units for each stringency, extending
the value corresponding to the _key_cutoffs_unit in the extras to a
dictionary that specifies the units for each stringency, similar to the
cutoffs.

Currently the behaviour of the `set_cutoffs` and `get_cutoffs` methods of the
`RecommendedCutoffMixin` class is different. The first sets the cutoffs for all
stringencies along with a default stringency, the second only retrieves the
cutoffs for a specified stringency. This can be somewhat confusing for the
user, and means that the user cannot easily set the cutoffs for a single
stringency.

Here we change the `set_cutoffs` method so it only sets the recommended
cutoffs for a single stringency, which has to be specified as an input
argument. The stringency is automatically set to be the default in case
it is the first stringency specified, and a `set_default_stringency`
method is added to the user can still change the default stringency at
any time after setting multiple stringencies.

We also allow the user to specify units for each stringency, extending
the value corresponding to the `_key_cutoffs_unit` in the extras to a
dictionary that specifies the units for each stringency, similar to the
cutoffs.
@mbercx mbercx added this to the v0.6.0 milestone Apr 12, 2021
@mbercx mbercx requested a review from sphuber April 12, 2021 11:24
@mbercx
Copy link
Member Author

mbercx commented Apr 12, 2021

@sphuber test should be passing, but could still do with a good scrubbin'. Will do so once we are agreed on the design!

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbercx some minor adjustments but I think the design of the interface is good like this. Maybe just add some tests surrounding the fact that we now have multiple units and add a test on what should happen if you call it and no default stringency is set.

@mbercx mbercx requested a review from sphuber April 12, 2021 14:40
except KeyError as exception:
raise ValueError(f'stringency `{stringency}` is not defined for this family.') from exception

def delete_cutoffs(self, stringency) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oliver

And maybe we do the same as in set_cutoffs, if after the operation is completed there is only one stringency left, that becomes the new default. If you agree, would be good to have a test for this and add in the docstring like for set_cutoffs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it makes sense, and don't immediately see any issue with this. I wonder if we should print a message when the user removes the default_stringency with the remove_cutoffs method. Something along the lines of:

  • Only one stringency remaining: The default stringency has been set to: '<LEFTOVER STRINGENCY>'
  • Multiple stringencies remaining: Default stringency removed but multiple options left. Please set the new default stringency with the ``set_default_stringency()`` method.

And I will make sure that Oliver's hunger for tests is amply satisfied. 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be fine with me, but what are you suggesting to use for printing the message? I think the only options we have are logging or a warnings.warn and probably the latter since we haven't really used or setup logging yet. Printing directly I don't like in normal API code tbh.

@mbercx mbercx requested a review from sphuber April 12, 2021 19:51
@mbercx
Copy link
Member Author

mbercx commented Apr 12, 2021

That should turn Oliver's frown upside down! I also implemented the logic discussed and added some warnings in case the default stringency is removed, or a new default stringency needs to still be set.

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Do you know what I consider the greatest sin in the world, my dear? Ingratitude." But I, for one, am very grateful for this PR

@sphuber sphuber merged commit 9687c1c into aiidateam:master Apr 13, 2021
@mbercx mbercx deleted the fix/066/set-cutoffs-single branch April 13, 2021 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RecommendedCutoffMixin: changeset_cutoffs API to only set one stringency
2 participants