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

Use UUID rather than the aiida node instance as traitlet #354

Closed
wants to merge 5 commits into from

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Sep 7, 2022

From AiiDA 2.x every orm entity instance is now tied to a specific storage instance (which is connected to the database).
So once the storage instance is closed (and so close the connection), then those orm instances are now "dead" and can not be used for other reloaded sessions.

Since this requires changing the API of the ComputationalResourceWidget, I create this dedicated PR for it.
Do we also consider the back-ward compatibility or do we just leave this all to the 2.x support by put all these changes to #344 ?

Copy link
Member

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

I've started reviewing this and have a few suggestions and a few questions. I am a bit confused about how we use the validation mechanism here. Maybe we can clarify this before I move forward with further review.

Do we also consider the back-ward compatibility or do we just leave this all to the 2.x support by put all these changes to #344 ?

I think we established that AWB that supports AiiDA 2.x will not support 1.x. In so far, this change set does not need to be backwards-compatible.

aiidalab_widgets_base/computational_resources.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/computational_resources.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/computational_resources.py Outdated Show resolved Hide resolved
@unkcpz
Copy link
Member Author

unkcpz commented Sep 12, 2022

@csadorf thanks for the review!

I think we established that AWB that supports AiiDA 2.x will not support 1.x. In so far, this change set does not need to be backwards-compatible.

I agree. But this means we need to care about the release. I suggest cherry pick and release a version without this feature for 1.x supported only and after that having this new API a new version released with PR #344.

@unkcpz unkcpz requested a review from csadorf September 12, 2022 17:33
# This place will never be reached, because the trait's type is checked.
return None
try:
_ = orm.load_code(code_uuid)
Copy link
Member

Choose a reason for hiding this comment

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

To my knowledge, the widget will be blocked while the validation is running. Therefore, I don't think we should run code as part of the validation that might require a significant amount of time (like a database query). I think the validation should not extend beyond very basic checks in the sense of whether the widget will enter a valid state with the provided value.

Anything beyond that should be handled as part of the business logic of the application. That means, we should inform consumers that the selected value does not correspond to a valid code and then allow those consumers to react to that in an appropriate manner.

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 see, thanks! The UUID is got from an instance queried from the database, to be honest, I see less point to check its existence.
Changed and please check the last commit.

Comment on lines +211 to +213
except ValueError:
self.output.value = f"""'<span style="color:red">{code_uuid}</span>'
is not a valid UUID."""
Copy link
Member

Choose a reason for hiding this comment

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

I think the standard behavior is to raise a TraitError in this case, see here.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is the exception raised when the code_uuid is not a valid UUID. uuid.UUID module will raise a ValueError
For example:

from uuid import UUID

UUID("IAMNOTUUID", version=4)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but we should raise a TraitError in response.

@danielhollas
Copy link
Contributor

danielhollas commented Sep 13, 2022

I agree. But this means we need to care about the release. I suggest cherry pick and release a version without this feature for 1.x supported only and after that having this new API a new version released with PR #344.

Yes please 😊 I asked @yakutovicha to cut a new 1.x release now to release my recent PRs so you might want to hold on merging this till then maybe (or have a separate 2.x branch). EDIT: Release made 🚀

@yakutovicha
Copy link
Member

I agree. But this means we need to care about the release. I suggest cherry pick and release a version without this feature for 1.x supported only and after that having this new API a new version released with PR #344.

As a side note: I just created support/aiida-1.x branch. All the bug fixes for the aiida-1.x should go there. You can now feel free to brake things in the master branch 😄 .

Copy link
Member

@yakutovicha yakutovicha left a comment

Choose a reason for hiding this comment

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

Just to mention that (apparently) an AiiDA object cannot be a trait and it is not 100% clear to me why. There are many widgets in this repository relying on AiiDA objects being traits.

I am still missing why the error pops up for the ComputationalResourcesWidget and doesn't manifest itself for the StructureManagerWidget (as we tested with @unkcpz).

Before approving this I would like to understand:

  1. Should we not use AiiDA objects as traits?
  2. If we shouldn't: why is that?
  3. If we still can, what are the new restrictions?

Can @chrisjsewell and/or @unkcpz comment on this? Understanding the points above can clarify how to move forward.

Comment on lines +200 to +201
"""If code is provided, set it as it is. If code's UUID is provided,
check it is valid in DB"""
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure this description is valid anymore. Looks like you forbid providing the code object (only ID or UUID).

@unkcpz
Copy link
Member Author

unkcpz commented Sep 19, 2022

Hi @yakutovicha, is this possible related to self.hold_trait_notifications()? I don't know how this contextmanager work under the hood, but from its functionality, it will run the code (where inside refresh function it will query for the aiida data for the code/computer node) and hold the notification. I guess the issue comes from where calls the update of this widget is a new session and the error pop up.

I make the above assumption since when testing the ComputationalResourcesWidget itself from the notebook all works fine, the issue occurs only when embedding the widget into qeapp.

Let me know how to test this further. If hold_trait_notifications is the catch, I'd say we should not use AiiDA objects as traits in all cases.

@yakutovicha
Copy link
Member

Let me know how to test this further. If hold_trait_notifications is the catch, I'd say we should not use AiiDA objects as traits in all cases.

I don't know how to test it at the moment. I need to look closer. But I would very much prefer to keep using AiiDA objects as traits, cause otherwise, we will need a huge rewrite of the AWB library.

@unkcpz
Copy link
Member Author

unkcpz commented Sep 26, 2022

As discussed offline, the issue reported in aiidalab/aiidalab-qe#279 is rooted in using unsafe multiple threads calls to access the AiiDA database which is not well handled by AiiDA at the moment.
I'll close this PR and fix the thread issue in QeApp.

@unkcpz unkcpz closed this Sep 26, 2022
@yakutovicha
Copy link
Member

@unkcpz is it okay to delete the branch?

@unkcpz
Copy link
Member Author

unkcpz commented Oct 6, 2022

Sure! Deleted.

@unkcpz unkcpz deleted the fix/xx/use-uuid-as-traitlets branch October 6, 2022 14:40
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.

4 participants