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(dp/pt): refactor se_e3 descriptor #3813

Merged
merged 16 commits into from
May 30, 2024
Merged

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented May 23, 2024

Note:

  1. exclude_types is supported only for pt/dp.
  2. Note that an exsiting bug in TF is fixed in deepmd/tf/env.py, when resnet_dt is True for se_e3.

Summary by CodeRabbit

  • New Features

    • Introduced DescrptSeT class for DeepPot-SE descriptor with enhanced atomic configuration handling.
    • Added DescrptBlockSeT class for descriptor block functionality.
  • Improvements

    • Enhanced parameter management and serialization methods in descriptor classes.
    • Added env_protection parameter for better environmental control.
  • Bug Fixes

    • Improved method signatures for better consistency and error handling.
  • Tests

    • Added comprehensive test cases for DescrptSeT class across different deep learning frameworks.
    • Included consistency checks and JIT compilation tests.

Copy link

coderabbitai bot commented May 23, 2024

Walkthrough

The recent changes introduce a new class DescrptSeT across multiple files, representing a DeepPot-SE descriptor for atomic configurations. This class incorporates angular and radial information, provides methods for computing descriptors, managing parameters, serialization, and updating selections for neighbor statistics. Additionally, test cases for consistency and JIT compilation have been added, and the env_protection parameter has been integrated into the descriptor initialization and related methods.

Changes

Files/Groups Change Summary
deepmd/dpmodel/descriptor/se_t.py, deepmd/pt/model/descriptor/se_t.py, deepmd/tf/descriptor/se_t.py Introduced DescrptSeT class with methods for descriptor computation, parameter management, serialization, and updating selections. Added env_protection parameter in the __init__ method.
deepmd/pt/model/descriptor/se_a.py Modified __init__ method to include trainable parameter and removed ntypes and **kwargs. Added logic to raise NotImplementedError if spin is not None.
source/tests/pt/model/test_se_t.py Added test cases for DescrptSeT functionality, including consistency checks and JIT compilation testing.
source/tests/consistent/descriptor/test_se_t.py Introduced test cases for DescrptSeT descriptor class across different deep learning frameworks, ensuring consistency across frameworks.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant DescrptSeT
    participant DeepPot-SE Frameworks

    User->>DescrptSeT: Initialize with parameters
    DescrptSeT->>DeepPot-SE Frameworks: Compute descriptor
    DeepPot-SE Frameworks-->>DescrptSeT: Return descriptor
    DescrptSeT-->>User: Provide descriptor

Possibly related issues


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 Configration 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

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@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: 13

Outside diff range and nitpick comments (3)
source/tests/pt/model/test_se_e2_a.py (2)

Line range hint 59-105: The test_consistency method is well-implemented, covering various configurations for the descriptor. However, consider removing unused variables such as idt, prec, and em to clean up the code.

- for idt, prec, em in itertools.product(
+ for _, _, _ in itertools.product(

Line range hint 107-134: The test_jit method correctly tests JIT compilation. However, the variable model is redundantly assigned twice. Consider simplifying this.

- model = torch.jit.script(dd0)
- model = torch.jit.script(dd1)
+ model = torch.jit.script(dd1)
deepmd/tf/descriptor/se_t.py (1)

758-759: Clarify the requirement for ndim to be 2 in the documentation.

The requirement for ndim to be 2 is enforced via an assertion in the serialize_network method. It would be beneficial for maintainability and clarity to mention this requirement in the method's documentation.

deepmd/dpmodel/descriptor/se_t.py Show resolved Hide resolved
deepmd/dpmodel/descriptor/se_t.py Show resolved Hide resolved
deepmd/dpmodel/descriptor/se_t.py Show resolved Hide resolved
deepmd/pt/model/descriptor/se_t.py Outdated Show resolved Hide resolved
deepmd/pt/model/descriptor/se_t.py Show resolved Hide resolved
deepmd/tf/descriptor/se_t.py Outdated Show resolved Hide resolved
deepmd/pt/model/descriptor/se_t.py Show resolved Hide resolved
deepmd/tf/descriptor/se_t.py Outdated Show resolved Hide resolved
source/tests/pt/model/test_se_t.py Show resolved Hide resolved
source/tests/consistent/descriptor/test_se_t.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 23, 2024

Codecov Report

Attention: Patch coverage is 82.74336% with 78 lines in your changes are missing coverage. Please review.

Project coverage is 82.53%. Comparing base (dd7f27a) to head (0ac65d6).

Files Patch % Lines
deepmd/pt/model/descriptor/se_t.py 78.24% 47 Missing ⚠️
deepmd/dpmodel/descriptor/se_t.py 85.92% 19 Missing ⚠️
deepmd/tf/descriptor/se_t.py 88.29% 11 Missing ⚠️
deepmd/pt/model/descriptor/se_a.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            devel    #3813    +/-   ##
========================================
  Coverage   82.53%   82.53%            
========================================
  Files         513      515     +2     
  Lines       49040    49492   +452     
  Branches     2985     2985            
========================================
+ Hits        40473    40849   +376     
- Misses       7656     7732    +76     
  Partials      911      911            

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

deepmd/tf/descriptor/se_t.py Outdated Show resolved Hide resolved
examples/water/se_e3/input_torch.json Outdated Show resolved Hide resolved
iProzd and others added 4 commits May 27, 2024 14:06
Co-authored-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Duo <50307526+iProzd@users.noreply.github.com>
Copy link

@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/model/descriptor/se_a.py Outdated Show resolved Hide resolved
@njzjz njzjz linked an issue May 27, 2024 that may be closed by this pull request
@iProzd
Copy link
Collaborator Author

iProzd commented May 28, 2024

A UT is needed for testing consistency between results using exclude_types and results from masked nlist. I opened an issue #3830 and a seperate PR needed, after finding inconsistencies in some of the existing descriptors.

data.pop("type", None)
variables = data.pop("@variables")
embeddings = data.pop("embeddings")
env_mat = data.pop("env_mat")

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable env_mat is not used.
data.pop("type", None)
variables = data.pop("@variables")
embeddings = data.pop("embeddings")
env_mat = data.pop("env_mat")

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable env_mat is not used.
@property
def skip_pt(self) -> bool:
(
resnet_dt,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable resnet_dt is not used.
def skip_pt(self) -> bool:
(
resnet_dt,
excluded_types,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable excluded_types is not used.
(
resnet_dt,
excluded_types,
precision,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable precision is not used.
# TF se_e2_a type_one_side=False requires atype sorted
(
resnet_dt,
excluded_types,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable excluded_types is not used.
(
resnet_dt,
excluded_types,
precision,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable precision is not used.
resnet_dt,
excluded_types,
precision,
env_protection,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable env_protection is not used.
dd0.seat.mean = torch.tensor(davg, dtype=dtype, device=env.DEVICE)
dd0.seat.dstd = torch.tensor(dstd, dtype=dtype, device=env.DEVICE)
dd1 = DescrptSeT.deserialize(dd0.serialize())
model = torch.jit.script(dd0)

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'model' is unnecessary as it is
redefined
before this value is used.
dd0.seat.dstd = torch.tensor(dstd, dtype=dtype, device=env.DEVICE)
dd1 = DescrptSeT.deserialize(dd0.serialize())
model = torch.jit.script(dd0)
model = torch.jit.script(dd1)

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'model' is unnecessary as it is
redefined
before this value is used.
@iProzd iProzd requested a review from njzjz May 28, 2024 14:16
@iProzd iProzd requested a review from wanghan-iapcm May 28, 2024 14:16
@iProzd iProzd requested a review from njzjz May 29, 2024 06:16
@iProzd iProzd enabled auto-merge May 29, 2024 07:45
@iProzd iProzd added this pull request to the merge queue May 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2024
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@iProzd iProzd added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@njzjz njzjz added this pull request to the merge queue May 30, 2024
Merged via the queue into deepmodeling:devel with commit 8de0aba May 30, 2024
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] pt: support se_e3 in the PyTorch backend
3 participants