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.41k stars 487 forks source link

[r2] fix seeds in se_a and se_atten (#3880) #3947

Closed njzjz closed 1 week ago

njzjz commented 1 week ago

Summary by CodeRabbit

These changes ensure more reliable descriptor computations and improved test accuracy.


(cherry picked from commit 0c472d1596ae24b5b548ae6ae38688dbab911de5)

coderabbitai[bot] commented 1 week ago
Walkthrough ## Walkthrough This update primarily addresses issues with seed handling in the `deepmd` descriptor and attention modules. Specifically, seed incrementation logic was added to multiple functions in response to certain conditions. Additionally, several tests were modified to reflect new expected values due to the changed seed handling logic. ## Changes | File | Change Summary | |----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------| | `deepmd/descriptor/se_a.py` | Added logic to increment `self.seed` by `self.seed_shift` under certain conditions; renamed return variable and modified return logic | | `deepmd/descriptor/se_atten.py` | Added conditional seed incrementation within `_attention_layers` and `_filter_lower` functions | | `source/tests/test_model_se_a_ebd_v2.py` | Updated `refe`, `reff`, and `refv` arrays' values in the `test_model` function | | `source/tests/test_pairwise_dprc.py` | Modified expected values in `test_model_ener` method to `4.82969` and `-0.104339` | ## Assessment against linked issues | Objective (Issue Number) | Addressed | Explanation | |--------------------------------------------------------------------|-----------|------------------------------------| | Ensure seeds of descriptor/fitting in dpmodel are passed to network (#3799) | ✅ | |

[!TIP]

AI model upgrade ## `gpt-4o` model for reviews and chat is now live OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our [Discord Community](https://discord.com/invite/GsXnASn26c) to provide any feedback or to report any issues.

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between a85d58f71911e97fcb06605a7b9e5df58b5a0ec2 and e4ae74bf949fc35562ffb22809622eebc43fac37.
Files selected for processing (4) * deepmd/descriptor/se_a.py (3 hunks) * deepmd/descriptor/se_atten.py (8 hunks) * source/tests/test_model_se_a_ebd_v2.py (1 hunks) * source/tests/test_pairwise_dprc.py (1 hunks)
Additional comments not posted (15)
source/tests/test_model_se_a_ebd_v2.py (3)
`142-142`: **Verify the updated reference value for `refe`.** Ensure that the new value `[6.100037044296185e-01]` is correct and consistent with the expected results. --- `144-161`: **Verify the updated reference values for `reff`.** Ensure that the new values are correct and consistent with the expected results. --- `164-172`: **Verify the updated reference values for `refv`.** Ensure that the new values are correct and consistent with the expected results.
source/tests/test_pairwise_dprc.py (2)
`522-522`: **Verify the updated expected value for `e[0]`.** Ensure that the new value `4.82969` is correct and consistent with the expected results. --- `523-523`: **Verify the updated expected value for `f[0, 0]`.** Ensure that the new value `-0.104339` is correct and consistent with the expected results.
deepmd/descriptor/se_a.py (3)
`1034-1035`: **LGTM! Conditional increment of the seed.** The seed is incremented correctly based on the conditions. --- Line range hint `1047-1067`: **LGTM! Correct parameters passed to `filter_lower_R42GR`.** The function call includes the necessary parameters including the newly added `self.seed`, `self.seed_shift`, and `self.uniform_seed`. --- `1065-1066`: **LGTM! Conditional increment of the seed.** The seed is incremented correctly based on the conditions.
deepmd/descriptor/se_atten.py (7)
`962-963`: **Conditional seed increment.** The increment of `self.seed` ensures that each layer has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`. --- `977-978`: **Conditional seed increment.** The increment of `self.seed` ensures that each layer has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`. --- `992-993`: **Conditional seed increment.** The increment of `self.seed` ensures that each layer has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`. --- `1026-1027`: **Conditional seed increment.** The increment of `self.seed` ensures that each layer has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`. --- `1091-1092`: **Conditional seed increment.** The increment of `self.seed` ensures that each filter has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`. --- `1132-1133`: **Conditional seed increment.** The increment of `self.seed` ensures that each filter has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`. --- `1191-1192`: **Conditional seed increment.** The increment of `self.seed` ensures that each filter has a different seed when `self.uniform_seed` is `False` and `self.seed` is not `None`.
--- 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 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.51%. Comparing base (a85d58f) to head (e4ae74b).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## r2 #3947 +/- ## ======================================= Coverage 81.50% 81.51% ======================================= Files 342 342 Lines 33865 33882 +17 Branches 2872 2876 +4 ======================================= + Hits 27601 27618 +17 Misses 5381 5381 Partials 883 883 ```

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