-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
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
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.
Cleaner way of getting the positions. Just a few comments/suggestions that I think should be addressed before merging. Thanks!
perses/annihilation/relative.py
Outdated
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) |
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 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.
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.
Actually, I think this method expects the positions to be given in nanometers. We should change the docstring to reflect this.
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, just added changes to address these comments!
perses/annihilation/relative.py
Outdated
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) |
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.
Same as previous comment.
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.
Looks good!
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):
Change log