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

Fix: always output weighted average error #4401

Merged
merged 4 commits into from
Nov 22, 2024

Conversation

caic99
Copy link
Member

@caic99 caic99 commented Nov 22, 2024

This PR makes all dp test result output the "weighted average of errors" part. It would be better for post-processing tools to handle the output data.

Summary by CodeRabbit

  • New Features

    • Introduced support for the DeepWFC model, enhancing the functionality of the testing framework.
  • Bug Fixes

    • Improved error reporting by streamlining the handling of the DeepGlobalPolar model, ensuring consistent logging of average errors for all models.
  • Refactor

    • Simplified control flow by removing redundant conditional checks related to the DeepGlobalPolar model.
    • Enhanced clarity of output by repositioning logging statements for average errors to execute unconditionally.
    • Updated import statements for better organization and consistency.

Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request focus on the test function within the deepmd/entrypoints/test.py file. The modifications incorporate the DeepWFC model and adjust the handling of the DeepGlobalPolar model, which is now deprecated and triggers a warning when encountered. Logging of average errors has been restructured to execute unconditionally for all models, enhancing consistency in error reporting. Additionally, import statements have been updated, and minor formatting adjustments have been made to maintain code style consistency.

Changes

File Change Summary
deepmd/entrypoints/test.py Added handling for DeepWFC in the test function; adjusted handling of DeepGlobalPolar with a warning for deprecation. Logging of average errors is now unconditional. Minor formatting adjustments made for consistency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestFunction
    participant DeepGlobalPolar
    participant DeepWFC
    participant OtherModels

    User->>TestFunction: Initiate test
    TestFunction->>DeepGlobalPolar: Process system
    DeepGlobalPolar-->>TestFunction: Return results
    TestFunction->>DeepWFC: Process system
    DeepWFC-->>TestFunction: Return results
    TestFunction->>OtherModels: Process system
    OtherModels-->>TestFunction: Return results
    TestFunction->>TestFunction: Calculate weighted averages
    TestFunction->>User: Log weighted averages
Loading

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d1712c9 and b77b895.

📒 Files selected for processing (1)
  • deepmd/entrypoints/test.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
deepmd/entrypoints/test.py

195-198: Combine if branches using logical or operator

Combine if branches

(SIM114)

🔇 Additional comments (1)
deepmd/entrypoints/test.py (1)

185-196: LGTM! The error logging structure is consistent.

The changes ensure consistent logging of weighted averages across different model types.

deepmd/entrypoints/test.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 22, 2024

Codecov Report

Attention: Patch coverage is 72.22222% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.64%. Comparing base (d1712c9) to head (3b9ce65).
Report is 1 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/entrypoints/test.py 72.22% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4401      +/-   ##
==========================================
+ Coverage   84.59%   84.64%   +0.05%     
==========================================
  Files         614      614              
  Lines       57009    57007       -2     
  Branches     3486     3487       +1     
==========================================
+ Hits        48224    48254      +30     
+ Misses       7660     7627      -33     
- Partials     1125     1126       +1     

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


🚨 Try these New Features:

Signed-off-by: Chun Cai <amoycaic@gmail.com>
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)
deepmd/entrypoints/test.py (1)

195-198: Combine similar conditions for better maintainability.

The conditions for DeepPolar and DeepGlobalPolar can be combined since they use the same print function.

Apply this diff to combine the conditions:

-    elif isinstance(dp, DeepPolar):
-        print_polar_sys_avg(avg_err)
-    elif isinstance(dp, DeepGlobalPolar):
-        print_polar_sys_avg(avg_err)
+    elif isinstance(dp, (DeepPolar, DeepGlobalPolar)):
+        print_polar_sys_avg(avg_err)
🧰 Tools
🪛 Ruff (0.7.0)

195-198: Combine if branches using logical or operator

Combine if branches

(SIM114)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b77b895 and df7121d.

📒 Files selected for processing (1)
  • deepmd/entrypoints/test.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
deepmd/entrypoints/test.py

195-198: Combine if branches using logical or operator

Combine if branches

(SIM114)

🔇 Additional comments (1)
deepmd/entrypoints/test.py (1)

199-200: ⚠️ Potential issue

Verify DeepWFC import for runtime usage.

DeepWFC is imported conditionally with TYPE_CHECKING, but it's used in runtime code. This could lead to runtime errors.

Let's verify the import setup:

Consider moving the import outside the TYPE_CHECKING block if the class is needed at runtime:

-if TYPE_CHECKING:
-    from deepmd.infer.deep_wfc import (
-        DeepWFC,
-    )
+from deepmd.infer.deep_wfc import (
+    DeepWFC,
+)

@caic99 caic99 requested a review from njzjz November 22, 2024 08:40
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)
deepmd/entrypoints/test.py (1)

Line range hint 1018-1052: Enhance docstring for test_wfc function

The docstring is missing descriptions for some parameters and the return value structure.

Add the following parameter descriptions to the docstring:

 def test_wfc(
     dp: "DeepWFC",
     data: DeepmdData,
     numb_test: int,
     detail_file: Optional[str],
 ) -> tuple[list[np.ndarray], list[int]]:
-    """Test energy type model.
+    """Test wave function coefficient (WFC) model.
 
     Parameters
     ----------
     dp : DeepPot
         instance of deep potential
     data : DeepmdData
         data container object
     numb_test : int
         munber of tests to do
     detail_file : Optional[str]
-        file where test details will be output
+        file where test details will be output. If None, no details are saved.
 
     Returns
     -------
     tuple[list[np.ndarray], list[int]]
-        arrays with results and their shapes
+        Dictionary containing RMSE metrics and their corresponding data sizes:
+        - 'rmse': Tuple of (RMSE value, size of WFC array)
     """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df7121d and 3ff6cc2.

📒 Files selected for processing (1)
  • deepmd/entrypoints/test.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
deepmd/entrypoints/test.py

195-198: Combine if branches using logical or operator

Combine if branches

(SIM114)

🔇 Additional comments (1)
deepmd/entrypoints/test.py (1)

31-33: LGTM: Clean import addition for DeepWFC support

The import is properly placed with other model imports and is necessary for the new functionality.

deepmd/entrypoints/test.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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3ff6cc2 and 3b9ce65.

📒 Files selected for processing (1)
  • deepmd/entrypoints/test.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
deepmd/entrypoints/test.py

195-198: Combine if branches using logical or operator

Combine if branches

(SIM114)

🔇 Additional comments (2)
deepmd/entrypoints/test.py (2)

37-39: LGTM!

The import of DeepWFC is correctly placed and necessary for the new model support.


199-200: LGTM!

The addition of the DeepWFC model type check and corresponding error printing is correctly implemented.

deepmd/entrypoints/test.py Show resolved Hide resolved
@njzjz njzjz enabled auto-merge November 22, 2024 09:42
@njzjz njzjz added this pull request to the merge queue Nov 22, 2024
Merged via the queue into deepmodeling:devel with commit 7bd2e5a Nov 22, 2024
60 checks passed
@caic99 caic99 deleted the caic99-patch-1 branch November 22, 2024 14:58
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.

2 participants