Skip to content
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

Merged
merged 3 commits into from
Jul 23, 2024
Merged

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Jul 23, 2024

reshape((0, -1)) is not allowed

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.

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

Walkthrough

The 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

Files Change Summary
deepmd/dpmodel/atomic_model/... Modified tensor reshaping in forward_common_atomic to explicitly calculate output shapes using out_shape2, improving flexibility in handling varying input sizes.
deepmd/dpmodel/descriptor/... Adjusted reshaping logic in call, cal_g, and cal_g_strip methods, using specific dimensions rather than automatic inference to enhance clarity and correctness.
deepmd/dpmodel/utils/nlist.py Added checks for empty coord arrays, modifying xmax calculation and ensuring coord reshaping aligns with batch_size, improving robustness against edge cases.
deepmd/pt/model/... Similar reshaping improvements for rot_mat and other tensor variables in multiple files, ensuring explicit size definitions rather than relying on -1 for inference.
deepmd/pt/utils/nlist.py Added conditional checks for empty tensors, ensuring robust handling of input data and maintaining dimensionality for reshaping operations.
source/tests/universal/common/cases/... Introduced test_zero_forward to validate functionality under zero atom conditions, expanding test coverage for edge cases in forward operations.

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
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29c1b58 and 747e1c9.

Files selected for processing (1)
  • source/tests/universal/common/cases/model/utils.py (1 hunks)
Additional comments not posted (1)
source/tests/universal/common/cases/model/utils.py (1)

224-326: LGTM! Ensure the function is used appropriately.

The code changes are approved.

However, ensure that all necessary function calls to test_zero_forward are present in the test suite.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 of if-else-block

Replace if-else-block with xmax = np.max(coord) + 2.0 * rcut if coord.size > 0 else 2.0 * rcut

(SIM108)

source/tests/universal/common/cases/model/utils.py Outdated Show resolved Hide resolved
deepmd/pt/model/descriptor/se_r.py Show resolved Hide resolved
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.84%. Comparing base (8116297) to head (747e1c9).

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4005   +/-   ##
=======================================
  Coverage   82.83%   82.84%           
=======================================
  Files         522      522           
  Lines       50901    50920   +19     
  Branches     3015     3015           
=======================================
+ Hits        42165    42183   +18     
+ Misses       7799     7798    -1     
- Partials      937      939    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
@iProzd iProzd added this pull request to the merge queue Jul 23, 2024
Merged via the queue into deepmodeling:devel with commit a6ea2c1 Jul 23, 2024
60 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Jul 26, 2024
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>
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
`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>
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants