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

Speed up functions for retrieving old/new positions from hybrid positions #1020

Merged
merged 4 commits into from
Jun 1, 2022

Conversation

zhang-ivy
Copy link
Contributor

Description

Motivation and context

Resolves #1005

How has this been tested?

The existing test test_relative.py::test_position_output() passes.

I added a timer to this test and here are the times with the old approach vs new approach (this PR):

  • with old approach:
    • old_positions(): 0.04454398155212402
    • new_positions(): 0.04473400115966797
  • with new approach
    • old_positions(): 0.001668691635131836
    • new_positions(): 0.001196146011352539

Change log


@zhang-ivy zhang-ivy requested review from ijpulidos and mikemhenry May 25, 2022 19:52
@codecov
Copy link

codecov bot commented May 25, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.26%. Comparing base (9c9902e) to head (4fb3b88).
Report is 78 commits behind head on main.

Additional details and impacted files

Copy link
Contributor

@mikemhenry mikemhenry left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ijpulidos ijpulidos left a comment

Choose a reason for hiding this comment

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

Cleaner way of getting the positions. Just a few comments/suggestions that I think should be addressed before merging. Thanks!

for idx in range(n_atoms_old):
old_positions[idx, :] = hybrid_positions[idx, :]
hybrid_indices = [self._old_to_hybrid_map[idx] for idx in range(n_atoms_old)]
old_positions = unit.Quantity(hybrid_positions[hybrid_indices, :], unit=unit.nanometer)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think hybrid_positions at this point should already be of type Quantity (see lines 2156 and 2157), so there shouldn't be a need to cast them as such again. This might help with performance, but also in the case where we want to change the units without having to manually edit them in many places at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I think this method expects the positions to be given in nanometers. We should change the docstring to reflect this.

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, just added changes to address these comments!

for idx in range(n_atoms_new):
new_positions[idx, :] = hybrid_positions[self._new_to_hybrid_map[idx], :]
hybrid_indices = [self._new_to_hybrid_map[idx] for idx in range(n_atoms_new)]
new_positions = unit.Quantity(hybrid_positions[hybrid_indices, :], unit=unit.nanometer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous comment.

@mikemhenry mikemhenry requested a review from ijpulidos May 31, 2022 22:48
Copy link
Contributor

@ijpulidos ijpulidos left a comment

Choose a reason for hiding this comment

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

Looks good!

@ijpulidos ijpulidos enabled auto-merge (squash) June 1, 2022 00:03
@ijpulidos ijpulidos disabled auto-merge June 1, 2022 00:08
@mikemhenry mikemhenry merged commit 7a05c88 into main Jun 1, 2022
@mikemhenry mikemhenry deleted the speed-up-position-retrieval branch June 1, 2022 17:32
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.

Speed up functions for retrieving old/new positions from hybrid positions
3 participants