Skip to content

Conversation

@iProzd
Copy link
Collaborator

@iProzd iProzd commented May 21, 2025

Summary by CodeRabbit

  • New Features

    • Added an option to use an exponential switch function for neighbor updates in descriptors, providing a smoother decay of neighbor contributions near cutoff distances. This is enabled via a new parameter across multiple descriptor components.
  • Documentation

    • Updated parameter documentation to describe the exponential switch function, its mathematical definition, and recommended smoothing parameters.
  • Tests

    • Enhanced test suites to cover the new exponential switch option, verifying consistent behavior and integration across different configurations.
  • Improvements

    • Included environment protection parameter in serialization of environment matrices across several descriptor classes for more complete state representation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 21, 2025

Warning

Rate limit exceeded

@iProzd has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 11a8e48 and a574ac3.

📒 Files selected for processing (1)
  • deepmd/utils/argcheck.py (2 hunks)
📝 Walkthrough

"""

Walkthrough

A new boolean parameter use_exp_switch was introduced across descriptor and environment matrix components to enable an exponential switch function for neighbor updates as an alternative to the existing polynomial switch. This parameter is now configurable, serialized, and integrated into both the main codebase and associated tests, with updated function signatures and documentation.

Changes

File(s) Change Summary
deepmd/dpmodel/descriptor/dpa3.py, deepmd/pt/model/descriptor/dpa3.py Added use_exp_switch parameter to RepFlowArgs and propagated it to DescrptBlockRepflows initialization and serialization.
deepmd/dpmodel/descriptor/repflows.py, deepmd/pt/model/descriptor/repflows.py Added use_exp_switch parameter to DescrptBlockRepflows class and constructor; integrated into environment matrix instantiation and forward pass.
deepmd/dpmodel/utils/env_mat.py, deepmd/pt/model/descriptor/env_mat.py Introduced compute_exp_sw function for exponential switch; updated environment matrix functions/classes to accept and use use_exp_switch.
deepmd/pt/utils/preprocess.py Added new function compute_exp_sw for exponential switch computation with validation and clamping.
deepmd/utils/argcheck.py Added use_exp_switch (alias: use_env_envelope) argument to dpa3_repflow_args with documentation.
source/tests/consistent/descriptor/test_dpa3.py Extended tests to parameterize and handle use_exp_switch, updated skip logic and data propagation.
source/tests/universal/dpmodel/descriptor/test_descriptor.py Added use_exp_switch parameter to DescriptorParamDPA3 and included in test parameterization.
deepmd/pd/model/descriptor/dpa1.py, deepmd/pd/model/descriptor/se_a.py Updated serialization of environment matrix to include env_protection parameter in DPEnvMat construction.
deepmd/pt/model/descriptor/dpa1.py, deepmd/pt/model/descriptor/se_a.py, deepmd/pt/model/descriptor/se_t.py Updated serialization of environment matrix to include env_protection parameter in DPEnvMat construction.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RepFlowArgs
    participant DescrptBlockRepflows
    participant EnvMat
    participant EnvMatUtils

    User->>RepFlowArgs: Initialize (use_exp_switch)
    RepFlowArgs->>DescrptBlockRepflows: Pass use_exp_switch
    DescrptBlockRepflows->>EnvMat: Initialize (use_exp_switch)
    EnvMat->>EnvMatUtils: Compute environment matrix (use_exp_switch)
    EnvMatUtils->>EnvMatUtils: Select switch function (exp or polynomial)
    EnvMatUtils-->>EnvMat: Return environment matrix
    EnvMat-->>DescrptBlockRepflows: Return EnvMat instance
    DescrptBlockRepflows-->>User: Descriptor ready
Loading

Suggested reviewers

  • wanghan-iapcm
  • njzjz
  • iProzd
    """
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (1)
deepmd/pt/model/descriptor/env_mat.py (1)

61-61: Add more context to the parameter documentation.

The current description is minimal. Consider enhancing the documentation to explain the difference between the two switch functions and when one might be preferred over the other.

-    - use_exp_switch: Whether to use the exponential switch function.
+    - use_exp_switch: Whether to use the exponential switch function instead of the polynomial one.
+      The exponential switch provides a sharper transition and may be preferred for systems 
+      where a more distinct cutoff boundary is desired.

Also applies to: 74-74

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8176173 and 3d1071c.

📒 Files selected for processing (10)
  • deepmd/dpmodel/descriptor/dpa3.py (5 hunks)
  • deepmd/dpmodel/descriptor/repflows.py (5 hunks)
  • deepmd/dpmodel/utils/env_mat.py (5 hunks)
  • deepmd/pt/model/descriptor/dpa3.py (1 hunks)
  • deepmd/pt/model/descriptor/env_mat.py (6 hunks)
  • deepmd/pt/model/descriptor/repflows.py (5 hunks)
  • deepmd/pt/utils/preprocess.py (1 hunks)
  • deepmd/utils/argcheck.py (2 hunks)
  • source/tests/consistent/descriptor/test_dpa3.py (10 hunks)
  • source/tests/universal/dpmodel/descriptor/test_descriptor.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
deepmd/pt/model/descriptor/env_mat.py (1)
deepmd/pt/utils/preprocess.py (2)
  • compute_exp_sw (20-29)
  • compute_smooth_weight (9-17)
deepmd/dpmodel/descriptor/repflows.py (1)
deepmd/dpmodel/utils/env_mat.py (1)
  • EnvMat (101-189)
deepmd/dpmodel/utils/env_mat.py (3)
deepmd/dpmodel/array_api.py (1)
  • support_array_api (11-35)
deepmd/pt/utils/preprocess.py (2)
  • compute_exp_sw (20-29)
  • compute_smooth_weight (9-17)
deepmd/pt/model/descriptor/env_mat.py (1)
  • _make_env_mat (11-48)
deepmd/pt/utils/preprocess.py (1)
deepmd/dpmodel/utils/env_mat.py (1)
  • compute_exp_sw (39-53)
⏰ Context from checks skipped due to timeout of 90000ms (29)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Analyze (python)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Build C library (2.14, >=2.5.0rc0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (cpu, cpu)
🔇 Additional comments (32)
deepmd/pt/model/descriptor/dpa3.py (1)

153-153: LGTM! Added use_exp_switch parameter successfully.

The parameter is correctly passed from self.repflow_args to the DescrptBlockRepflows initialization, maintaining consistency with other similar parameters.

source/tests/universal/dpmodel/descriptor/test_descriptor.py (3)

485-485: LGTM! Added use_exp_switch parameter with appropriate default value.

The default value of False ensures backward compatibility with existing code.


507-507: LGTM! Parameter propagation to RepFlowArgs is correct.

The parameter is properly passed to the RepFlowArgs constructor.


545-545: LGTM! Test parameterization ensures coverage of both options.

Including both True and False values ensures the tests will verify the behavior of both switch function implementations.

deepmd/pt/model/descriptor/env_mat.py (4)

6-7: LGTM! Import statement for compute_exp_sw added correctly.

The function is imported alongside the existing compute_smooth_weight function.


18-18: LGTM! Parameter added to _make_env_mat with correct default value.

The default value of False maintains backward compatibility.


38-42: LGTM! Conditional logic for switching between functions is clear and concise.

The code cleanly uses a conditional expression to determine which switch function to use.


87-87: LGTM! Parameter propagation is handled correctly.

The use_exp_switch parameter is properly forwarded to the _make_env_mat function.

deepmd/dpmodel/descriptor/repflows.py (6)

125-134: Well-documented parameter with clear explanations

The docstring for the use_exp_switch parameter is comprehensive and provides:

  • A clear explanation of the parameter's purpose
  • The mathematical definition of the exponential switch function
  • Recommended parameter values for different cutoff radii
  • Guidance on selecting appropriate rcut_smth values

This documentation helps users understand how to properly configure the feature.


183-183: LGTM: Parameter added with backward compatibility

The use_exp_switch parameter is correctly added with a default value of False, which ensures backward compatibility with existing code.


215-215: LGTM: Parameter properly stored as instance attribute

The parameter value is correctly stored as an instance attribute, following the same pattern as other parameters.


276-280: LGTM: Parameter correctly passed to EnvMat for edge calculations

The use_exp_switch parameter is properly propagated to the edge environment matrix.


281-286: LGTM: Parameter correctly passed to EnvMat for angle calculations

The use_exp_switch parameter is properly propagated to the angle environment matrix.


598-598: LGTM: Parameter included in serialization

The use_exp_switch parameter is correctly added to the serialized dictionary, ensuring it's preserved when the object is serialized and deserialized.

deepmd/utils/argcheck.py (2)

1500-1510: Well-documented new parameter for exponential switch function.

The documentation for use_exp_switch is comprehensive, clearly explaining the purpose, mathematical form, and recommended usage of the exponential switch function. It includes recommended values for the smoothing factor based on different cutoff radii.


1611-1618: Proper implementation of the exponential switch parameter.

The implementation of the new use_exp_switch parameter follows the established pattern of this codebase. The parameter is optional with a default of False to maintain backward compatibility, and includes an appropriate alias "use_env_envelope".

deepmd/dpmodel/descriptor/dpa3.py (5)

126-135: Well-documented parameter addition.

The documentation for the use_exp_switch parameter is comprehensive and helpful. It clearly explains what the parameter does, how the exponential switch function works, and provides guidance on choosing appropriate parameter values for different cutoff radii.


163-163: LGTM! Parameter declaration with appropriate default.

The parameter is added with a default value of False, which ensures backward compatibility with existing code.


190-190: LGTM! Proper instance attribute assignment.

The parameter is correctly stored as an instance attribute.


222-222: LGTM! Parameter included in serialization.

The parameter is correctly added to the serialized data dictionary.


319-319: LGTM! Parameter correctly passed to downstream component.

The parameter is properly passed from RepFlowArgs to DescrptBlockRepflows.

deepmd/pt/model/descriptor/repflows.py (4)

136-145: Consistent documentation across implementations.

The documentation for the use_exp_switch parameter matches the one in dpa3.py, providing a clear and consistent explanation of the feature across different parts of the codebase.


196-196: LGTM! Parameter declaration with appropriate default value.

The parameter is added with a default value of False, maintaining consistency with the implementation in dpa3.py.


229-229: LGTM! Proper instance attribute assignment.

The parameter is correctly stored as an instance attribute.


411-411: LGTM! Parameter correctly passed to environment matrix calculations.

The use_exp_switch parameter is passed to both edge and angle neighbor environment matrix calculations, ensuring consistent application of the selected switch function throughout the model.

Also applies to: 448-448

source/tests/consistent/descriptor/test_dpa3.py (3)

68-68: LGTM! Test parameterization for new feature.

The test parameterization now includes both True and False values for use_exp_switch, ensuring the feature is properly tested in both configurations.


84-84: LGTM! Parameter correctly included in test data.

The use_exp_switch parameter is properly unpacked and passed to the RepFlowArgs constructor in the test data.

Also applies to: 108-108


159-160: Appropriate test skipping for unsupported backend.

Tests are correctly skipped for the PD backend when use_exp_switch is True, as this feature is not yet supported in that backend.

deepmd/dpmodel/utils/env_mat.py (4)

38-54: Well-implemented exponential switch function.

The exponential switch function is implemented with appropriate parameter validation, follows the mathematical formula described in the documentation, and is consistent with the implementation in the PyTorch version of the code.


88-92: Clean conditional selection of switch function.

The code elegantly selects between the polynomial and exponential switch functions based on the use_exp_switch parameter, maintaining a clear structure.


107-107: LGTM! Parameter integration with EnvMat class.

The use_exp_switch parameter is properly integrated into the EnvMat class constructor, stored as an instance attribute, and passed to the _make_env_mat function.

Also applies to: 112-112, 170-170


181-181: LGTM! Parameter included in serialization.

The use_exp_switch parameter is correctly added to the serialized data dictionary of the EnvMat class.

@iProzd iProzd requested review from njzjz and wanghan-iapcm May 22, 2025 14:55
@codecov
Copy link

codecov bot commented May 22, 2025

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.78%. Comparing base (95ca4ad) to head (a574ac3).
⚠️ Report is 81 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/dpmodel/utils/env_mat.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4756   +/-   ##
=======================================
  Coverage   84.78%   84.78%           
=======================================
  Files         698      698           
  Lines       67709    67734   +25     
  Branches     3542     3540    -2     
=======================================
+ Hits        57408    57430   +22     
- Misses       9170     9171    +1     
- Partials     1131     1133    +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wanghan-iapcm wanghan-iapcm enabled auto-merge May 26, 2025 02:57
iProzd and others added 2 commits May 26, 2025 13:33
Signed-off-by: Duo <50307526+iProzd@users.noreply.github.com>
a_compress_e_rate,
a_compress_use_split,
optim_update,
use_exp_switch,

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable use_exp_switch is not used.
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue May 26, 2025
Merged via the queue into deepmodeling:devel with commit 75b175b May 26, 2025
60 checks passed
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