deepmodeling / deepmd-kit

A deep learning package for many-body potential energy representation and molecular dynamics
https://docs.deepmodeling.com/projects/deepmd/
GNU Lesser General Public License v3.0
1.46k stars 504 forks source link

refactor: refactor update_sel and save min_nbor_dist #3829

Closed njzjz closed 4 months ago

njzjz commented 4 months ago

Fix https://github.com/deepmodeling/deepmd-kit/issues/3525. Fix https://github.com/deepmodeling/deepmd-kit/issues/3544.

Summary by CodeRabbit

coderabbitai[bot] commented 4 months ago
Walkthrough ## Walkthrough The changes across multiple files enhance the `update_sel` method by adding parameters for `train_data` and `type_map`, and updating its return type to include a tuple with updated local data and an optional float value. This modification aims to improve neighbor statistics calculations. Additionally, the `UpdateSel.hook` method was removed, affecting the control flow related to saving data to the model. ## Changes | Files | Change Summary | |-------|----------------| | `deepmd/dpmodel/descriptor/dpa1.py`, `deepmd/dpmodel/descriptor/dpa2.py`, `deepmd/dpmodel/descriptor/hybrid.py`, `deepmd/dpmodel/descriptor/make_base_descriptor.py`, `deepmd/dpmodel/descriptor/se_e2_a.py`, `deepmd/dpmodel/descriptor/se_r.py` | Updated `update_sel` method to accept `train_data`, `type_map`, and return a tuple with updated local data and optional float value. | | `deepmd/dpmodel/model/base_model.py`, `deepmd/dpmodel/model/dp_model.py`, `deepmd/dpmodel/model/spin_model.py` | Added `min_nbor_dist` attribute and related methods for model compression. Modified `update_sel` method signature. | | `deepmd/dpmodel/utils/update_sel.py`, `deepmd/pt/utils/update_sel.py` | Removed `hook` method from `UpdateSel` class. | | `deepmd/pt/entrypoints/main.py` | Modified `train` function to handle `min_nbor_dist` and updated model selection and training data processing logic. | | `deepmd/pt/model/descriptor/dpa1.py`, `deepmd/pt/model/descriptor/dpa2.py`, `deepmd/pt/model/descriptor/hybrid.py`, `deepmd/pt/model/descriptor/se_a.py`, `deepmd/pt/model/descriptor/se_r.py`, `deepmd/pt/model/descriptor/se_t.py` | Updated `update_sel` method to accept `train_data`, `type_map`, and return a tuple with updated local data and optional float value. | | `deepmd/pt/model/model/dp_model.py`, `deepmd/pt/model/model/dp_zbl_model.py`, `deepmd/pt/model/model/frozen.py`, `deepmd/pt/model/model/model.py`, `deepmd/pt/model/model/spin_model.py` | Modified `update_sel` method signature and added `min_nbor_dist` related methods. | | `deepmd/pt/utils/serialization.py` | Added serialization and deserialization support for `min_nbor_dist` variable. | | `deepmd/tf/descriptor/descriptor.py`, `deepmd/tf/descriptor/hybrid.py`, `deepmd/tf/descriptor/loc_frame.py`, `deepmd/tf/descriptor/se.py`, `deepmd/tf/descriptor/se_a_mask.py`, `deepmd/tf/descriptor/se_atten.py` | Updated `update_sel` method to accept `train_data`, `type_map`, and return a tuple with updated local data and optional float value. | | `deepmd/tf/entrypoints/compress.py` | Modified `compress` function to retrieve `train_data` and pass it to `update_sel.get_min_nbor_dist`. | ## Assessment against linked issues | Objective | Addressed | Explanation | |-----------|-----------|-------------| | Save to the model in `UpdateSel.hook` (#3525) | ❌ | The `hook` method was removed instead of implementing the save functionality. |

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 27ea21892bc1ab670a7ff227cef22a36b44bdea3 and ecb7b6671c33573480082aae5646e2f4bea0ba3a.
Files selected for processing (4) * deepmd/dpmodel/descriptor/se_t.py (2 hunks) * deepmd/pt/entrypoints/main.py (4 hunks) * deepmd/pt/model/descriptor/se_a.py (2 hunks) * deepmd/pt/model/descriptor/se_t.py (2 hunks)
Files skipped from review due to trivial changes (1) * deepmd/pt/model/descriptor/se_a.py
Files skipped from review as they are similar to previous changes (1) * deepmd/pt/entrypoints/main.py
Additional comments not posted (2)
deepmd/dpmodel/descriptor/se_t.py (1)
`354-382`: Refactor of `update_sel` method aligns with PR objectives. The method now correctly handles the `train_data` and `type_map` parameters to perform neighbor statistics and update selections. The return type has been adjusted to include both the updated local data and the minimum neighbor distance, which is a useful addition for further processing.
deepmd/pt/model/descriptor/se_t.py (1)
`330-358`: Refactor of `update_sel` method aligns with PR objectives. The method now correctly handles the `train_data` and `type_map` parameters to perform neighbor statistics and update selections. The return type has been adjusted to include both the updated local data and the minimum neighbor distance, which is a useful addition for further processing.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 81.68317% with 37 lines in your changes missing coverage. Please review.

Project coverage is 82.62%. Comparing base (8de0aba) to head (ecb7b66). Report is 127 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/dpmodel/descriptor/dpa2.py 28.57% 5 Missing :warning:
deepmd/pt/entrypoints/main.py 58.33% 5 Missing :warning:
deepmd/pt/model/descriptor/dpa2.py 28.57% 5 Missing :warning:
deepmd/tf/model/pairtab.py 40.00% 3 Missing :warning:
deepmd/dpmodel/descriptor/se_r.py 50.00% 2 Missing :warning:
deepmd/dpmodel/descriptor/se_t.py 50.00% 2 Missing :warning:
deepmd/pt/model/descriptor/se_r.py 50.00% 2 Missing :warning:
deepmd/pt/model/descriptor/se_t.py 50.00% 2 Missing :warning:
deepmd/pt/model/model/dp_zbl_model.py 50.00% 2 Missing :warning:
deepmd/pt/utils/serialization.py 50.00% 2 Missing :warning:
... and 6 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## devel #3829 +/- ## ========================================== + Coverage 82.53% 82.62% +0.08% ========================================== Files 515 515 Lines 49492 49563 +71 Branches 2985 2987 +2 ========================================== + Hits 40849 40949 +100 + Misses 7732 7703 -29 Partials 911 911 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

njzjz commented 4 months ago

The UT for the dp model is necessary. or shall we provide consistency test for the behavior of update_sel across backends?

Good idea. The e2e and unit tests are not in conflict.

njzjz commented 4 months ago

We haven't had fixtures for descriptors, though.

njzjz commented 4 months ago

@coderabbitai resolve