-
Notifications
You must be signed in to change notification settings - Fork 184
Update shuffle_poscar feature in run.py #1730
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
Conversation
numpy.random.Generator.shuffle() performs the intended operation of shuffling the order of atoms. numpy.random.Generator.permuted() permutes the elements along the given axis, which mixes the coordinates of all atoms Signed-off-by: ztzkz <95387041+ztzkz@users.noreply.github.com>
for more information, see https://pre-commit.ci
📝 WalkthroughWalkthroughThe change updates the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant make_model_devi
participant RNG
Caller->>make_model_devi: Call with shuffle_poscar=True
make_model_devi->>RNG: rng.shuffle(system.data["coords"], axis=1)
RNG-->>make_model_devi: Return shuffled coordinates
make_model_devi-->>Caller: Return modified system
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #1730 +/- ##
=======================================
Coverage 49.40% 49.40%
=======================================
Files 83 83
Lines 14770 14770
=======================================
Hits 7297 7297
Misses 7473 7473 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Hi, I can't understand what this PR changes. Please explain more about it.
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.
Pull Request Overview
This PR fixes a bug in the shuffle_poscar feature where the wrong NumPy random method was being used. The change corrects the atom coordinate shuffling logic to use the proper in-place shuffle operation instead of a permutation that incorrectly mixed coordinates across all atoms.
- Replaced
rng.permuted()
withrng.shuffle()
for proper atom coordinate shuffling - Fixed the shuffling behavior to preserve atomic coordinate integrity
The original code uses numpy.random.Generator.permuted function, which according to manual
The intended function should be numpy.random.Generator.shuffle, where
So permute randomizes the x, y, z coordinates of each atom independently, so it creates coordinates entirely unphysical, as shown in the picture, leading to non-convergence in DFT. I believe shuffle is the intended logic for this functionality. |
I create an example to test, and import numpy as np
x = np.arange(0, 30).reshape(2,5,3)
print(f"{x=}")
rng = np.random.default_rng(123)
print(f"{rng.permutation(x, axis=1)=}")
rng = np.random.default_rng(123)
rng.shuffle(x, axis=1)
print(f"{x=}")
|
I see the problem. It seems permutation and shuffle behave the same in this case, but the current code uses permuted, which gives the unintended behavior.
|
Thank you for reminding me. I didn't realize they are different. |
numpy.random.Generator.shuffle() performs the intended operation of shuffling the order of atoms. numpy.random.Generator.permuted() permutes the elements along the given axis, which mixes the coordinates of all atoms


shuffle
permuted
Summary by CodeRabbit