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 (pt): Expose Linear Ener Model #4194

Merged
merged 31 commits into from
Oct 11, 2024

Conversation

anyangml
Copy link
Collaborator

@anyangml anyangml commented Oct 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced two new JSON configuration files for linear energy calculations in water simulations.
    • Launched the LinearEnergyModel class for advanced energy and force calculations.
    • Added a parameter for customizable model weighting in the linear energy model.
    • Expanded test suite with new test classes for validating linear energy models.
    • Added new model configurations and test classes to enhance testing capabilities.
  • Bug Fixes

    • Corrected input handling in the deserialization method for version compatibility.
    • Adjusted numerical values in data files for accurate testing.

@anyangml anyangml marked this pull request as draft October 8, 2024 06:18
Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes include the addition of new JSON configuration files for linear energy models and modifications to several Python classes and methods to support these models. Specifically, new configuration files define model parameters, learning rates, loss functions, and training setups. Additionally, a new function get_linear_model was introduced to construct linear energy models, and the LinearEnergyModel class was created to encapsulate the functionality for these models. Various test classes were also added to ensure the correct functionality of the new models and configurations.

Changes

File Path Change Summary
examples/water/d3/input_pt.json New JSON configuration file for linear energy model added.
examples/water/linear/input_pt.json New JSON configuration file for linear energy model added.
deepmd/pt/model/model/init.py Added get_linear_model function and updated get_model to handle model type "linear_ener".
deepmd/pt/model/model/dp_linear_model.py Introduced LinearEnergyModel class with methods for handling linear energy models and their outputs.
deepmd/pt/model/atomic_model/linear_atomic_model.py Added weights parameter to LinearEnergyAtomicModel constructor for model contribution weighting.
source/tests/common/test_examples.py Added new input file paths for testing purposes.
source/tests/universal/common/cases/model/model.py Added LinearEnerModelTest class for testing linear energy models.
source/tests/universal/pt/model/test_model.py Introduced TestLinearEnergyModelPT class to test LinearEnergyModel functionality.
source/tests/pt/model/test_permutation.py Added new models model_linear and model_spin, along with TestEnergyModelSpinSeA class.
source/tests/pt/test_training.py Added TestLinearEnergyModel class for testing linear energy model functionality.
source/tests/pt/model/water/linear_ener.json New JSON configuration file for linear energy model added.
source/tests/pt/model/water/data/d3/dftd3.txt New data file added for testing purposes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Model
    User->>Model: Submit input data
    Model->>Model: Process input with descriptor type "linear_ener"
    Model-->>User: Return processed output
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 576c289 and d3b3342.

📒 Files selected for processing (2)
  • examples/water/linear/input_pt.json (1 hunks)
  • source/tests/common/test_examples.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/tests/common/test_examples.py
🧰 Additional context used
🔇 Additional comments (5)
examples/water/linear/input_pt.json (5)

1-80: Verify intention of duplicate model configurations

The model section is well-structured and aligns with the PR objective of exposing a Linear Energy Model. The configurations for the descriptor and fitting_net appear appropriate for the task.

However, I noticed that there are two identical model configurations in the "models" array. While this could be intentional for ensemble learning or other purposes, it's worth confirming if this duplication is deliberate or if it's an oversight.

Could you please clarify the intention behind having two identical model configurations? If this is intentional, consider adding a comment explaining the purpose of this duplication for better clarity.


81-87: LGTM: Learning rate configuration

The learning rate configuration using an exponential decay strategy is well-defined. The parameters (decay_steps, start_lr, and stop_lr) are clearly specified. This approach is commonly used and can be effective for training neural networks.


88-97: Verify intention of zero volume preference

The loss configuration is well-structured for an energy model, using the "ener" type and including preferences for energy and force components. The use of start and limit preferences allows for dynamic adjustment during training, which is a good practice.

However, I noticed that both start_pref_v and limit_pref_v (volume preferences) are set to 0. While this could be intentional if volume is not a relevant factor in your model, it's worth confirming if this is the desired configuration.

Could you please confirm if setting the volume preference to 0 is intentional? If so, consider adding a comment explaining why volume is not considered in the loss calculation for better clarity.


98-124: Consider clarifying batch size and reviewing number of training steps

The training configuration is comprehensive and well-structured. Using multiple systems for training data is good for model generalization. However, there are two points to consider:

  1. The batch_size for training data is set to "auto". While this can be convenient, it might be helpful to specify what "auto" means in this context or provide a comment explaining how the automatic batch size is determined.

  2. The number of training steps is set to 1,000,000, which seems quite high. Depending on your dataset size and model complexity, this could lead to very long training times or potential overfitting. Consider if this high number of steps is necessary for your use case.

Could you please clarify how the "auto" batch size is determined? Also, have you considered the implications of using such a high number of training steps? If these choices are deliberate based on your specific requirements, consider adding comments to explain the rationale.


1-124: Overall: Well-structured configuration with minor clarifications needed

This configuration file for the linear energy model is comprehensive and well-structured. It aligns well with the PR objective of exposing a Linear Energy Model. The file includes all necessary sections: model parameters, learning rate settings, loss function specifications, and training configurations.

To improve clarity and maintainability, please address the following points:

  1. Clarify the intention behind having two identical model configurations in the "models" array.
  2. Confirm if setting the volume preference to 0 in the loss section is intentional.
  3. Explain how the "auto" batch size is determined for training data.
  4. Review the high number of training steps (1,000,000) and confirm if this is necessary for your use case.

Adding comments to explain these choices will greatly enhance the configuration's readability and help future users understand the rationale behind these decisions.


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>, please review it.
    • 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 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 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 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 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

🧹 Outside diff range and nitpick comments (1)
examples/water/zbl/input.json (1)

Line range hint 1-95: Overall impact of descriptor type change

The change from "se_e2_a" to "se_atten" descriptor type is the only modification in this configuration file. However, this alteration can have a significant impact on the model's behavior, performance, and potentially its results.

Consider the following recommendations:

  1. Document the rationale behind this change in the PR description or commit message.
  2. Ensure comprehensive testing of the model with this new configuration, comparing results with the previous version to understand the impact.
  3. Update any relevant documentation or user guides that might reference the descriptor type.
  4. If this change is part of a larger update or feature addition, make sure all related components and configurations are consistently updated across the project.

Would you like assistance in generating a test plan or documentation updates related to this change?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b807bb4 and e906fac.

📒 Files selected for processing (1)
  • examples/water/zbl/input.json (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
examples/water/zbl/input.json (1)

Line range hint 13-26: Verify descriptor configuration compatibility

With the change of descriptor type to "se_atten", please verify that the other parameters in the descriptor configuration are still appropriate and optimal. Specifically, check the following:

  1. The sel parameter: [46, 92]
  2. The neuron configuration: [25, 50, 100]
  3. Other parameters like rcut, rcut_smth, axis_neuron, etc.

To assist in this verification, let's search for other configurations using the "se_atten" descriptor type:

This will help us compare the current configuration with other instances of "se_atten" usage in the project, if any exist.

examples/water/zbl/input.json Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 63.55932% with 43 lines in your changes missing coverage. Please review.

Project coverage is 83.45%. Comparing base (3939786) to head (d3b3342).
Report is 192 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/pt/model/model/__init__.py 6.06% 31 Missing ⚠️
deepmd/pt/model/model/dp_linear_model.py 86.95% 9 Missing ⚠️
...eepmd/pt/model/atomic_model/linear_atomic_model.py 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4194      +/-   ##
==========================================
- Coverage   83.50%   83.45%   -0.06%     
==========================================
  Files         539      540       +1     
  Lines       52339    52455     +116     
  Branches     3047     3047              
==========================================
+ Hits        43708    43777      +69     
- Misses       7685     7730      +45     
- Partials      946      948       +2     

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

@github-actions github-actions bot added the Python label Oct 8, 2024
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: 8

🧹 Outside diff range and nitpick comments (1)
deepmd/pt/model/model/dp_linear_model.py (1)

143-143: Correct the typographical error in the docstring

There's a typographical error in the docstring for the update_sel method. The word "statictics" should be corrected to "statistics".

Apply this diff to fix the typo:

-    data used to do neighbor statictics
+    Data used to perform neighbor statistics
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e906fac and 7d3044c.

📒 Files selected for processing (3)
  • deepmd/pt/model/atomic_model/linear_atomic_model.py (3 hunks)
  • deepmd/pt/model/model/init.py (3 hunks)
  • deepmd/pt/model/model/dp_linear_model.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
deepmd/pt/model/model/__init__.py (2)

113-113: ⚠️ Potential issue

Validate the weights parameter to prevent unexpected behavior

The weights parameter defaults to "mean" if not specified. To enhance robustness, consider validating the weights value to ensure it meets expected criteria and handling any invalid inputs appropriately.


39-41: Verify the existence and correct import of dp_linear_model and DPLinearModel

The import statement requires the dp_linear_model module and the DPLinearModel class to be present in the package. Ensure that dp_linear_model.py exists in the same directory and that DPLinearModel is defined within it.

Run the following script to confirm:

✅ Verification successful

DPLinearModel import verified successfully

  • dp_linear_model.py exists in deepmd/pt/model/model/.
  • DPLinearModel class is defined within dp_linear_model.py.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that dp_linear_model.py exists and contains the DPLinearModel class.

# Test: Find dp_linear_model.py. Expect: Path to dp_linear_model.py
fd 'dp_linear_model.py' deepmd/pt/model/model/

# Test: Search for the DPLinearModel class definition. Expect: Definition of DPLinearModel class
rg --type py --context 2 'class DPLinearModel' $(fd 'dp_linear_model.py' deepmd/pt/model/model/)

Length of output: 323

deepmd/pt/model/atomic_model/linear_atomic_model.py (3)

51-52: Docstring accurately reflects the new weights parameter

The update to the docstring correctly documents the weights parameter, including its expected types and usage.


59-59: Addition of weights parameter in __init__ method is appropriate

The inclusion of the weights parameter with a default value of "mean" in the constructor enhances the flexibility of the model.


352-373: _compute_weight method correctly computes model weights

The logic in the _compute_weight method effectively handles different types of weights inputs ("sum", "mean", or a list of floats) and computes the weights appropriately for each case.

deepmd/pt/model/model/dp_linear_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_linear_model.py Show resolved Hide resolved
deepmd/pt/model/model/dp_linear_model.py Show resolved Hide resolved
deepmd/pt/model/model/dp_linear_model.py Show resolved Hide resolved
deepmd/pt/model/model/__init__.py Show resolved Hide resolved
deepmd/pt/model/model/__init__.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/__init__.py Outdated Show resolved Hide resolved
@anyangml
Copy link
Collaborator Author

anyangml commented Oct 8, 2024

This PR should resolve #4186

@anyangml anyangml linked an issue Oct 8, 2024 that may be closed by this pull request
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

🧹 Outside diff range and nitpick comments (2)
deepmd/pt/model/model/__init__.py (2)

111-164: LGTM: Implementation of get_linear_model function

The get_linear_model function is well-structured and correctly handles the creation of linear models based on the input parameters. It appropriately manages both descriptor-based models and pair table models.

Consider improving error handling for missing keys

When accessing nested keys in sub_model_params, there's a risk of KeyError if the keys are missing. Consider implementing checks or using dict.get() with default values to prevent potential crashes and provide informative error messages.

Replace assert with explicit exception handling

The assertion for pair table models (lines 144-146) could be replaced with explicit exception handling for improved robustness, especially when Python is run with optimizations.

Consider replacing the assertion with a ValueError:

if "type" not in sub_model_params or sub_model_params["type"] != "pairtab":
    raise ValueError("Sub-models in LinearEnergyModel must be a DPModel or a PairTable Model")

309-310: LGTM: Addition of linear_ener model type

The addition of the "linear_ener" model type and the call to get_linear_model is consistent with the new functionality.

Consider explicit error handling for unknown model types

The current implementation falls back to BaseModel.get_class_by_type(model_type) for unknown types, which may not handle all cases gracefully. Consider adding explicit error handling for unknown model_type values to improve clarity and debuggability.

You could modify the code as follows:

elif model_type == "linear_ener":
    return get_linear_model(model_params)
else:
    raise ValueError(f"Unknown model type: {model_type}")

If BaseModel.get_class_by_type is intended to handle custom model types dynamically, ensure it includes proper error handling and documentation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d3044c and 21580e1.

📒 Files selected for processing (4)
  • deepmd/pt/model/model/init.py (3 hunks)
  • deepmd/pt/model/model/dp_linear_model.py (1 hunks)
  • examples/water/d3/dftd3.txt (1 hunks)
  • examples/water/d3/input_pt.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • examples/water/d3/dftd3.txt
🧰 Additional context used
🔇 Additional comments (9)
examples/water/d3/input_pt.json (5)

1-52: LGTM: Model parameters are well-defined and consistent with PR objectives.

The model configuration is well-structured and includes detailed parameters for both the "se_atten" descriptor and the "pairtab" model. This aligns with the PR title "Feat (pt): Expose Linear Ener Model" and the changes mentioned in the summary.


53-59: LGTM: Learning rate configuration is appropriate.

The learning rate configuration uses exponential decay, which is a good practice for adjusting the learning rate during training. The parameters (decay_steps, start_lr, stop_lr) are well-defined.


60-69: LGTM: Loss function configuration is well-defined.

The loss function configuration is appropriate for an energy model, with preferences for energy and force components.

Please verify if setting both start_pref_v and limit_pref_v to 0 for the volume component is intentional. If volume is not relevant for this model, this is correct; otherwise, you might want to adjust these values.


70-96: LGTM: Training configuration is comprehensive.

The training configuration is well-structured, with separate systems for training and validation, which is a good practice. The number of training steps, display frequency, and save frequency are well-defined.

Could you please clarify what the "auto" batch size means for the training data? It might be helpful to specify how this automatic batch size is determined or provide a default value if the automatic determination fails.


1-96: Overall, the configuration file is well-structured and comprehensive.

This new configuration file for the linear energy model is well-defined and aligns with the PR objectives. It includes all necessary sections (model parameters, learning rate, loss function, and training configuration) with appropriate details. The use of comments throughout the file enhances readability.

A few minor points to consider:

  1. Verify if the volume preference in the loss function (both start and limit set to 0) is intentional.
  2. Clarify what the "auto" batch size means for the training data.

These clarifications will ensure the configuration is fully optimized for your use case.

deepmd/pt/model/model/__init__.py (1)

39-41: LGTM: New import for DPLinearModel

The import statement for DPLinearModel is correctly added and appropriately placed with other model imports.

deepmd/pt/model/model/dp_linear_model.py (3)

35-41: Initialization method is correctly implemented.

The __init__ method properly initializes the superclass with the provided arguments.


60-92: The forward method processes outputs correctly.

The method correctly constructs the model_predict dictionary based on the model outputs and gradient requirements.


93-129: The forward_lower method handles extended inputs appropriately.

The method processes extended coordinates and neighbor lists, constructing the model_predict dictionary accordingly.

deepmd/pt/model/model/dp_linear_model.py Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (1)
source/tests/universal/pt/model/test_model.py (1)

877-882: Remove unused variables dp_model1 and dp_model2

The variables dp_model1 and dp_model2 are assigned but never used. This can lead to unnecessary code clutter and potential confusion. Consider removing these variables if they are not needed.

Apply this diff to remove the unused variables:

-        dp_model1 = DPAtomicModel(
-            ds1,
-            ft1,
-            type_map=cls.expected_type_map,
-        )
-        dp_model2 = DPAtomicModel(
-            ds2,
-            ft2,
-            type_map=cls.expected_type_map,
-        )
🧰 Tools
🪛 Ruff

877-877: Local variable dp_model1 is assigned to but never used

Remove assignment to unused variable dp_model1

(F841)


882-882: Local variable dp_model2 is assigned to but never used

Remove assignment to unused variable dp_model2

(F841)

🪛 GitHub Check: CodeQL

[notice] 877-877: Unused local variable
Variable dp_model1 is not used.


[notice] 882-882: Unused local variable
Variable dp_model2 is not used.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 739670e and 8b1cb8c.

📒 Files selected for processing (2)
  • source/tests/universal/common/cases/model/model.py (1 hunks)
  • source/tests/universal/pt/model/test_model.py (3 hunks)
🧰 Additional context used
🪛 Ruff
source/tests/universal/pt/model/test_model.py

877-877: Local variable dp_model1 is assigned to but never used

Remove assignment to unused variable dp_model1

(F841)


882-882: Local variable dp_model2 is assigned to but never used

Remove assignment to unused variable dp_model2

(F841)


888-888: Undefined name dp_model

(F821)


889-889: Undefined name pt_model

(F821)

🪛 GitHub Check: CodeQL
source/tests/universal/pt/model/test_model.py

[notice] 877-877: Unused local variable
Variable dp_model1 is not used.


[notice] 882-882: Unused local variable
Variable dp_model2 is not used.

🔇 Additional comments (2)
source/tests/universal/common/cases/model/model.py (2)

Line range hint 1-48: Summary: New test class added for LinearEnerModel

The addition of LinearEnerModelTest class expands the test coverage to include the new linear energy model. The class structure and attribute initialization are consistent with other test classes in the file, maintaining the overall design pattern.

To further improve this addition:

  1. Consider adding explanatory comments to clarify the purpose and uniqueness of this test class.
  2. Evaluate if additional test methods specific to linear energy models are needed.
  3. Review if any methods from ModelTestCase need to be overridden for specific linear model testing.

These enhancements will ensure comprehensive testing of the new linear energy model while maintaining code clarity and consistency.


31-47: LGTM! New test class added for LinearEnerModel.

The addition of LinearEnerModelTest class is a good step towards testing the new linear energy model. The class structure and attribute initialization are consistent with other test classes in the file.

Consider adding explanatory comments.

To improve code readability and maintainability, consider adding comments explaining the purpose of this new test class and how it differs from EnerModelTest.

Evaluate the need for additional tests.

While the current setup mirrors EnerModelTest, consider if there are any specific characteristics or edge cases of the linear energy model that might require additional test methods.

Review inherited methods for potential overrides.

Verify if any methods from ModelTestCase need to be overridden to accommodate specific testing requirements for the linear energy model.

source/tests/universal/pt/model/test_model.py Outdated Show resolved Hide resolved
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: 0

🧹 Outside diff range and nitpick comments (1)
source/tests/universal/pt/model/test_model.py (1)

850-850: Consider adjusting the precision for smooth testing

The aprec_dict["test_smooth"] is set to 1e-5, which might be too strict for some cases. Consider adjusting this value if you encounter frequent test failures due to small numerical differences.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8b1cb8c and 63e7017.

📒 Files selected for processing (1)
  • source/tests/universal/pt/model/test_model.py (3 hunks)
🧰 Additional context used
🔇 Additional comments (6)
source/tests/universal/pt/model/test_model.py (6)

22-22: LGTM: New import added for DPLinearModel

The import of DPLinearModel has been correctly added to the list of imports from deepmd.pt.model.model.


47-47: LGTM: New import added for LinearEnerModelTest

The import of LinearEnerModelTest has been correctly added to the list of imports from the common test cases.


810-829: LGTM: Parameterized decorator for TestLinearEnergyModelPT

The parameterized decorator for TestLinearEnergyModelPT is correctly implemented, using appropriate descriptor and fitting parameters for testing.


830-842: LGTM: TestLinearEnergyModelPT class definition and modules_to_test property

The TestLinearEnergyModelPT class is correctly defined, inheriting from unittest.TestCase, LinearEnerModelTest, and PTTestCase. The modules_to_test property is implemented correctly to include script module API testing when appropriate.


877-877: Remove unused variables

The variables dp_model1 and dp_model2 are defined but not used in the current implementation. Consider removing them to improve code clarity.

Also applies to: 882-882


844-903: ⚠️ Potential issue

Potential issue in setUpClass method

The setUpClass method has a potential issue with undefined variables. The variables dp_model1 and dp_model2 are created but not used in the DPLinearModel initialization. Instead, undefined variables dp_model and pt_model are used.

Consider updating the code as follows:

-        cls.module = DPLinearModel(
-            dp_model,
-            pt_model,
-            type_map=cls.expected_type_map,
-        )
+        cls.module = DPLinearModel(
+            [dp_model1, dp_model2],
+            type_map=cls.expected_type_map,
+        )

Also, note that there are unused variables dp_model1 and dp_model2 (lines 877 and 882). Consider removing them if they are not needed elsewhere in the class.

To verify the usage of these variables, run the following script:

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 63e7017 and 0514eae.

📒 Files selected for processing (1)
  • deepmd/pt/model/atomic_model/linear_atomic_model.py (4 hunks)
🧰 Additional context used
🔇 Additional comments (5)
deepmd/pt/model/atomic_model/linear_atomic_model.py (5)

51-52: Documentation of 'weights' parameter is clear

The addition of the weights parameter in the docstring enhances flexibility by allowing users to specify model weighting. The explanation is clear and concise.


59-59: Parameter 'weights' added with appropriate default

The weights parameter is added to the constructor with a default value of "mean", providing sensible default behavior while allowing customization.


95-102: Replace assert statements with explicit exceptions (duplicate comment)

Using assert statements for input validation can be problematic because assertions may be ignored in optimized Python runs (when using the -O flag). It's safer to use explicit exception handling to ensure validations are always enforced. Consider raising exceptions like ValueError instead.


347-350: Type annotations enhance code clarity

Adding type annotations to the _compute_weight method improves code readability and maintainability. This helps with static type checking and better understanding of expected parameter types.


355-382: Weight computation logic is sound

The implementation of _compute_weight correctly handles different types of weights inputs (str and list) and computes the weights accordingly. The use of comprehensions and built-in functions is appropriate.

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

🧹 Outside diff range and nitpick comments (1)
source/tests/universal/pt/model/test_model.py (1)

Line range hint 812-869: Consider diversifying model configurations in setUpClass.

The setUpClass method correctly sets up the testing environment for DPLinearModel. However, consider the following suggestions to enhance the test coverage:

  1. The descriptors ds1 and ds2 are currently identical. Consider using different parameters for each to test how DPLinearModel handles diverse descriptors.
  2. Similarly, ft1 and ft2 are identical. Varying their parameters could provide more comprehensive testing.
  3. As a result, dp_model1 and dp_model2 are currently identical. Creating them with different configurations would better test the capabilities of DPLinearModel in handling diverse atomic models.

Implementing these changes could provide a more robust test suite for DPLinearModel.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0514eae and 000c1c8.

📒 Files selected for processing (1)
  • source/tests/universal/pt/model/test_model.py (6 hunks)
🧰 Additional context used
🔇 Additional comments (4)
source/tests/universal/pt/model/test_model.py (4)

Line range hint 774-796: LGTM: Class definition and parameterization are well-structured.

The TestLinearEnergyModelPT class is properly defined with comprehensive parameterization, covering various descriptor and fitting parameter combinations. This approach ensures thorough testing of the DPLinearModel with different configurations.


Line range hint 797-810: LGTM: modules_to_test property is correctly implemented.

The modules_to_test property is well-implemented, consistently following the pattern used in other test classes. It appropriately includes script modules for testing when available, which enhances the test coverage.


Line range hint 856-870: LGTM: JIT compilation and expected value setup are correct.

The latter part of the setUpClass method correctly sets up JIT compilation for the module and defines the expected values for message passing, dimension parameters, and selection type. This implementation is consistent with other test classes and provides a solid foundation for the tests.


843-854: Resolved: Previously unused variables are now utilized.

The variables dp_model1 and dp_model2, which were flagged as unused in past reviews, are now correctly utilized in creating the DPLinearModel. This resolves the previous issue and improves the overall code quality.

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

🧹 Outside diff range and nitpick comments (1)
source/tests/pt/model/test_permutation.py (1)

Line range hint 247-251: Consider Adding Explicit Spin-Related Assertions in Tests

While the spin parameters are included in the test setup, consider adding specific test methods or assertions that validate spin-related outputs. This will ensure comprehensive coverage of spin functionalities and confirm that spin interactions are correctly handled by the model.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1579a7e and 5b5e948.

📒 Files selected for processing (1)
  • source/tests/pt/model/test_permutation.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
source/tests/pt/model/test_permutation.py (2)

Line range hint 101-137: 'model_spin' Configuration Added Correctly

The model_spin configuration is appropriately defined, extending the existing model configurations to include spin parameters. This addition enhances the testing capabilities for spin functionalities and aligns with the codebase's structure.


Line range hint 247-251: Test Class TestEnergyModelSpinSeA Properly Implements Spin Testing

The test class TestEnergyModelSpinSeA correctly initializes the model with spin parameters and sets self.test_spin = True to enable spin-specific testing within the PermutationTest framework.

examples/water/zbl/input.json Outdated Show resolved Hide resolved
@anyangml anyangml requested a review from njzjz October 10, 2024 02:28
Copy link
Collaborator

@iProzd iProzd left a comment

Choose a reason for hiding this comment

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

Shall we add a linear model example using two dp atomic model?

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.

[BUG] Linear model for pytorch backend
4 participants