Skip to content

Conversation

@CaRoLZhangxy
Copy link
Collaborator

@CaRoLZhangxy CaRoLZhangxy commented Jul 18, 2025

dict.insert will not replace old value of the key value while lammps reallocate will keep old value in old address. This may cause dict always use the initial value of some keys.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of communication settings to ensure that updates to existing entries are correctly applied, preventing potential issues with outdated or duplicate information during tensor communication.

@github-actions github-actions bot added the C++ label Jul 18, 2025
@CaRoLZhangxy CaRoLZhangxy requested a review from iProzd July 18, 2025 15:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

📝 Walkthrough

Walkthrough

The changes update the way key-value pairs are inserted into communication dictionaries within two source files. Specifically, calls to insert are replaced with insert_or_assign, ensuring that existing keys are overwritten with new values rather than being ignored. No other logic or structure is changed.

Changes

File(s) Change Summary
source/api_cc/src/DeepPotPT.cc Replaced comm_dict.insert() calls with comm_dict.insert_or_assign() for several communication keys.
source/api_cc/src/DeepSpinPT.cc Replaced comm_dict.insert() calls with comm_dict.insert_or_assign() for several communication keys.

📜 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 2b32af5 and 83789f7.

📒 Files selected for processing (2)
  • source/api_cc/src/DeepPotPT.cc (1 hunks)
  • source/api_cc/src/DeepSpinPT.cc (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: njzjz
PR: deepmodeling/deepmd-kit#4226
File: deepmd/dpmodel/atomic_model/base_atomic_model.py:202-202
Timestamp: 2024-10-16T21:49:57.401Z
Learning: When reviewing PRs, avoid making refactor suggestions that are not directly related to the PR's changes. For example, in `deepmd/dpmodel/atomic_model/base_atomic_model.py`, do not suggest simplifying `for kk in ret_dict.keys()` to `for kk in ret_dict` unless it's relevant to the PR.
source/api_cc/src/DeepPotPT.cc (2)
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.
🔇 Additional comments (2)
source/api_cc/src/DeepPotPT.cc (1)

200-205: Excellent fix for communication dictionary consistency during LAMMPS reallocation.

The change from insert to insert_or_assign is critical for correctness. The original insert method would ignore new values if keys already existed, potentially leaving stale data from previous memory addresses during LAMMPS reallocation. This fix ensures communication tensors always reflect current, valid data.

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

208-214: Consistent fix applied to DeepSpinPT communication dictionary.

The same critical fix is properly applied here, ensuring communication tensors remain current during LAMMPS reallocation. The additional "has_spin" key is appropriate for this spin-specific implementation. Good consistency with the DeepPotPT.cc changes.

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

@iProzd iProzd added this pull request to the merge queue Jul 19, 2025
Merged via the queue into deepmodeling:devel with commit 68f0d21 Jul 19, 2025
51 checks passed
ChiahsinChu pushed a commit to ChiahsinChu/deepmd-kit that referenced this pull request Dec 17, 2025
dict.insert will not replace old value of the key value while lammps
reallocate will keep old value in old address. This may cause dict
always use the initial value of some keys.

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

## Summary by CodeRabbit

* **Bug Fixes**
* Improved handling of communication settings to ensure that updates to
existing entries are correctly applied, preventing potential issues with
outdated or duplicate information during tensor communication.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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