-
Notifications
You must be signed in to change notification settings - Fork 139
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
Fix N shape bugs #157
Merged
Merged
Fix N shape bugs #157
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
032e875
fix for peratom
Linux-cpp-lisp 7cbab12
checks in per_species
Linux-cpp-lisp 1062e36
fix assert
Linux-cpp-lisp 5bc30d5
add some asserts
Linux-cpp-lisp 47cc4f4
add per atom unit tests
nw13slx 9bc461e
refine assert
nw13slx 2918c3d
mean_std over dim=0 only
Linux-cpp-lisp dc5dc68
test global vector quantity
Linux-cpp-lisp 28e658e
Merge branch 'develop' into N_shapeissue
Linux-cpp-lisp 5fa465e
Merge branch 'develop' into N_shapeissue
Linux-cpp-lisp ec89afd
better error
Linux-cpp-lisp 33796e3
energies are 1D, flatten
Linux-cpp-lisp a3b1095
correct assertion
Linux-cpp-lisp fcae06d
fixed assert
Linux-cpp-lisp 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -537,13 +537,18 @@ def _per_atom_statistics( | |||||||||||||
""" | ||||||||||||||
# using unique_consecutive handles the non-contiguous selected batch index | ||||||||||||||
_, N = torch.unique_consecutive(batch, return_counts=True) | ||||||||||||||
N = N.unsqueeze(-1) | ||||||||||||||
assert N.ndim == 2 | ||||||||||||||
assert N.shape == (len(arr), 1) | ||||||||||||||
assert arr.ndim == 2 | ||||||||||||||
data_dim = arr.shape[1] | ||||||||||||||
arr = arr / N | ||||||||||||||
assert arr.shape == (len(N), data_dim) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
if ana_mode == "mean_std": | ||||||||||||||
arr = arr / N | ||||||||||||||
mean = torch.mean(arr) | ||||||||||||||
std = torch.std(arr, unbiased=unbiased) | ||||||||||||||
mean = torch.mean(arr, dim=0) | ||||||||||||||
std = torch.std(arr, unbiased=unbiased, dim=0) | ||||||||||||||
return mean, std | ||||||||||||||
elif ana_mode == "rms": | ||||||||||||||
arr = arr / N | ||||||||||||||
return (torch.sqrt(torch.mean(arr.square())),) | ||||||||||||||
else: | ||||||||||||||
raise NotImplementedError( | ||||||||||||||
|
@@ -567,8 +572,9 @@ def _per_species_statistics( | |||||||||||||
For a per-node quantity, computes the expected statistic but for each type instead of over all nodes. | ||||||||||||||
""" | ||||||||||||||
N = bincount(atom_types.squeeze(-1), batch) | ||||||||||||||
assert N.ndim == 2 # [batch, n_type] | ||||||||||||||
N = N[(N > 0).any(dim=1)] # deal with non-contiguous batch indexes | ||||||||||||||
|
||||||||||||||
assert arr.ndim >= 2 | ||||||||||||||
if arr_is_per == "graph": | ||||||||||||||
|
||||||||||||||
if ana_mode != "mean_std": | ||||||||||||||
|
@@ -585,10 +591,15 @@ def _per_species_statistics( | |||||||||||||
|
||||||||||||||
if ana_mode == "mean_std": | ||||||||||||||
mean = scatter_mean(arr, atom_types, dim=0) | ||||||||||||||
assert mean.shape[1:] == arr.shape[1:] # [N, dims] -> [type, dims] | ||||||||||||||
assert len(mean) == N.shape[1] | ||||||||||||||
std = scatter_std(arr, atom_types, dim=0, unbiased=unbiased) | ||||||||||||||
assert std.shape == mean.shape | ||||||||||||||
return mean, std | ||||||||||||||
elif ana_mode == "rms": | ||||||||||||||
square = scatter_mean(arr.square(), atom_types, dim=0) | ||||||||||||||
assert square.shape[1:] == arr.shape[1:] # [N, dims] -> [type, dims] | ||||||||||||||
assert len(square) == N.shape[1] | ||||||||||||||
dims = len(square.shape) - 1 | ||||||||||||||
for i in range(dims): | ||||||||||||||
square = square.mean(axis=-1) | ||||||||||||||
|
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
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.
why?
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.
should we make N the same shape as arr from the 2nd axis?
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.
what do you mean?