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

chore: align dataset summary output #4541

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Conversation

caic99
Copy link
Member

@caic99 caic99 commented Jan 8, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced test size configuration with percentage-based input
    • Added method to automatically compute test sizes across systems
  • Deprecation

    • Marked get_test method as deprecated
  • Improvements

    • Updated logging format for better readability
    • Improved error handling for test size configuration

@github-actions github-actions bot added the Python label Jan 8, 2025
Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

📝 Walkthrough

Walkthrough

The changes in the deepmd/utils/data_system.py file focus on enhancing the DeepmdDataSystem class's test size configuration. The modifications introduce a new way to specify test sizes using percentage strings, add a private method _make_auto_ts to automatically compute test sizes across systems, and mark the get_test method as deprecated. The changes aim to provide more flexible and intuitive test data management for deep learning systems.

Changes

File Change Summary
deepmd/utils/data_system.py - Added _make_auto_ts private method to compute test sizes automatically
- Updated constructor to handle percentage-based test size specification
- Marked get_test method as deprecated
- Modified logging format in print_summary for improved readability

Sequence Diagram

sequenceDiagram
    participant DS as DeepmdDataSystem
    participant Constructor as __init__
    participant AutoTS as _make_auto_ts

    Constructor->>DS: Initialize with test_size
    alt Percentage test_size
        Constructor->>AutoTS: Compute test size
        AutoTS-->>Constructor: Return calculated test size
    else Fixed test size
        Constructor->>Constructor: Use provided test size
    end
Loading

The sequence diagram illustrates how the new _make_auto_ts method is integrated into the constructor's test size calculation process, allowing for dynamic test size determination based on system characteristics.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 comments (2)
deepmd/utils/data_system.py (2)

Line range hint 78-106: Add validation for test size percentage range.

The code accepts percentage-based test size but doesn't validate if the percentage is within the valid range (0-100).

Add validation before the percentage calculation:

     elif isinstance(self.test_size, str):
         words = self.test_size.split("%")
         try:
             percent = int(words[0])
+            if not 0 <= percent <= 100:
+                raise ValueError(f"test_size percentage must be between 0 and 100, got {percent}")
         except ValueError as e:
             raise RuntimeError("unknown test_size rule " + words[0]) from e
         self.test_size = self._make_auto_ts(percent)

Line range hint 582-599: Improve deprecation handling of get_test method.

The method is marked as deprecated using a comment, but it should use Python's built-in deprecation warning mechanism.

Apply this improvement:

-    def get_test(self, sys_idx: Optional[int] = None, n_test: int = -1):  # depreciated
+    def get_test(self, sys_idx: Optional[int] = None, n_test: int = -1):
+        """Get test data from the data systems.
+
+        .. deprecated:: 2.0.0
+           Use get_test_data() instead. Will be removed in version 3.0.0.
+        """
+        warnings.warn(
+            "get_test() is deprecated since version 2.0.0 and will be removed in 3.0.0. "
+            "Use get_test_data() instead.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
🧹 Nitpick comments (2)
deepmd/utils/data_system.py (2)

678-678: Fix string formatting in print_summary.

The string formatting has been adjusted for better readability, but the line contains trailing whitespace.

Remove the trailing whitespace:

-            "%s  %6d  %6d  %6d  %9.3e  %3s",
+            "%s  %6d  %6d  %6d  %9.3e  %3s".rstrip(),

Line range hint 551-558: Improve _make_auto_ts implementation.

The method needs better documentation and edge case handling.

Apply these improvements:

     def _make_auto_ts(self, percent):
+        """Calculate test size for each system based on percentage.
+
+        Parameters
+        ----------
+        percent : int
+            Percentage of total samples to use for testing (0-100)
+
+        Returns
+        -------
+        list
+            List of test sizes for each system
+        """
         ts = []
         for ii in range(self.nsystems):
             ni = self.batch_size[ii] * self.nbatches[ii]
             tsi = int(ni * percent / 100)
+            if tsi == 0 and percent > 0:
+                warnings.warn(f"System {ii} has too few samples, setting minimum test size to 1")
+                tsi = 1
             ts.append(tsi)
 
         return ts
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbdb9b9 and 9acd739.

📒 Files selected for processing (1)
  • deepmd/utils/data_system.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Build C library (2.14, >=2.5.0rc0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.55%. Comparing base (bf79cc6) to head (9acd739).
Report is 8 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4541      +/-   ##
==========================================
- Coverage   84.58%   84.55%   -0.04%     
==========================================
  Files         675      677       +2     
  Lines       63580    63902     +322     
  Branches     3488     3487       -1     
==========================================
+ Hits        53782    54034     +252     
- Misses       8673     8742      +69     
- Partials     1125     1126       +1     

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

@njzjz njzjz added this pull request to the merge queue Jan 8, 2025
Merged via the queue into deepmodeling:devel with commit 9af197c Jan 8, 2025
61 checks passed
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