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

plumpy.ProcessListener made persistent #274

Closed
wants to merge 1 commit into from

Conversation

rikigigi
Copy link
Member

solves #273

We implement the persistence of ProcessListener by deriving the class ProcessListener and EventHelper from persistence.Savable. The class EventHelper is moved to a new file because of a circular import with utils and persistence

@rikigigi
Copy link
Member Author

@sphuber I don't understand why 4 test fail here https://github.com/aiidateam/plumpy/actions/runs/6012847906/job/16309013751?pr=274 ... do you have any idea?
For me the call_with_super_check is a little bit obscure...

Thank you very much

@sphuber
Copy link
Collaborator

sphuber commented Aug 30, 2023

The call_with_super_check is a decorator that can be used for a classes method, which ensures that if it is subclassed, the subclass calls super() or it raises an exception. The problem is that it is not quite sure which subclass it is complaining about. I have looked through your changes, and I don't immediately see any place where you have forgotten to call the super. Will have to look into it later.

@rikigigi
Copy link
Member Author

I think that the reason that prevented call_with_super_check from working was the fact that it used a single counter for all function. In my case it was called multiple times in the stack. Unfortunately to make the persistence of the Listener, I had to introduce some ugly hacks in the test suite to avoid circular references and to correctly compare snapshots.

@rikigigi rikigigi marked this pull request as ready for review September 19, 2023 11:30
@rikigigi
Copy link
Member Author

The timeout issue is not present in my local run of the test suite :-(

@rikigigi
Copy link
Member Author

did a simple test with aiidateam/aiida-core#5732 rebased on current develop + https://github.com/sphuber/aiida-s3 and it worked fine, with the ProcessListener being correctly called on the aiida daemon

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (44d27d1) 90.83% compared to head (8724b83) 90.76%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #274      +/-   ##
==========================================
- Coverage   90.83%   90.76%   -0.06%     
==========================================
  Files          21       22       +1     
  Lines        2974     2995      +21     
==========================================
+ Hits         2701     2718      +17     
- Misses        273      277       +4     
Files Coverage Δ
src/plumpy/base/utils.py 100.00% <100.00%> (ø)
src/plumpy/utils.py 82.12% <ø> (+0.61%) ⬆️
src/plumpy/processes.py 92.47% <87.50%> (+0.02%) ⬆️
src/plumpy/process_listener.py 85.19% <78.58%> (-8.14%) ⬇️
src/plumpy/event_helper.py 80.00% <80.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rikigigi
Copy link
Member Author

@sphuber just a ping. Are the changes in the call_with_super_check ok? Thank you

@sphuber
Copy link
Collaborator

sphuber commented Oct 25, 2023

Sorry for the delay @rikigigi . Could you please give a small writeup as to why these hacks were necessary and what they are doing?

@rikigigi
Copy link
Member Author

rikigigi commented Nov 1, 2023

I reverted the changes on the call_with_super_check, but a small details that prints the name of the correct function in case of error. They were not necessary.

The issue with the tests is simple: the
class ProcessSaver(plumpy.ProcessListener)
is defined as a Listener. If now the ProcessListener is persistent, when we save the Process in the tests a mess happens because of the saved instance of the class inside the ProcessListener, that have inside it the ProcessListener itself. So What I did is to modify the ProcessSaver to not store directly inside it the Process to save but to use an external global dictionary where we save the Process by instance id. In this way we avoid the circular reference and we don't have to change all the tests.

Copy link
Collaborator

@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 @rikigigi . Changes look good, just some minor final requests and then we can merge this.

src/plumpy/processes.py Outdated Show resolved Hide resolved
src/plumpy/processes.py Outdated Show resolved Hide resolved
@@ -376,6 +424,11 @@ def compare_value(bundle1, bundle2, v1, v2, exclude=None):
elif isinstance(v1, list) and isinstance(v2, list):
for vv1, vv2 in zip(v1, v2):
compare_value(bundle1, bundle2, vv1, vv2, exclude)
elif isinstance(v1, set) and isinstance(v2, set) and len(v1) == len(v2) and len(v1) <= 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Am I going nuts or are the bundle1 and bundle2 arguments in compare_dictionaries and compare_value not doing anything whatsoever? If true and they do not do anything, do we really need this custom dictionary compare function? Surely there must be existing tools that provide this? I realize this is not something you added in this PR, but just wondering if I am missing something

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 think you are right, bundle1 and bundle2 are useless! https://github.com/seperman/deepdiff may be an option, but I don't think I will add it in this PR

test/utils.py Outdated Show resolved Hide resolved
test/utils.py Show resolved Hide resolved
test/utils.py Show resolved Hide resolved
@sphuber
Copy link
Collaborator

sphuber commented Nov 2, 2023

Also, please install pre-commit. Inside the repo, simply run pre-commit install. This way the pre-commit linter autoamtically runs when you commit. This will fix the broken CI.

Finally, maybe you want to merge this into https://github.com/aiidateam/plumpy/tree/support/0.21.x instead. aiida-core is currently stuck on v0.21.x. If we merge this into master it will have to be released with v0.22.x instead, and so you won't be able to install it with aiida-core. So you may want to rebase this onto the support/0.21.x branch

@rikigigi
Copy link
Member Author

rikigigi commented Nov 7, 2023

ok, thank you! I'm working on it.

rikigigi added a commit to rikigigi/plumpy that referenced this pull request Nov 10, 2023
solves aiidateam#273

We implement the persistence of ProcessListener by deriving the class
ProcessListener and EventHelper from persistence.Savable.
The class EventHelper is moved to a new file because of a circular
import with utils and persistence

Fixing the test

There was a circular reference issue in the test listener that was
storing a reference to the process inside it, making its serialization
impossible. To fix the tests an ugly hack was used: storing the
reference to the process outside the class in a global dict using id as
keys. Some more ugly hacks are needed to check correctly the equality of
two processes. We must ignore the fact that the instances if the
listener are different.

We call del on dict items of the ProcessListener's global implemented in the test suite
to clean the golbal variables

addressed issues in aiidateam#274
solves aiidateam#273

We implement the persistence of ProcessListener by deriving the class
ProcessListener and EventHelper from persistence.Savable.
The class EventHelper is moved to a new file because of a circular
import with utils and persistence

Fixing the test

There was a circular reference issue in the test listener that was
storing a reference to the process inside it, making its serialization
impossible. To fix the tests an ugly hack was used: storing the
reference to the process outside the class in a global dict using id as
keys. Some more ugly hacks are needed to check correctly the equality of
two processes. We must ignore the fact that the instances if the
listener are different.

We call del on dict items of the ProcessListener's global implemented in the test suite
to clean the golbal variables

addressed issues in aiidateam#274
rikigigi added a commit to rikigigi/plumpy that referenced this pull request Nov 10, 2023
solves aiidateam#273

We implement the persistence of ProcessListener by deriving the class
ProcessListener and EventHelper from persistence.Savable.
The class EventHelper is moved to a new file because of a circular
import with utils and persistence

Fixing the test

There was a circular reference issue in the test listener that was
storing a reference to the process inside it, making its serialization
impossible. To fix the tests an ugly hack was used: storing the
reference to the process outside the class in a global dict using id as
keys. Some more ugly hacks are needed to check correctly the equality of
two processes. We must ignore the fact that the instances if the
listener are different.

We call del on dict items of the ProcessListener's global implemented in the test suite
to clean the golbal variables

addressed issues in aiidateam#274
@rikigigi
Copy link
Member Author

I addressed the issues and created a different PR for 0.21.x support #277

@sphuber
Copy link
Collaborator

sphuber commented Nov 13, 2023

I am closing this as I cherry-picked your fix that was released with the v0.21.10 support in #279 so it is now also on master

@sphuber sphuber closed this Nov 13, 2023
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.

2 participants