Skip to content

feat: support using valid set for input.json for dp test #4859

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

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

caic99
Copy link
Member

@caic99 caic99 commented Aug 1, 2025

  • add --input-json flag to dp test
  • handle rglob_patterns in validation systems when using --input-json

Summary by CodeRabbit

  • New Features

    • Added support for specifying a training input JSON file when running tests, enabling automatic use of validation data for testing.
    • Introduced command-line option to provide the input JSON file for test execution.
  • Bug Fixes

    • Improved error handling for missing validation systems in the input JSON file.
  • Tests

    • Enhanced test coverage to validate new JSON input functionality and recursive glob patterns in validation data systems.

@Copilot Copilot AI review requested due to automatic review settings August 1, 2025 07:55
@github-actions github-actions bot added the Python label Aug 1, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for using a validation dataset from a training input JSON file for the dp test command. The implementation adds an --input-json flag that allows users to specify a training configuration file, and the validation systems defined in that file will be used for testing instead of requiring separate system specification.

Key changes:

  • Added --input-json command line argument to the dp test command
  • Enhanced the test function to handle rglob_patterns when using input JSON files
  • Refactored existing test code to support both traditional and JSON-based testing approaches

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
deepmd/main.py Added --input-json argument to the test command parser
deepmd/entrypoints/test.py Implemented logic to process validation systems from input JSON with rglob pattern support
source/tests/pt/test_dp_test.py Refactored tests and added new test cases for input JSON functionality
Comments suppressed due to low confidence (1)

source/tests/pt/test_dp_test.py:33

  • [nitpick] The parameter name 'use_input_json' could be more descriptive. Consider 'use_validation_from_json' or 'load_systems_from_json' to better indicate its purpose.
    def _run_dp_test(self, use_input_json: bool, numb_test: int = 0) -> None:

val_params = jdata.get("training", {}).get("validation_data", {})
validation = val_params.get("systems")
if not validation:
raise RuntimeError("No validation data found in input json")
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The error message should be more specific about where validation data should be located in the JSON structure. Consider: "No validation systems found in training.validation_data.systems of input json file"

Suggested change
raise RuntimeError("No validation data found in input json")
raise RuntimeError("No validation systems found in training.validation_data.systems of input json file")

Copilot uses AI. Check for mistakes.

Comment on lines +47 to +49
val_sys = self.config["training"]["validation_data"]["systems"]
if isinstance(val_sys, list):
val_sys = val_sys[0]
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

This code duplicates the validation system extraction logic that's already implemented in the main test function. Consider extracting this into a helper method to avoid duplication.

Suggested change
val_sys = self.config["training"]["validation_data"]["systems"]
if isinstance(val_sys, list):
val_sys = val_sys[0]
val_sys = self._get_validation_system()

Copilot uses AI. Check for mistakes.

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

📝 Walkthrough

Walkthrough

The changes introduce support for specifying validation systems via an input JSON file in the test entrypoint and CLI. The test function and CLI parser are updated to accept an input_json argument, and the logic for extracting and processing systems from JSON is implemented. Associated tests are refactored and expanded to cover the new functionality, including recursive glob pattern handling.

Changes

Cohort / File(s) Change Summary
Entrypoint test logic update
deepmd/entrypoints/test.py
Added support for an input_json parameter to the test function. When provided, validation systems are extracted from the JSON, resolved, and processed, with error handling for missing systems. Imports and docstrings updated accordingly.
CLI parser enhancement
deepmd/main.py
Added -i/--input-json argument to the "test" CLI subcommand, allowing users to specify a training input JSON file for test system selection. Made the mutually exclusive group required.
Test refactor and new cases
source/tests/pt/test_dp_test.py
Refactored the main test method into a helper, added tests for the new input_json functionality, and introduced a new test class to verify recursive glob pattern support in validation data systems.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant test()
    participant j_loader
    participant process_systems

    User->>CLI: Run test command (with or without --input-json)
    CLI->>test(): Call test() with input_json or datafile
    alt input_json provided
        test()->>j_loader: Load JSON file
        j_loader-->>test(): Return parsed JSON
        test()->>process_systems: Extract and resolve systems
        process_systems-->>test(): Return system list
    else datafile provided
        test()->>test(): Read systems from datafile
    else
        test()->>test(): Expand system string
    end
    test()->>test(): Proceed with testing using system list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66d7e36 and 72c57c7.

📒 Files selected for processing (1)
  • deepmd/entrypoints/test.py (5 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4144
File: source/api_cc/tests/test_deeppot_dpa_pt.cc:166-246
Timestamp: 2024-09-19T04:25:12.408Z
Learning: Refactoring between test classes `TestInferDeepPotDpaPt` and `TestInferDeepPotDpaPtNopbc` is addressed in PR #3905.
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4144
File: source/api_cc/tests/test_deeppot_dpa_pt.cc:166-246
Timestamp: 2024-10-08T15:32:11.479Z
Learning: Refactoring between test classes `TestInferDeepPotDpaPt` and `TestInferDeepPotDpaPtNopbc` is addressed in PR #3905.
📚 Learning: in the file `deepmd/pd/infer/inference.py`, when loading the model checkpoint in the `tester` class,...
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4302
File: deepmd/pd/infer/inference.py:35-38
Timestamp: 2024-11-25T07:42:55.735Z
Learning: In the file `deepmd/pd/infer/inference.py`, when loading the model checkpoint in the `Tester` class, it's acceptable to not include additional error handling for loading the model state dictionary.

Applied to files:

  • deepmd/entrypoints/test.py
📚 Learning: in the deepmd project, entry points like `deepmd.jax` may be registered in external projects, so the...
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4284
File: deepmd/jax/__init__.py:8-8
Timestamp: 2024-10-30T20:08:12.531Z
Learning: In the DeepMD project, entry points like `deepmd.jax` may be registered in external projects, so their absence in the local configuration files is acceptable.

Applied to files:

  • deepmd/entrypoints/test.py
📚 Learning: the function `nvprof_context` is defined in `deepmd/pd/utils/utils.py`, so importing it in `deepmd/p...
Learnt from: HydrogenSulfate
PR: deepmodeling/deepmd-kit#4414
File: deepmd/pd/train/training.py:66-66
Timestamp: 2024-11-29T12:15:22.226Z
Learning: The function `nvprof_context` is defined in `deepmd/pd/utils/utils.py`, so importing it in `deepmd/pd/train/training.py` is correct.

Applied to files:

  • deepmd/entrypoints/test.py
🪛 Ruff (0.12.2)
deepmd/entrypoints/test.py

113-113: Undefined name update_deepmd_input

(F821)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (30)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test C++ (true)
  • 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 library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (clang, clang)
🔇 Additional comments (3)
deepmd/entrypoints/test.py (3)

17-17: LGTM! Necessary imports for JSON input functionality.

The imports of j_loader and process_systems are appropriate and necessary for the new input JSON feature.

Also applies to: 45-47


67-67: LGTM! Proper function signature and documentation.

The addition of the optional input_json parameter with appropriate typing and documentation is well done.

Also applies to: 86-87


111-112: LGTM! Well-structured JSON processing logic.

The implementation correctly:

  • Loads and updates the JSON data
  • Extracts validation systems from the nested structure
  • Handles both string and list formats for validation systems
  • Resolves paths relative to the JSON file location
  • Supports recursive glob patterns via process_systems

Also applies to: 114-116, 118-124

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.76%. Comparing base (43504d3) to head (711f4a0).

Files with missing lines Patch % Lines
deepmd/entrypoints/test.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4859   +/-   ##
=======================================
  Coverage   84.76%   84.76%           
=======================================
  Files         699      699           
  Lines       68077    68091   +14     
  Branches     3541     3541           
=======================================
+ Hits        57708    57720   +12     
- Misses       9235     9236    +1     
- Partials     1134     1135    +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

Choose a reason for hiding this comment

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

Please use add_mutually_exclusive_group to group input_json, data_file, and system.

"--input-json",
default=None,
type=str,
help="The training input json file. Validation data in the training script will be used for testing.",
Copy link
Member

Choose a reason for hiding this comment

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

It's unclear why validation data is used other than training data. I suggest adding two options.

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