-
Notifications
You must be signed in to change notification settings - Fork 663
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
Conversation
Codecov ReportBase: 93.48% // Head: 93.49% // Increases project coverage by
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
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. |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
There was a problem hiding this 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/CHANGELOG
Outdated
@@ -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 |
There was a problem hiding this comment.
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. :)
There was a problem hiding this 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.
I'll be out for a ~week. I'll rebase once the numpy deprecations issues are fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks @pgbarletta
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.
@@ -119,6 +119,11 @@ def _unpickle(u, ix): | |||
return u.atoms[ix] | |||
|
|||
|
|||
# TODO 3.0: deprecate _unpickle in favor of _unpickle2. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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.
From #3947
Changes made in this Pull Request:
PR Checklist
PD: sorry for the new PR. I synced up my fork from develop and that somehow closed the previous PR.