-
Notifications
You must be signed in to change notification settings - Fork 658
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
Slicing fixes #916
Slicing fixes #916
Conversation
@MDAnalysis/coredevs a review please? |
Looks good, but because you've changed a kwarg I think you'll need to document that |
stop : int, optional | ||
Last frame of trajectory to analyse, Default: -1 | ||
Frame index to stop analysis. Default: None becomes | ||
n_frames. Iteration stops *before* this frame number. |
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.
, which means that the trajectory would be read until the end (because the first frame has index 0 and the last frame has index n_frames - 1.
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.
Right, that is unclear here and I'll fix it.
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.
On 27/07/16 20:25, Oliver Beckstein wrote:
In package/MDAnalysis/analysis/contacts.py
#916 (comment):stop : int, optional
Last frame of trajectory to analyse, Default: -1
Frame index to stop analysis. Default: None becomes
n_frames. Iteration stops _before_ this frame number.
, which means that the trajectory would be read until the end (because
the first frame has index 0 and the last frame has index n_frames - 1.—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
https://github.com/MDAnalysis/mdanalysis/pull/916/files/79b1582267ece8ea14f27fd4bed37ef187d95544#r72495216,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABUWuuLApCu8e94JQMbJNZsA4rp733hgks5qZ6K0gaJpZM4JVv0L.This is an odd behavior. The default should not be -1, it should be
None. Why would we want to stop before the end of the trajectory?
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.
Hence the pull request?
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.
@jdetle Sorry, I read the comment from a mail notification, and I thought the code abstract was the new snippets. My bad.
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.
No problem.
See comments in code. Needs a closer look how this interacts (or possibly solves) #818. |
I have slain the beast grendel (#818). |
( I am pretty proud of myself right now in case any of you were wondering...) |
@@ -514,7 +515,11 @@ def timeseries(self, asel, start=None, stop=None, step=None, format='afc'): | |||
where the shape is (frame, number of atoms, | |||
coordinates) | |||
""" | |||
start, stop, skip = self.check_slice_indices(start, stop, step) | |||
if skip is not None: |
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.
Here add a deprecation warning, skip to be removed in 1.0.
Also add a .. versionchanged:: 0.16.0
that explains how skip
is now step
and behaves differently; you can add a link to issue #818.
Hi @orbeckst. Sorry, I reformatted the C code because it was hard for me to read. I can certainly squash some commits. I also have yet to address the comments you previously made so I will finish that either tonight or tomorrow. |
It will close #818, yes. |
When you reformat then make that a single commit and say in the commit message that this is only formatting and no functional changes. This makes it a lot easier to follow diffs. Oliver Beckstein
|
Unfortunately that commit both reformatted and changed things. My best guess of fixing things would be |
Merrrgggg that doesn't work. |
@@ -137,6 +137,15 @@ def test_volume(self): | |||
err_msg="wrong volume for unitcell (no unitcell " | |||
"in DCD so this should be 0)") | |||
|
|||
def test_timeseries_slicing(self): |
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.
So this is a good test, but I'd turn it into a generator.. so something like:
def test_timeseries_slicing():
for start, stop, step in (
(None, None, 10), # this is your current test
(1, None, 10), # this tests non zero start point
etc:
yield self._check_timeseries, start, stop, step
def _check_timeseries(self, start, stop, step):
self.u = mda.U
ts = timeseries()
ts_skip = timeseries(self.u.atoms, start, stop, step)
assert_array_almost_equal([ts[:, start:stop:step], ts_skip, 5)
Yes, splitting the commit into formatting and changes would be awesome for readability. It's also important for any efforts to move to Py3: I this gets rewritten we need to know what was changed. I think your git rebase with edit will work for splitting the commit with multiple add/commit during the edit step. Maybe you need a reset, too, in there somewhere. S/O has a good answer on git commit splitting. Oliver Beckstein
|
I tried to do it with a simple rebase and things did not work super well. For what its worth I included the lines of changed code in the first comment in this PR. |
@richardjgowers Could you take some time to look at my test generator and tell me what I'm doing wrong? I suspect the tests aren't running as they should because the tests took the same time before and after adding the generator. |
rc = skip_dcdstep(dcd.fd, dcd.natoms, dcd.nfixed, dcd.charmm, numskip) | ||
if (rc < 0): | ||
raise IOError("Error skipping frame from DCD file") | ||
dcd.setsread = dcd.setsread + numskip | ||
dcd.setsread = dcd.setsread + numskip |
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.
Are you sure that this should now be one level out, i.e. not inside the if (step > 1 and skip >1)
statement any more?
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.
Yes.
Edit: Actually, I am not sure. Let me add some more tests.
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.
Everything is fine, current tests account for this, the logic is sound too.
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.
ok. Btw, can we write this aesthetically more pleasingly as
dcd.setsread += numskip
The stop gymnastics has been done away with. |
@orbeckst Did a small squash hope that didn't delete your comments :/ Hopefully the new comments address your concerns. |
@@ -115,15 +115,21 @@ def __read_timecorrel(object self, object atoms, object atomcounts, object forma | |||
for i from 0 <= i < n_frames: | |||
if (step > 1 and i > 0): | |||
# Check if we have fixed atoms | |||
# XXX not 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.
This comment said "We should check for fixed atoms here but we have not implemented it".
I don't think that you are addressing fixed atoms anywhere (it's an obscure feature in CHARMM DCD files where only the first frame contains the positions of the frozen atoms and all later frames do not have these positions, which are unchanging.) Therefore, please leave this comment in.
Okay! I will fix it when I get back from my swim!
|
Hi John, don't worry – it's ok to sometimes not watch the issue tracker ;-)… and I am told it's Sunday, too. For me, hacking away feels like a reward and I really like doing it when I get a chance but there is really no expectation for anyone to be on call 24/7. Relaxed coders are good coders! Oliver
Oliver Beckstein * [email protected] |
@jdetle give me a poke when this is ready to review |
Poke |
def test_timeseries_slicing(self): | ||
# check that slicing behaves correctly | ||
# should fail before issue #914 resolved | ||
x = [(0, 1, 1), (1,1,1), (1, 2, 1), (1, 2, 2), (1, 4, 2), (1, 4, 4), |
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.
backwards stepping? (step = -1)
check that using None
works too
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.
Haha... annnnd its broken.
So the functions for the DCD reader don't read in reverse from the best of my understanding and changing them to do this would probably be a pain. I don't know the best way of going about doing this, but it is certainly something we would want in the DCD Reader for python 3. Anyone have any thoughts? |
So has reverse iteration always been broken? (ie current develop state) if On Mon, 1 Aug 2016, 17:56 John Detlefs, [email protected] wrote:
|
Yes reverse iteration for the creation of a timeseries has been broken to begin with. For example, start = 5, stop =0 and step -1 returns a timeseries of array indices 5, 6, 7, 8, 9. I've got some work I have to get done on PCA but I'll raise an issue after I get things done on that. (Priorities!) |
Then it's arguably not your problem to fix in this PR. Make a separate On Mon, 1 Aug 2016, 18:09 John Detlefs, [email protected] wrote:
|
The CHANGELOG doesn't mention that #818 is also fixed with this PR. |
Slicing fixes
Fixes #914, #818
Changes made in this Pull Request:
check_slice_indices
Added known failures for backwards steps steps.
PR Checklist
TODO
LINE CHANGES IN dcd.c
line 440
[line 470](https://github.com/jdetle/mdanalysis/blob/1c6c24124c1640294b65e6bc27f4cf8c09f962db/package/M
DAnalysis/coordinates/src/dcd.c#L470)
frame iteration lines