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

feat pt : Support property fitting in `devel` branch #3867

Open Chengqian-Zhang opened 3 weeks ago

Chengqian-Zhang commented 3 weeks ago

Solve issue #3866

Summary by CodeRabbit

coderabbitai[bot] commented 3 weeks ago
Walkthrough ## Walkthrough The recent updates primarily introduce new classes and methods to handle property fitting, property evaluation, and atomic model updates in the DeepMD framework. Significant additions include the `PropertyFittingNet`, `DeepProperty`, and `EnergyModel` classes, modifications to support intensive property handling, and new methods across various files for property evaluation and intensivity checks. ## Changes | Files | Change Summary | |--------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `deepmd/dpmodel/fitting/property_fitting.py` | Added the `PropertyFittingNet` class for property fitting neural networks, introducing initialization, serialization, and deserialization methods. | | `deepmd/dpmodel/output_def.py` | Updated `OutputVariableDef` class to include an `intensive` boolean attribute and its getter method. | | `deepmd/infer/deep_eval.py` | Added mappings for properties and reducing properties, including a new abstract method `get_intensive` in `DeepEvalBackend`. | | `deepmd/infer/deep_property.py` | Introduced the `DeepProperty` class to evaluate properties of structures based on deep learning models. | | `deepmd/pt/model/atomic_model/dp_atomic_model.py` | Added the `get_intensive` method to the `AtomicModel` class. | | `deepmd/pt/model/atomic_model/property_atomic_model.py` | Introduced the `DPPropertyAtomicModel` class with the `get_intensive` method. | | `deepmd/pt/model/model/property_model.py` | Added `PropertyModel` class with methods for forward pass, task dimension retrieval, and determining if the output is intensive. | | `deepmd/pt/train/training.py` | Added import for `PropertyLoss` and handled `loss_type == "property"` condition in `training.py` to create a `PropertyLoss` instance. | | `deepmd/pt/utils/stat.py` | Added `intensive` parameter to `compute_output_stats` and `compute_output_stats_global` functions to indicate intensive or extensive fitting property. | | `examples/property/README.md`, `examples/property/data/data_0/type.raw`, ... | Provided examples and dataset for QM9 property fitting, with files describing labels for properties like `lumo`, `homo`, and `band_gap`. | | `deepmd/pt/model/atomic_model/base_atomic_model.py` | Added check for `intensive` attribute in `fitting_net` for output statistics computation and introduced `get_intensive` method. | | `deepmd/dpmodel/atomic_model/property_atomic_model.py`, `deepmd/dpmodel/model/property_model.py` | Introduced `DPPropertyAtomicModel` and `EnergyModel` classes, including methods for property intensiveness retrieval and model initialization. | | `deepmd/pt/model/model/__init__.py` | Updated import for `PropertyModel`, modified `get_standard_model` logic, and introduced `embed()` call from `IPython`. |

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 79153731279842a48dfc53cc22acae1b72bc788b and 692ac978a46319e2ad48328ea79685b5fb4bd156.
Files selected for processing (4) * deepmd/dpmodel/atomic_model/property_atomic_model.py (1 hunks) * deepmd/dpmodel/model/property_model.py (1 hunks) * deepmd/pt/model/model/__init__.py (2 hunks) * examples/property/README.md (1 hunks)
Files skipped from review as they are similar to previous changes (2) * deepmd/pt/model/model/__init__.py * examples/property/README.md
Additional comments not posted (2)
deepmd/dpmodel/atomic_model/property_atomic_model.py (1)
`16-18`: **Clarify the source of `atomic_output_def()`.** The method `get_intensive` uses `atomic_output_def()` which is not defined in this file or in the parent class as per the provided context. This could lead to a runtime error if not properly implemented.
Verification successful --- **Clarify the source of `atomic_output_def()`.** The method `atomic_output_def` is defined in `deepmd/dpmodel/atomic_model/base_atomic_model.py` and `deepmd/pt/model/atomic_model/base_atomic_model.py`. This indicates that `property_atomic_model.py` likely inherits this method, ensuring it is available and preventing potential runtime errors. - **Locations of `atomic_output_def` definitions:** - `deepmd/dpmodel/atomic_model/base_atomic_model.py` - `deepmd/pt/model/atomic_model/base_atomic_model.py`
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the definition of `atomic_output_def` in the parent class or elsewhere in the codebase. # Test: Search for the method definition. Expect: At least one definition in the codebase. ast-grep --lang python --pattern $'class $$_ { atomic_output_def($$) { $$$ } }' ``` Length of output: 562 --- --- Script: ```shell #!/bin/bash # Description: Verify the definition of `atomic_output_def` in the codebase. # Test: Search for the method definition. Expect: At least one definition in the codebase. ast-grep --lang python --pattern 'def atomic_output_def($$): $$$' ``` Length of output: 67 --- --- Script: ```shell #!/bin/bash # Description: Search for the definition or assignment of `atomic_output_def` in the codebase. # Test: Search for `atomic_output_def` in the codebase, including inheritance and dynamic assignments. rg 'atomic_output_def' -t py ``` Length of output: 4081
deepmd/dpmodel/model/property_model.py (1)
`19-27`: **Check the order and completeness of superclass initializations.** The constructor initializes `DPModelCommon` and `DPPropertyModel_`. However, the order of initialization might not correctly set up the state if the superclasses have overlapping state modifications. Furthermore, the use of positional and keyword arguments in `DPPropertyModel_`'s initialization needs to be verified for correctness.
--- 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 3 weeks ago

Codecov Report

Attention: Patch coverage is 59.24765% with 130 lines in your changes missing coverage. Please review.

Project coverage is 82.58%. Comparing base (949c3b8) to head (692ac97).

Files Patch % Lines
deepmd/entrypoints/test.py 5.97% 63 Missing :warning:
deepmd/pt/loss/property.py 27.08% 35 Missing :warning:
deepmd/dpmodel/model/property_model.py 0.00% 10 Missing :warning:
...epmd/dpmodel/atomic_model/property_atomic_model.py 0.00% 8 Missing :warning:
deepmd/pt/train/training.py 0.00% 5 Missing :warning:
deepmd/pt/utils/stat.py 20.00% 4 Missing :warning:
deepmd/pt/infer/deep_eval.py 71.42% 2 Missing :warning:
deepmd/pt/model/model/__init__.py 33.33% 2 Missing :warning:
...pmd/pt/model/atomic_model/property_atomic_model.py 87.50% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## devel #3867 +/- ## ========================================== - Coverage 82.73% 82.58% -0.15% ========================================== Files 519 527 +8 Lines 50539 50858 +319 Branches 3015 3015 ========================================== + Hits 41812 42001 +189 - Misses 7791 7921 +130 Partials 936 936 ```

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

Chengqian-Zhang commented 2 weeks ago

Lack dp test on property and doc for property fitting. You can review other codes and iterate the code together.

Chengqian-Zhang commented 1 week ago

I notice that in deepmd/dpmodel/model/ener_model.py, the EnergyModel class only implement __init__ method. I do not know why. Currently I only implement __init__ method in class PropertyModel in deepmd/dpmodel/model/property_model.py as well like ener_model.py.