Skip to content

UUID as traitlets for threading related widgets #375

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

Merged
merged 10 commits into from
Nov 16, 2022

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Oct 21, 2022

The widget changed are:

  • ComputationalResourcesWidget because of QeApp code setup trigger refresh it in thread.
  • ComputerDropdownWidget
  • ProcessListWidget because thread call in update function for process.
  • ProcessMonitor thread call in join
  • ProcessNodesTreeWidget

@danielhollas
Copy link
Contributor

@unkcpz sorry for a delay on this. I'll try to take a closer look and test this next week. Thanks!

@unkcpz unkcpz mentioned this pull request Nov 1, 2022
6 tasks
@unkcpz
Copy link
Member Author

unkcpz commented Nov 1, 2022

@unkcpz sorry for a delay on this. I'll try to take a closer look and test this next week. Thanks!

Thanks! Since this PR is separated from the migration to 2.x and it is not manifest the thread issue in 1.6.x, I think you can have a test to make sure everything is working with the new changes in this PR.

@danielhollas
Copy link
Contributor

I made some progress today, was able to convert my app to support this branch and did some basic testing. Will try to do more testing tomorrow.

@unkcpz
Copy link
Member Author

unkcpz commented Nov 7, 2022

Hi @danielhollas, do you have any update on using and testing this? I want to try to finalize this and hopefully have QeApp support AiiDA 2.x supported by next week.

Copy link
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

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

@unkcpz here's my initial review. I agree with the target of merging this next week.

I did some testing within my own application, but need to do a bit more and want to test individual widgets as well.

I have also ran into an interesting edge case that possibly not covered here. I had a widget that passed an AiiDA node to another widget based on the UI interaction (e.g. user clicks a button and AiiDA node is passed to a widget). Presumably because the UI interaction was handled by a different thread than the thread that originally passed the Node, it ran into the same issue as we're solving here, even though the widget itself did not explicitly use threading. So something to be mindful of.

@@ -545,10 +542,10 @@ class ProcessListWidget(ipw.VBox):

past_days (int): Sumulations that were submitted in the last `past_days`.

incoming_node (int, str, Node): Trait that takes node id or uuid and returns the node that must
incoming_node (tr): Trait that takes node uuid that must
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why not keep support of passing id instead of uuid?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean pk? Do you have any use case for where you what to use primary key, since I think you can use UUID to include all the cases for pk?

process = change["new"]
if process is None or process.id != getattr(change["old"], "id", None):
process_uuid = change["new"]
if process_uuid is None or process_uuid != change["old"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we clean this up a bit to reduce the indentation levels? The first if statement is super confusing to me.

If I understood the logic correctly, this should work?

Suggested change
if process_uuid is None or process_uuid != change["old"]:
if process_uuid == change["old"]:
return
# stop thread (if running)
if self._monitor_thread is not None:
with self._monitor_thread_lock:
self._monitor_thread_stop.set()
self._monitor_thread.join()
if process_uuid is None:
return
with self.hold_trait_notifications():
with self._monitor_thread_lock:
self._monitor_thread_stop.clear()
self._monitor_thread = Thread(
target=self._monitor_process, args=(process_uuid,)
)
self._monitor_thread.start()

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, fully agree. I try to simplify it more. Please have a test of it. I'll do the test further more on qeApp.

Copy link
Member Author

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

@danielhollas thanks a lot for the test. I think the main open issue is whether we need to using only the UUID or also support the other entities (label/pk etc.) as the value of those widgets.

I update the ProcessMornitor to try to make it more clear.

@@ -545,10 +542,10 @@ class ProcessListWidget(ipw.VBox):

past_days (int): Sumulations that were submitted in the last `past_days`.

incoming_node (int, str, Node): Trait that takes node id or uuid and returns the node that must
incoming_node (tr): Trait that takes node uuid that must
Copy link
Member Author

Choose a reason for hiding this comment

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

You mean pk? Do you have any use case for where you what to use primary key, since I think you can use UUID to include all the cases for pk?

process = change["new"]
if process is None or process.id != getattr(change["old"], "id", None):
process_uuid = change["new"]
if process_uuid is None or process_uuid != change["old"]:
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, fully agree. I try to simplify it more. Please have a test of it. I'll do the test further more on qeApp.

@unkcpz unkcpz requested a review from danielhollas November 7, 2022 16:54
@unkcpz unkcpz requested a review from danielhollas November 10, 2022 16:17
@unkcpz
Copy link
Member Author

unkcpz commented Nov 10, 2022

I got this PR tested on QeApp and no issue was found.

@danielhollas
Copy link
Contributor

@unkcpz great that you tested it. I didn't get to it this week due to other things. I'll get back to it on Monday, but if you need to merge before than feel free.

Next week I will for sure need to do some production calculations so will test this more, perhaps this can be merged but still not released as a full 2.0 version before more testing is done?

@unkcpz
Copy link
Member Author

unkcpz commented Nov 10, 2022

Next week I will for sure need to do some production calculations so will test this more, perhaps this can be merged but still not released as a full 2.0 version before more testing is done?

Yes, I think we can set some milestones in the next meeting for 2.0.0. I think the major version is for backward compatibility breakup. This means if we change other traitslet, it breaks compatibility. I think we need to make the release after that?

@unkcpz
Copy link
Member Author

unkcpz commented Nov 16, 2022

Hi @yakutovicha, are you reviewing this? I think we can have another alpha release with this merged. Then I can keep on working on QeApp.
@danielhollas, also if you want to have a final check/test.

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.

Overall looks good to me.

Looking at the discussion, I see one unclear point, whether to allow to use of node labels together with UUIDs. IMO, it would be ok to keep UUIDs only, as I wrote in the review comments.

@danielhollas please let me know if you agree with that.

@@ -688,7 +695,7 @@ def start_autoupdate(self, update_interval=10):
class ProcessMonitor(traitlets.HasTraits):
"""Monitor a process and execute callback functions at specified intervals."""

process = traitlets.Instance(ProcessNode, allow_none=True)
process_uuid = Unicode(allow_none=True)
Copy link
Member

Choose a reason for hiding this comment

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

What about naming it value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed. Also test the new API in QE app.

@danielhollas
Copy link
Contributor

Thanks @unkcpz. I was testing it today / yesterday in my app and did not find any issues, but was not testing all the functionality here. Unfortunately, I had some other urgent stuff to do for tomorrow's meeting. I'll try to do one more round of testing today late evening if I get to it. Otherwise, this is good to merge from my side and release a new alpha version.

@yakutovicha I think you're right about the UUID value, I am find with only supporting UUID. One question, how does the Code selection UI looks if there are two computers with the same label? e.g. if one imports nodes from another DB? Perhaps we should display PKs in the Dropdown in such cases, since otherwise the user will only see two identical labels?

@yakutovicha
Copy link
Member

yakutovicha commented Nov 16, 2022

One question, how does the Code selection UI looks if there are two computers with the same label? e.g. if one imports nodes from another DB? Perhaps we should display PKs in the Dropdown in such cases, since otherwise the user will only see two identical labels?

I think they are indistinguishable from the current UI. I agree with you that adding a PK number alongside with the code label would be a good option 👍

@unkcpz unkcpz enabled auto-merge (squash) November 16, 2022 16:40
@unkcpz unkcpz disabled auto-merge November 16, 2022 16:52
@unkcpz unkcpz merged commit 2ec0db9 into master Nov 16, 2022
@unkcpz unkcpz deleted the fix/uuid-as-traitlets-threading-widget branch November 16, 2022 17:03
unkcpz added a commit to unkcpz/aiidalab-widgets-base that referenced this pull request Nov 16, 2023
)

- `aiida-core~=2.2` to align with aiida-core version in new docker stack
- `aiidalab-widget-base==2.0.0b5` for pinning the widgetnbextension version aiidalab#467
- `widget-bandsplot~=0.5.1` for fixing TDOS background filling issue.
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.

3 participants