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

Changed default memory layout of MemoryReader to 'fac' #1132

Merged

Conversation

wouterboomsma
Copy link
Contributor

@wouterboomsma wouterboomsma commented Dec 20, 2016

Fixes #1063 and #1065

Changes made in this Pull Request:

  • Switched default layout of MemoryReader to 'fac'
  • Ensure that the internal numpy array in a MemoryReader is always float32.

PR Checklist

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

@wouterboomsma
Copy link
Contributor Author

Sorry for the delay.

One small annoyance is that this code no longer works

    coordinates = universe.trajectory.timeseries(universe.atoms)
    universe2 = mda.Universe(PSF, coordinates, format=MemoryReader)

and has to be replaced with

    coordinates = universe.trajectory.timeseries(universe.atoms, format='fac')
    universe2 = mda.Universe(PSF, coordinates, format=MemoryReader)

or

    coordinates = universe.trajectory.timeseries(universe.atoms)
    universe2 = mda.Universe(PSF, coordinates, format=MemoryReader, order='afc')

Encore uses timeseries() interface quite frequently to extract subuniverses with MemoryReader so this means I had to add format='fac' quite a few places. But I can live with this solution.

@mnmelo
Copy link
Member

mnmelo commented Dec 20, 2016

Perhaps this makes the case for a change of the timeseries return default to 'fac'?
I'd be for it, since I find fac order much more intuitive.

@wouterboomsma
Copy link
Contributor Author

@mnmelo I agree about the intuition, although I'm a bit worried about how much user-code we would break by changing the default of timeseries. But at least changing the MemoryReader to the right layout now before release is a step in the right direction.

@@ -150,6 +150,6 @@ def get_ensemble_bootstrap_samples(ensemble,
size=ensemble.trajectory.timeseries().shape[1])
ensembles.append(
mda.Universe(ensemble.filename,
ensemble.trajectory.timeseries(format='afc')[:,indices,:],
ensemble.trajectory.timeseries(format='fac')[indices,:,:],
Copy link
Member

Choose a reason for hiding this comment

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

you can now actually skip the last :, :] in the fancy index. Numpy will default to taking the full array for lower dimensions

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Great, thanks, @wouterboomsma !

Revisions:

  • test that checks the default memory order
  • optional: simplify the indexing by leaving out trailing [..., :, :]

We can change timeseries at some other time. But at least by using format='fac' explicitly you will be future proof... (except that we will probably also rename format to order in timeseries() but that's a different issue).

@@ -167,7 +161,7 @@

u2 = mda.Merge(protein).load_new(
AnalysisFromFunction(lambda ag: ag.positions.copy(),
protein).run().results.swapaxes(0, 1),
Copy link
Member

Choose a reason for hiding this comment

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

It's really nice that the swapaxes are gone now. That makes the code easier to understand

@kain88-de kain88-de added this to the 0.16.0 milestone Jan 2, 2017
@kain88-de
Copy link
Member

@wouterboomsma ping

@wouterboomsma
Copy link
Contributor Author

@kain88-de, @orbeckst I'm back. Sorry for the delay. I'll implement the changes requested by @orbeckst today or tomorrow. Two comments:

I sometimes add the extra :,: to make it clear to the reader of the code how many dimensions the container has - which is not always clear from the context. But I can certainly remove this if you like.

@orbeckst, when you write "test that checks the default memory order" do you mean tests that verify that after reading in a structure from file, the layout in the Memory Reader corresponds to the 'fac' standard. So for instance, reading it in with and with and without explicitly setting the format to 'fac' and then comparing that they are the same?

@orbeckst
Copy link
Member

orbeckst commented Jan 12, 2017 via email

@jbarnoud
Copy link
Contributor

I sometimes add the extra :,: to make it clear to the reader of the code how many dimensions the container has - which is not always clear from the context. But I can certainly remove this if you like.

For what it is worth, I prefer the explicit notation.

@wouterboomsma
Copy link
Contributor Author

@orbeckst Added test for default layout (2be6477)

@orbeckst
Copy link
Member

orbeckst commented Jan 13, 2017 via email

@orbeckst
Copy link
Member

All good, thank you. Can this be merged from your end?

@wouterboomsma
Copy link
Contributor Author

@orbeckst I don't think I have permissions to merge anything into the main repo (at least, I cannot see any "merge" button - could be due to my limited experience with github).

@kain88-de
Copy link
Member

No only maintainers can merge you haven't overlooked anything.

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.

5 participants