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

Add pickling of Atom, Residue, Segment and groups. #3953

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Add pickling of Atom, Residue, Segment and groups. #3953

merged 1 commit into from
Jan 3, 2023

Conversation

pgbarletta
Copy link
Contributor

@pgbarletta pgbarletta commented Dec 8, 2022

From #3947

Changes made in this Pull Request:

  • Add reduce() method to both ResidueGroup and SegmentGroup
  • Change _unpickle() so it can create any kind of group from its indices.
  • Add one test for each group in the parallelism section.

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

PD: sorry for the new PR. I synced up my fork from develop and that somehow closed the previous PR.

@codecov
Copy link

codecov bot commented Dec 8, 2022

Codecov Report

Base: 93.48% // Head: 93.49% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (404cd45) compared to base (0c4f823).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3953   +/-   ##
========================================
  Coverage    93.48%   93.49%           
========================================
  Files          190      190           
  Lines        24951    24963   +12     
  Branches      3527     3527           
========================================
+ Hits         23326    23338   +12     
  Misses        1102     1102           
  Partials       523      523           
Impacted Files Coverage Δ
package/MDAnalysis/core/groups.py 97.51% <100.00%> (+0.02%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

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

can we use empty Universes?

"""Test SegmentGroup pickling support."""
@pytest.fixture()
def universe(self):
return mda.Universe(TPR, XTC)
Copy link
Member

Choose a reason for hiding this comment

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

minor quibble, but if you use Universe.empty() it'll make the tests a little faster. it's not a big deal, but over 1,000 tests it adds up slowly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, don't get it. Say I do:

seg_group = mda.Universe.empty(10).segments
seg = pickle.loads(pickle.dumps(seg_group))

how do I compare them? And would that be a useful test?

Copy link
Member

Choose a reason for hiding this comment

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

you could check that the new segments have the same universe as the old one:

u = mda.Universe.empty()

segs = u.segments

new = pickle.loads(...)

assert new.universe is u

I think maybe you're right, a better test would have dummy data inside the Universe...

u = mda.Universe.empty()
u.add_TopologyAttr('segids', values=['A', 'B', etc]

... some pickling

assert new.segids == ['A', 'B', etc]

The idea is you can create a Universe without using files, and it'll make the tests faster if we don't (and also makes the tests not reliant on TPRParser working)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. I went with the 2nd choice:

def test_segmentgroup_pickle():
    u = mda.Universe.empty(10)
    u.add_Segment(segid="X")
    u.add_Segment(segid="Y")
    u.add_Segment(segid="Z")
    segids = ["A", "X", "Y", "Z"]
    u.add_TopologyAttr("segids", values=["A", "X", "Y", "Z"])
    seg_group = mda.SegmentGroup((1, 3), u)
    seg = pickle.loads(pickle.dumps(seg_group))
    assert_equal(seg.universe.segments.segids, segids)

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Two little things and then I think good to go.

package/MDAnalysis/core/groups.py Show resolved Hide resolved
@@ -39,6 +39,8 @@ Fixes
* fixes guessed_attributes and read_attributes methods of the Topology class, as
those methods were giving unexpected results for some topology attributes
(e.g. bonds, angles) (PR #3779).
* Add pickling support for Atom, Residue, Segment, ResidueGroup
Copy link
Member

Choose a reason for hiding this comment

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

Entries newest first and this needs to be put under 2.5.0. Merging with upstream/develop also required. :)

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Two tiny nitpicks sorry.

package/AUTHORS Outdated Show resolved Hide resolved
@pgbarletta
Copy link
Contributor Author

I'll be out for a ~week. I'll rebase once the numpy deprecations issues are fixed.

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

LGTM thanks @pgbarletta

package/CHANGELOG Outdated Show resolved Hide resolved
Add reduce() method to both ResidueGroup and SegmentGroup
Change _unpickle() so it can create any kind of group from its indices.
Add one test for each group in the parallelism section.
@pgbarletta pgbarletta requested a review from IAlibay January 3, 2023 08:29
@@ -119,6 +119,11 @@ def _unpickle(u, ix):
return u.atoms[ix]


# TODO 3.0: deprecate _unpickle in favor of _unpickle2.
Copy link
Member

Choose a reason for hiding this comment

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

Just a comment here, unless it changes user-facing behaviour there is no need to deprecate a private method like this. We can just throw it out right now and none would be the wiser.

Please raise a relevant issue regarding this though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

I'll approve although please do raise the issue for the follow-up 3.0 work, otherwise it'll get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants