-
Notifications
You must be signed in to change notification settings - Fork 504
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: fix errors for zero atom inputs #4005
Conversation
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
WalkthroughWalkthroughThe recent changes enhance tensor manipulation and reshaping logic across various modules in the DeepMD framework. Key improvements include explicit handling of tensor dimensions to avoid reliance on automatic inference, enhancing clarity and robustness. Functions were updated to ensure proper dimensionality in reshaping operations, particularly when handling edge cases like empty input arrays or variable shapes, ultimately improving model stability and performance. Additionally, a new test method was introduced to validate behavior under zero atom conditions. Changes
Sequence Diagram(s)sequenceDiagram
participant A as User
participant B as Model
participant C as Utils
A->>B: Initiate forward operation
B->>C: Prepare input coordinate data
alt If coord is empty
C->>B: Return default xmax
else
C->>B: Calculate xmax
end
B->>C: Reshape tensors with explicit dimensions
C-->>B: Return reshaped tensors
B-->>A: Output results
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional comments not posted (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (1)
deepmd/dpmodel/utils/nlist.py (1)
98-101
: Use a ternary operator for clarity.The conditional check for empty
coord
arrays is logical and improves robustness. Consider using a ternary operator for clarity.- if coord.size > 0: - xmax = np.max(coord) + 2.0 * rcut - else: - xmax = 2.0 * rcut + xmax = np.max(coord) + 2.0 * rcut if coord.size > 0 else 2.0 * rcut
Tools
Ruff
98-101: Use ternary operator
xmax = np.max(coord) + 2.0 * rcut if coord.size > 0 else 2.0 * rcut
instead ofif
-else
-blockReplace
if
-else
-block withxmax = np.max(coord) + 2.0 * rcut if coord.size > 0 else 2.0 * rcut
(SIM108)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
☔ View full report in Codecov by Sentry. |
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Fix #3732. Removes the special codes for `nloc==0` which has been supported by #4005. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved robustness in tensor handling when inputs are empty. - Enhanced test coverage for parameters in the `test_pair_deepmd_si` and `test_pair_deepmd_mpi` functions, testing scenarios with and without balance arguments. - **Bug Fixes** - Adjusted control flow in the `compute` method to simplify handling of zero atoms or local atoms. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
`reshape((0, -1))` is not allowed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved tensor reshaping logic across multiple models to enhance handling of varying input shapes. - Added a new test case to validate functionality when no atoms are present. - **Bug Fixes** - Enhanced error handling for empty coordinate inputs to improve function stability. - **Documentation** - Updated comments and structure for clarity in tensor manipulations across various models. - **Refactor** - Introduced explicit dimension definitions in tensor reshaping to avoid reliance on automatic inference. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Fix deepmodeling#3732. Removes the special codes for `nloc==0` which has been supported by deepmodeling#4005. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved robustness in tensor handling when inputs are empty. - Enhanced test coverage for parameters in the `test_pair_deepmd_si` and `test_pair_deepmd_mpi` functions, testing scenarios with and without balance arguments. - **Bug Fixes** - Adjusted control flow in the `compute` method to simplify handling of zero atoms or local atoms. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
reshape((0, -1))
is not allowedSummary by CodeRabbit
New Features
Bug Fixes
Documentation
Refactor