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

feat: directional nlist #4052

Merged
merged 7 commits into from
Aug 14, 2024
Merged

Conversation

wanghan-iapcm
Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm commented Aug 12, 2024

this pr implement the directional nlist, with which the central and neighboring atoms are treated as different atoms.

Summary by CodeRabbit

  • New Features
    • Introduced a new function for building a directional neighbor list, enhancing detailed neighbor analysis.
  • Bug Fixes
    • Improved handling of neighbor lists, ensuring proper management of virtual atoms and accurate sizing.
  • Tests
    • Added new tests for the directional neighbor list functionality and modified existing tests to cover additional scenarios.

@wanghan-iapcm wanghan-iapcm requested review from njzjz and iProzd August 12, 2024 13:09
Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

Walkthrough

The recent updates significantly enhance neighbor list generation in the codebase. The build_neighbor_list function has been improved to manage virtual atoms more effectively, utilizing a new helper function. Additionally, the introduction of the build_directional_neighbor_list function allows for detailed analysis of neighboring atoms within a specified cutoff distance. The testing suite has been expanded to validate these enhancements, ensuring robustness and flexibility in neighbor list handling.

Changes

Files Change Summary
deepmd/pt/utils/nlist.py Enhanced build_neighbor_list with _trim_mask_distinguish_nlist for better virtual atom management. Introduced build_directional_neighbor_list for detailed directional neighbor analysis.
source/tests/pt/model/test_nlist.py Added test_build_directional_nlist to validate the new directional neighbor list functionality. Modified test_build_notype to evaluate behavior with larger selection sizes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NeighborList
    participant Helper

    User->>NeighborList: Call build_neighbor_list()
    NeighborList->>Helper: Call _trim_mask_distinguish_nlist()
    Helper-->>NeighborList: Return trimmed neighbor list
    NeighborList-->>User: Return neighbor list

    User->>NeighborList: Call build_directional_neighbor_list()
    NeighborList-->>User: Return directional neighbor list
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3c3226e and e255f24.

Files selected for processing (1)
  • deepmd/pt/utils/nlist.py (3 hunks)
Additional comments not posted (2)
deepmd/pt/utils/nlist.py (2)

144-144: Remove unused variable assignment.

The variable nsel is assigned but never used. Consider removing this assignment to clean up the code.


170-172: Verify logic for distinguishing types.

Ensure that the function nlist_distinguish_types correctly handles the logic for distinguishing atom types as intended. This is crucial for maintaining the integrity of the neighbor list when distinguishing types.

Verification successful

Function nlist_distinguish_types correctly handles atom type distinction.

The function processes the neighbor list using PyTorch to distinguish atom types as intended. It employs appropriate tensor operations to maintain the integrity of the list while distinguishing types. No issues found with the implementation.

  • Location: deepmd/pt/utils/nlist.py lines 1-40
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic for distinguishing atom types in `nlist_distinguish_types`.

# Test: Search for the function implementation and its usage. Expect: Correct handling of atom types.
ast-grep --lang python --pattern 'def nlist_distinguish_types($_, $_, $_):'

Length of output: 77


Script:

#!/bin/bash
# Broader search for functions related to distinguishing types in the codebase.
rg 'def ' --context 5 --glob '*.py' | grep 'distinguish'

Length of output: 7082


Script:

#!/bin/bash
# Extract and review the implementation of `nlist_distinguish_types` from `deepmd/pt/utils/nlist.py`.
ast-grep --lang python --pattern 'def nlist_distinguish_types($_, $_, $_):' --after 20 deepmd/pt/utils/nlist.py

Length of output: 113


Script:

#!/bin/bash
# Use ripgrep to search for the function definition and provide more context to ensure its implementation is captured.
rg 'def nlist_distinguish_types' -A 50 deepmd/pt/utils/nlist.py

Length of output: 1493


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.

deepmd/pt/utils/nlist.py Fixed Show fixed Hide fixed
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: 1

deepmd/pt/utils/nlist.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.95%. Comparing base (1a6834d) to head (e255f24).
Report is 157 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/pt/utils/nlist.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4052   +/-   ##
=======================================
  Coverage   82.94%   82.95%           
=======================================
  Files         522      522           
  Lines       51021    51044   +23     
  Branches     3028     3028           
=======================================
+ Hits        42319    42342   +23     
+ Misses       7758     7756    -2     
- Partials      944      946    +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: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com>
@wanghan-iapcm
Copy link
Collaborator Author

crashed env on my local computer, the UTs will be fixed later on

deepmd/pt/utils/nlist.py Outdated Show resolved Hide resolved
wanghan-iapcm and others added 2 commits August 12, 2024 22:01
Co-authored-by: Duo <50307526+iProzd@users.noreply.github.com>
Signed-off-by: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com>
deepmd/pt/utils/nlist.py Outdated Show resolved Hide resolved
@njzjz
Copy link
Member

njzjz commented Aug 12, 2024

What is the purpose of introducing a different neighbor list?

@wanghan-iapcm
Copy link
Collaborator Author

What is the purpose of introducing a different neighbor list?

For the development of charge density models.

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: 0

Outside diff range, codebase verification and nitpick comments (1)
deepmd/pt/utils/nlist.py (1)

183-228: Correct parameter names in the docstring.

The parameter names in the docstring do not match the function signature. Update them for clarity and accuracy.

-    coord_central : torch.Tensor
+    coord_cntl : torch.Tensor
-    atype_central : torch.Tensor
+    atype_cntl : torch.Tensor
-    coord_neighbor : torch.Tensor
+    coord_neig : torch.Tensor
-    atype_central : torch.Tensor
+    atype_neig : torch.Tensor

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: 0

Outside diff range, codebase verification and nitpick comments (1)
deepmd/pt/utils/nlist.py (1)

195-205: Correct parameter names in the docstring.

The parameter names in the docstring do not match the function signature. Ensure that the names are consistent to avoid confusion.

-    coord_central : torch.Tensor
+    coord_cntl : torch.Tensor
-    atype_central : torch.Tensor
+    atype_cntl : torch.Tensor
-    coord_neighbor : torch.Tensor
+    coord_neig : torch.Tensor
-    atype_central : torch.Tensor
+    atype_neig : torch.Tensor

@wanghan-iapcm wanghan-iapcm requested review from njzjz and iProzd August 13, 2024 11:21
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Aug 14, 2024
Merged via the queue into deepmodeling:devel with commit 05323f3 Aug 14, 2024
60 checks passed
@wanghan-iapcm wanghan-iapcm deleted the dir-nlist branch August 14, 2024 02:32
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
this pr implement the directional nlist, with which the central and
neighboring atoms are treated as different atoms.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **New Features**
- Introduced a new function for building a directional neighbor list,
enhancing detailed neighbor analysis.
- **Bug Fixes**
- Improved handling of neighbor lists, ensuring proper management of
virtual atoms and accurate sizing.
- **Tests**
- Added new tests for the directional neighbor list functionality and
modified existing tests to cover additional scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com>
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Duo <50307526+iProzd@users.noreply.github.com>
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