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(pt): make comm_dict for dpa2 noncompulsory when nghost is 0 #4144

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Sep 19, 2024

Construct and pass a mapping instead when there is no ghost atom.

Summary by CodeRabbit

  • New Features

    • Introduced a new test class to evaluate the DeepPot model without periodic boundary conditions, enhancing testing coverage.
  • Bug Fixes

    • Corrected the order of returned values in existing tests for clarity and accuracy.
  • Documentation

    • Updated the cleanup process in test classes to improve test execution consistency.
  • Chores

    • Simplified the TearDown methods in multiple test classes, removing unnecessary file deletion steps.

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

Walkthrough

The changes involve modifications to the DeepPotPT::compute function to enhance message passing logic based on the presence of ghost atoms. Additionally, the TearDown methods in several test classes have been simplified to empty implementations, removing file deletion operations. A new test class has been introduced to evaluate the DeepPot model under non-periodic boundary conditions, while existing tests have been refined for accuracy and clarity.

Changes

Files Change Summary
source/api_cc/src/DeepPotPT.cc Modified the DeepPotPT::compute function to include conditional logic for message passing based on nghost. Created a mapping_tensor when nghost is zero to handle scenarios without ghost atoms. Updated calls to module.run_method to use the new tensor.
source/api_cc/tests/test_deeppot_a_fparam_aparam_pt.cc Removed file deletion from the TearDown method in TestInferDeepPotAFParamAParamPt, resulting in an empty method.
source/api_cc/tests/test_deeppot_dpa_pt.cc Introduced TestInferDeepPotDpaPtNopbc for testing without periodic boundary conditions. Simplified TearDown in TestInferDeepPotDpaPt to an empty method. Corrected the order of returned values from dp.eval method in TestInferDeepPotDpaPt.
source/api_cc/tests/test_deeppot_pt.cc Modified the TearDown method in TestInferDeepPotAPt to remove file deletion, resulting in an empty implementation.

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 generate interesting stats about this repository and render them as a table.
    -- @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.

@github-actions github-actions bot added the C++ label Sep 19, 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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba9f02f and 9381a13.

Files selected for processing (4)
  • source/api_cc/src/DeepPotPT.cc (3 hunks)
  • source/api_cc/tests/test_deeppot_a_fparam_aparam_pt.cc (1 hunks)
  • source/api_cc/tests/test_deeppot_dpa_pt.cc (3 hunks)
  • source/api_cc/tests/test_deeppot_pt.cc (1 hunks)
Additional comments not posted (7)
source/api_cc/tests/test_deeppot_a_fparam_aparam_pt.cc (1)

98-98: Possible residual file due to empty TearDown() method

The TearDown() method is now empty after removing the file deletion operation. If fparam_aparam.pb is still being generated during tests, it may remain on the filesystem after tests complete, potentially affecting subsequent test runs or causing unintended side effects.

Please verify whether fparam_aparam.pb is still created during the tests. If it is no longer generated or needed, consider removing the empty TearDown() method to clean up the code. If the file is still generated, reintroducing the file deletion ensures a clean test environment.

Run the following script to check if fparam_aparam.pb is being generated or used:

Verification successful

Remove empty TearDown() method

The empty TearDown() method in source/api_cc/tests/test_deeppot_a_fparam_aparam_pt.cc can be safely removed. Our verification confirms that:

  1. The file does not create, use, or manipulate 'fparam_aparam.pb'.
  2. There are no visible file operations or resource allocations that would require cleanup.

Removing this empty method will improve code cleanliness without affecting the test's functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for code that creates or manipulates 'fparam_aparam.pb'

# Test: Find any occurrences of 'fparam_aparam.pb' in the codebase
# Expectation: No code should be generating or using 'fparam_aparam.pb'

rg 'fparam_aparam\.pb' --type cpp

Length of output: 5977


Script:

#!/bin/bash
# Description: Search for any usage of 'fparam_aparam.pb' in the file under review and check for other potential cleanup operations

# Search for 'fparam_aparam.pb' in the specific file
echo "Searching for 'fparam_aparam.pb' usage in test_deeppot_a_fparam_aparam_pt.cc:"
rg 'fparam_aparam\.pb' source/api_cc/tests/test_deeppot_a_fparam_aparam_pt.cc

# Check for any file operations or resource allocations that might need cleanup
echo -e "\nChecking for file operations or resource allocations:"
rg -i '(fopen|malloc|new|create)' source/api_cc/tests/test_deeppot_a_fparam_aparam_pt.cc

Length of output: 464

source/api_cc/tests/test_deeppot_dpa_pt.cc (4)

39-39: Corrected the order of return values in the comment

The updated comment now correctly reflects the order of the returned values from dp.eval as e, f, v, ae, av. This improves code clarity.


227-227: Verify the model path in dp.init

The model is initialized using a relative path "../../tests/infer/deeppot_dpa.pth". Ensure that this path is correct and accessible during test execution to prevent file not found errors.


174-174: Handling empty box for non-periodic boundary conditions

Initializing box as an empty vector correctly represents non-periodic boundary conditions. Confirm that the DeepPot model and dp.compute method properly handle an empty box without errors.


250-393: Addition of comprehensive tests for non-periodic boundary conditions

The new test cases in TestInferDeepPotDpaPtNopbc effectively validate the DeepPot model under non-periodic boundary conditions. The use of atomic computations and neighbor lists enhances test coverage.

source/api_cc/src/DeepPotPT.cc (2)

167-167: Declaration of mapping_tensor

The declaration of c10::optional<torch::Tensor> mapping_tensor; is appropriate to allow for an optional tensor that may or may not be initialized based on conditions.


200-205: Proper Initialization of mapping_tensor When nghost == 0

The code correctly initializes mapping_tensor when do_message_passing == 1 && nghost == 0, handling the case where there are no ghost atoms (e.g., serial non-periodic boundary conditions). This ensures that mapping_tensor is set to a valid tensor for subsequent processing.

source/api_cc/tests/test_deeppot_dpa_pt.cc Show resolved Hide resolved
source/api_cc/tests/test_deeppot_dpa_pt.cc Show resolved Hide resolved
source/api_cc/src/DeepPotPT.cc Show resolved Hide resolved
source/api_cc/tests/test_deeppot_pt.cc Show resolved Hide resolved
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 97.97980% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.12%. Comparing base (ba9f02f) to head (9381a13).
Report is 3 commits behind head on devel.

Files with missing lines Patch % Lines
source/api_cc/src/DeepPotPT.cc 75.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4144      +/-   ##
==========================================
+ Coverage   83.09%   83.12%   +0.02%     
==========================================
  Files         533      533              
  Lines       52221    52313      +92     
  Branches     3032     3046      +14     
==========================================
+ Hits        43394    43484      +90     
+ Misses       7881     7879       -2     
- Partials      946      950       +4     

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

@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Sep 19, 2024
Merged via the queue into deepmodeling:devel with commit e1b6aec Sep 19, 2024
60 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Oct 15, 2024
enhancement on #4144

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced tensor mapping capabilities with the addition of a new
`mapping_tensor` variable.
- Updated `compute` method to handle ghost atoms and support improved
tensor creation logic.
	- Overloaded `computew` methods to support both double and float types.

- **Bug Fixes**
- Improved error handling in the `translate_error` method for better
exception management.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-merge-queue bot pushed a commit that referenced this pull request Oct 23, 2024
…4237)

fix errors mentioned in following pr:
#4220
#4209
#4144

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced message passing logic in the computation process for improved
efficiency.
- Added new test functions to evaluate DeepMD model performance under
various conditions.

- **Bug Fixes**
- Improved error handling and assertions in test cases to ensure
robustness.

- **Refactor**
- Streamlined tensor operations in the communication process to enhance
clarity and reduce unnecessary computations.
- Removed outdated test cases related to neighbor list handling in the
DeepPot class.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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