-
Notifications
You must be signed in to change notification settings - Fork 22
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
Collection ergonomics #990
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9382d44
Add lammps files created by tests to .gitignore
Yoshanuikabundi 0489229
Implement equality checking between TopologyKeys and tuples of atom i…
Yoshanuikabundi bfb8acf
Implement indexing on collections
Yoshanuikabundi d4db57c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9e59df5
Test equality of TopologyKeys with reversed indices
Yoshanuikabundi 569d9e4
Indexing into a collection with a tuple looks up forward and reverse
Yoshanuikabundi 44feb3f
Merge remote-tracking branch 'upstream/develop' into collection-ergon…
mattwthompson 959d604
TST: Update test comparing tuple representation
mattwthompson 339f46b
Merge remote-tracking branch 'upstream/collection-ergonomics' into co…
mattwthompson 4d3d81a
Add extended tuples and TopologyKeys to TopologyKey tests
Yoshanuikabundi 28d2c60
Implement extended tuple TopologyKey equality and make equality testi…
Yoshanuikabundi c6c9013
Add examples to docstrings
Yoshanuikabundi ed12deb
Add docs for collection ergonomics
Yoshanuikabundi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,11 @@ md.log | |
*stderr.txt | ||
*stdout.txt | ||
|
||
# LAMMPS | ||
log.lammps | ||
out.lmp | ||
tmp.in | ||
|
||
# OS | ||
.DS_Store | ||
.DS_Store? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm pretty sure these two should be equal?
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 believe this test is correct - Lines 131, 133 and 134 are all extended tuples, which has not been implemented (as we've discussed elsewhere), and in line 133 the bond order is not
None
so the tuple doesn't match.The second return line in that hash function is the existing behaviour -
BondKey.__eq__
isThere 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.
Ahhh I see what's going on,
TopologyKey.__eq__
was changed to compare hash functions. I don't think this is generally technically correct as you might get hash collisions - Python uses a 64 bit hash, so there are 2^64 possible hashes, and a typical simulation system might have 2^16 atoms (~65k), so if you need four of them to define a torsion then you might have 2^64 possible atom index tuples... which is really filling up the pigeon holes. Granted torsions tend to be defined between nearby atoms but that's also assuming that Python's hash function is doing a good job of avoiding collisions, and it's had pathological cases in the past.A better way might be to have a
_tuple()
function that gives the equivalent tuple, and then define__hash__
asreturn hash(self._tuple())
and__eq__
as something likereturn self._tuple() == other._tuple() or self._tuple() == other
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.
Comparing hashes in
__eq__
can also run into issues when comparing objects of different types.