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 bug: cannot set property default_mesh of DeepmdDataSystem #4360

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

ChiahsinChu
Copy link
Contributor

@ChiahsinChu ChiahsinChu commented Nov 15, 2024

Currently, the multi-task cannot work correctly, and an error is thrown. (See #4358 for more details)
To fix this bug, a minor change in DeepmdDataSystem is made to make the property default_mesh editable.

Summary by CodeRabbit

  • New Features

    • Introduced a new attribute for caching default mesh values, improving efficiency.
    • Added functionality to set test size as a percentage of total structures.
    • New method for automated test size calculation based on specified percentages.
  • Deprecations

    • Marked the get_test method as deprecated, shifting to a new approach for accessing test data.

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.51%. Comparing base (caf330f) to head (1e0b4fa).
Report is 1 commits behind head on r2.

Files with missing lines Patch % Lines
deepmd_utils/utils/data_system.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##               r2    #4360   +/-   ##
=======================================
  Coverage   81.51%   81.51%           
=======================================
  Files         342      342           
  Lines       33882    33888    +6     
  Branches     2881     2878    -3     
=======================================
+ Hits        27618    27623    +5     
- Misses       5381     5382    +1     
  Partials      883      883           

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


🚨 Try these New Features:

Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve modifications to the DeepmdDataSystem class within the deepmd_utils/utils/data_system.py file. A new private attribute _default_mesh is introduced to manage the default mesh, along with updates to the default_mesh property for caching. The constructor is revised to initialize _default_mesh, and the handling of test_size is enhanced to support percentage-based settings. A new method _make_auto_ts is added for calculating test sizes, and the get_test method is deprecated, shifting the approach to loading test data.

Changes

File Change Summary
deepmd_utils/utils/data_system.py - Added private attribute _default_mesh to store default mesh.
- Updated default_mesh property with caching and added a setter.
- Modified constructor to initialize _default_mesh.
- Altered test_size handling to allow percentage settings.
- Added method _make_auto_ts for test size calculation.
- Deprecated get_test method, invoking _load_test for test data loading.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DeepmdDataSystem

    User->>DeepmdDataSystem: Set default_mesh
    DeepmdDataSystem->>DeepmdDataSystem: Initialize _default_mesh
    DeepmdDataSystem->>DeepmdDataSystem: Cache default_mesh values
    User->>DeepmdDataSystem: Request test_size
    DeepmdDataSystem->>DeepmdDataSystem: Calculate test size based on percentage
    DeepmdDataSystem->>DeepmdDataSystem: Load test data using _load_test
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: 0

🧹 Outside diff range and nitpick comments (1)
deepmd_utils/utils/data_system.py (1)

246-248: Consider adding cache invalidation and validation

The current implementation has two potential issues:

  1. The @lru_cache on the getter could return stale data if the mesh is modified through the setter
  2. The setter lacks validation of the input value

Consider this improved implementation:

 @default_mesh.setter
 def default_mesh(self, value: List[np.ndarray]):
+    if not isinstance(value, list) or not all(isinstance(x, np.ndarray) for x in value):
+        raise ValueError("default_mesh must be a List[np.ndarray]")
+    if len(value) != self.nsystems:
+        raise ValueError(f"Expected {self.nsystems} meshes, got {len(value)}")
     self._default_mesh = value
+    # Clear the lru_cache to ensure fresh data
+    self.default_mesh.fget.cache_clear()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 440bb82 and 9117518.

📒 Files selected for processing (1)
  • deepmd_utils/utils/data_system.py (2 hunks)
🔇 Additional comments (2)
deepmd_utils/utils/data_system.py (2)

98-98: LGTM: Proper initialization of private attribute

The initialization of _default_mesh follows Python conventions for private attributes and is placed appropriately in the constructor.


237-244: LGTM: Well-implemented property with caching

The implementation correctly uses @lru_cache for performance optimization and implements lazy initialization of mesh values.

@njzjz njzjz linked an issue Nov 15, 2024 that may be closed by this pull request
@njzjz
Copy link
Member

njzjz commented Nov 15, 2024

I am going to fix the Python tests at least, otherwise it's not known that whether the PR breaks other tests.

@njzjz njzjz requested a review from Copilot November 15, 2024 19:37

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (1)

deepmd_utils/utils/data_system.py:4

  • The word 'dat' should be corrected to 'data'.
The test dat of system with index `sys_idx` will be returned.
@njzjz njzjz closed this Nov 15, 2024
@njzjz njzjz reopened this Nov 15, 2024
@wanghan-iapcm wanghan-iapcm requested a review from njzjz November 19, 2024 00:31
@wanghan-iapcm wanghan-iapcm merged commit bab9258 into deepmodeling:r2 Nov 19, 2024
47 checks passed
@ChiahsinChu ChiahsinChu deleted the devel-setattr branch November 19, 2024 09:39
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.

[BUG] multi-task example does not work
3 participants