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(cc): add atomic argument to DeepPotBase::computew #3996

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Jul 19, 2024

See #3969 for the background.

Summary by CodeRabbit

  • New Features
    • Introduced an 'atomic' parameter in various compute functions to enable atomic energy and virial calculations, providing more granular control over computations.

njzjz added 2 commits July 18, 2024 23:25
See deepmodeling#3969 for the background.

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
@github-actions github-actions bot added the C++ label Jul 19, 2024
Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Walkthrough

Walkthrough

Recent changes to the DeepPot library introduce an additional boolean parameter atomic to various compute and computew methods across several classes (DeepPotBase, DeepPotPT, and DeepPotTF). This parameter allows for conditional execution of atomic energy and virial calculations, enhancing the flexibility and efficiency of the computation process. The function signatures and internal logic have been updated to incorporate this new parameter consistently.

Changes

File(s) Change Summary
source/api_cc/include/DeepPot.h Updated computew and computew_mixed_type signatures in DeepPotBase class to include a new boolean parameter atomic, enhancing control over atomic-level calculations.
source/api_cc/include/DeepPotPT.h Enhanced compute and compute_mixed_type methods of DeepPotPT class with a new boolean parameter atomic, and removed default values for fparam and aparam to enforce explicit parameter provision.
source/api_cc/include/DeepPotTF.h Added atomic parameter to compute and compute_mixed_type methods in DeepPotTF class, requiring explicit vector arguments for fparam and aparam, enhancing control over atomic energy and virial computations.
source/api_cc/src/DeepPot.cc Modified function signatures in the DeepPot class to incorporate a new boolean parameter for compute and compute_mixed_type methods, ensuring consistent integration across different data types and configurations.
source/api_cc/src/DeepPotPT.cc Introduced a new boolean parameter atomic in compute method of DeepPotPT class, altering internal logic to conditionally execute atom-related calculations, enhancing flexibility and efficiency.
source/api_cc/src/DeepPotTF.cc Added atomic parameter to compute and compute_mixed_type methods in DeepPotTF class, altering control flow to execute additional tensor operations based on the value of atomic.

Sequence Diagram(s)

DeepPotPT: Conditional Execution Based on atomic

sequenceDiagram
    participant User
    participant DeepPotPT
    participant ComputeLogic

    User->>DeepPotPT: compute(ener, force, virial, atom_energy, atom_virial, aparam, atomic)
    alt atomic is true
        DeepPotPT->>ComputeLogic: execute atomic energy and virial calculations
        ComputeLogic-->>DeepPotPT: return atom_energy, atom_virial
    else atomic is false
        DeepPotPT->>ComputeLogic: skip atomic calculations
    end
    DeepPotPT-->>User: return ener, force, virial, [atom_energy, atom_virial if atomic is true]
Loading

DeepPotTF: Updated Compute Method with atomic

sequenceDiagram
    participant User
    participant DeepPotTF
    participant ComputeLogic

    User->>DeepPotTF: compute(dener, datype_, dbox, fparam, aparam, atomic)
    alt atomic is true
        DeepPotTF->>ComputeLogic: execute model with atom parameters
        ComputeLogic-->>DeepPotTF: return detailed energy/virial
    else atomic is false
        DeepPotTF->>ComputeLogic: execute model without atom parameters
    end
    DeepPotTF-->>User: return dener, force, virial, [atom_energy, atom_virial if atomic is true]
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cda653e and ce05235.

Files selected for processing (1)
  • source/api_cc/src/DeepPotPT.cc (17 hunks)
Files skipped from review as they are similar to previous changes (1)
  • source/api_cc/src/DeepPotPT.cc

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>.
    • 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 show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@njzjz njzjz changed the title fix(cc): add atomic argument to DeepPotBase fix(cc): add atomic argument to DeepPotBase.computew Jul 19, 2024
@njzjz njzjz changed the title fix(cc): add atomic argument to DeepPotBase.computew fix(cc): add atomic argument to DeepPotBase::computew Jul 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: 0

Outside diff range, codebase verification and nitpick comments (7)
source/api_cc/include/DeepPotTF.h (3)

74-76: Update all compute method calls to include the atomic parameter.

The atomic parameter has been added to the method signature, but none of the calls to this method have been updated accordingly. This could lead to compilation errors or incorrect behavior. Please update the following locations to include the atomic parameter:

  • source/api_cc/src/DeepTensorTF.cc
  • source/api_cc/src/DeepTensor.cc
  • source/api_cc/src/DeepPotTF.cc
  • source/api_cc/src/DataModifier.cc
  • source/api_cc/src/DataModifierTF.cc
  • source/api_cc/src/DeepPotPT.cc
  • source/api_cc/src/DeepPot.cc
Analysis chain

Verify the new parameter integration.

The atomic parameter has been added to the method signature. Ensure all calls to this method are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `compute` method are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurances of the new signature.
rg --type cpp -A 5 $'compute<'

Length of output: 32052


153-155: Integration of the atomic parameter is incomplete.

The atomic parameter has been added to the method signature of compute_mixed_type, but none of the calls to this method have been updated to include this new parameter. Please ensure that all calls to compute_mixed_type are updated to include the atomic parameter.

  • Files to update:
    • source/api_cc/src/DeepPot.cc
    • source/api_cc/src/DeepPotTF.cc
Analysis chain

Verify the new parameter integration.

The atomic parameter has been added to the method signature. Ensure all calls to this method are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `compute_mixed_type` method are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurances of the new signature.
rg --type cpp -A 5 $'compute_mixed_type<'

Length of output: 4943


Script:

#!/bin/bash
# Description: Verify all calls to `compute_mixed_type` method are updated with the new `atomic` parameter.

# Search for the method calls to check if the `atomic` parameter is included.
rg --type cpp 'compute_mixed_type<' -A 10

Length of output: 8729


115-117: Verify the new parameter integration.

The atomic parameter has not been integrated into the compute method signatures in DeepPotTF.cc. Please ensure all instances of the compute method are updated to include the atomic parameter.

  • File: source/api_cc/src/DeepPotTF.cc
  • Method Signatures:
    • template void DeepPotTF::compute<double, ENERGYTYPE>(...)
    • template void DeepPotTF::compute<float, ENERGYTYPE>(...)
    • template void DeepPotTF::compute<double, std::vector<ENERGYTYPE>>(...)
    • template void DeepPotTF::compute<float, std::vector<ENERGYTYPE>>(...)
Analysis chain

Verify the new parameter integration.

The atomic parameter has been added to the method signature. Ensure all calls to this method are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `compute` method with additional parameters are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurances of the new signature.
rg --type cpp -A 5 $'compute<'

Length of output: 32052


Script:

#!/bin/bash
# Description: Verify all calls to `compute` method include the new `atomic` parameter.

# Test: Search for the method signatures. Expect: Presence of the `atomic` parameter in the method signature.
rg --type cpp -A 10 'template void DeepPotTF::compute<' | grep -A 10 'compute<'
rg --type cpp -A 10 'template void DeepTensorTF::compute<' | grep -A 10 'compute<'
rg --type cpp -A 10 'template void DeepPotPT::compute<' | grep -A 10 'compute<'
rg --type cpp -A 10 'template void DipoleChargeModifierTF::compute<' | grep -A 10 'compute<'
rg --type cpp -A 10 'template void DipoleChargeModifier::compute<' | grep -A 10 'compute<'
rg --type cpp -A 10 'template void DeepPot::compute<' | grep -A 10 'compute<'
rg --type cpp -A 10 'template void DeepPotModelDevi::compute<' | grep -A 10 'compute<'

Length of output: 41762


Script:

#!/bin/bash
# Description: Verify all calls to `compute` method include the new `atomic` parameter.

# Test: Search for the method signatures in the context of the `DeepPotTF.h` file. Expect: Presence of the `atomic` parameter in the method signature.
rg --type cpp -A 10 'compute<' source/api_cc/include/DeepPotTF.h

Length of output: 66


Script:

#!/bin/bash
# Description: Verify all calls to `compute` method include the new `atomic` parameter.

# Test: Search for the method signatures in the relevant implementation files. Expect: Presence of the `atomic` parameter in the method signature.
rg --type cpp -A 10 'compute<' source/api_cc/src/DeepPotTF.cc

Length of output: 3396

source/api_cc/include/DeepPotPT.h (3)

150-151: Update method calls to include the new atomic parameter.

The atomic parameter has been added to the compute_mixed_type method signature, but the method calls have not been updated accordingly. Please ensure all calls to this method are updated to include the new atomic parameter.

  • Instances found in source/api_cc/src/DeepPotTF.cc
  • Instances found in source/api_cc/src/DeepPot.cc
Analysis chain

Verify the new parameter integration.

The atomic parameter has been added to the method signature. Ensure all calls to this method are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `compute_mixed_type` method are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurances of the new signature.
rg --type cpp -A 5 $'compute_mixed_type<'

Length of output: 4943


Script:

#!/bin/bash
# Description: Verify all calls to `compute_mixed_type` method are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurrences of the new signature with `atomic` parameter.
rg --type cpp -A 10 'compute_mixed_type<'

Length of output: 8729


115-117: Update all compute method calls to include the new atomic parameter.

The atomic parameter has been added to the compute method signature, but the method calls have not been updated to include this new parameter. Please ensure all calls to this method are updated accordingly.

  • Files to update:
    • source/api_cc/src/DeepTensorTF.cc
    • source/api_cc/src/DeepTensor.cc
    • source/api_cc/src/DataModifierTF.cc
    • source/api_cc/src/DataModifier.cc
    • source/api_cc/src/DeepPotTF.cc
    • source/api_cc/src/DeepPot.cc
Analysis chain

Verify the new parameter integration.

The atomic parameter has been added to the method signature. Ensure all calls to this method are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `compute` method with additional parameters are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurances of the new signature.
rg --type cpp -A 5 $'compute<'

Length of output: 32052


Script:

#!/bin/bash
# Description: Verify all calls to `compute` method with additional parameters are updated with the new `atomic` parameter.

# Test: Search for the method calls and include more context lines to verify the presence of the `atomic` parameter.
rg --type cpp -A 10 'compute<'

Length of output: 51990


74-76: Update method calls to include new parameter.

The atomic parameter has been added to the compute method in DeepPotPT.h, but the calls to this method in the source files have not been updated accordingly. Please update all calls to this method to include the atomic parameter.

  • Files to update:
    • source/api_cc/src/DeepTensorTF.cc
    • source/api_cc/src/DeepPotTF.cc
    • source/api_cc/src/DataModifierTF.cc
    • source/api_cc/src/DeepPotPT.cc
    • source/api_cc/src/DeepPot.cc
    • source/api_cc/src/DataModifier.cc
    • source/api_cc/src/DeepTensor.cc
Analysis chain

Verify the new parameter integration.

The atomic parameter has been added to the method signature. Ensure all calls to this method are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `compute` method are updated with the new `atomic` parameter.

# Test: Search for the method calls. Expect: Only occurances of the new signature.
rg --type cpp -A 5 $'compute<'

Length of output: 32052


Script:

#!/bin/bash
# Description: Verify the method declaration of `compute` in `DeepPotPT.h` to check for the `atomic` parameter.

# Test: Search for the method declaration. Expect: The method declaration includes the `atomic` parameter.
rg --type cpp -A 5 'compute' source/api_cc/include/DeepPotPT.h

Length of output: 3627

source/api_cc/src/DeepPotTF.cc (1)

835-836: Ensure proper handling of the atomic parameter.

The atomic parameter has been added to the function signature of compute_mixed_type. However, not all calls to this function include the atomic parameter. Please update the following instances to pass the correct value for atomic:

  • source/api_cc/src/DeepPotTF.cc
  • source/api_cc/src/DeepPot.cc
  • source/api_cc/tests/test_mixed_type.cc
  • source/api_c/tests/test_mixed_type.cc
  • source/api_c/src/c_api.cc
  • source/api_c/include/deepmd.hpp
Analysis chain

Ensure proper handling of the atomic parameter.

The atomic parameter is added to the function signature. Ensure that all calls to this function pass the correct value for atomic.


Ensure proper handling of the atomic parameter.

The atomic parameter has been added to the function signature of compute_mixed_type. Ensure that all calls to this function pass the correct value for atomic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `compute_mixed_type` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type cpp -A 5 $'compute_mixed_type'

Length of output: 15771


Script:

#!/bin/bash
# Description: Verify all function calls to `compute_mixed_type` include the `atomic` parameter.

# Test: Search for the function usage and check if the `atomic` parameter is included. Expect: Only occurrences with the `atomic` parameter.
rg --type cpp 'compute_mixed_type' -A 0 | grep -v 'atomic'

Length of output: 3126

Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 77.27273% with 15 lines in your changes missing coverage. Please review.

Project coverage is 82.90%. Comparing base (6199b03) to head (ce05235).
Report is 109 commits behind head on devel.

Files with missing lines Patch % Lines
source/api_cc/src/DeepPotTF.cc 42.30% 12 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3996      +/-   ##
==========================================
+ Coverage   82.83%   82.90%   +0.07%     
==========================================
  Files         522      522              
  Lines       50889    50888       -1     
  Branches     3015     3022       +7     
==========================================
+ Hits        42154    42189      +35     
+ Misses       7798     7754      -44     
- Partials      937      945       +8     

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

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link
Collaborator

@CaRoLZhangxy CaRoLZhangxy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@iProzd iProzd left a comment

Choose a reason for hiding this comment

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

It seems that the atomic option is only in C++ and not in C, while the default lammps compile option is C. We should better support this option in C.

@njzjz
Copy link
Member Author

njzjz commented Jul 23, 2024

It seems that the atomic option is only in C++ and not in C, while the default lammps compile option is C. We should better support this option in C.

This may be completed in a separated PR.

@iProzd iProzd added this pull request to the merge queue Jul 24, 2024
Merged via the queue into deepmodeling:devel with commit 806859b Jul 24, 2024
60 checks passed
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
…ng#3996)

See deepmodeling#3969 for the
background.

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

- **New Features**
- Introduced an 'atomic' parameter in various compute functions to
enable atomic energy and virial calculations, providing more granular
control over computations.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
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.

4 participants