fix(lmp): link torch for builtin shared builds#5535
Conversation
Expose PyTorch backend metadata from the DeePMD CMake package and use it in the LAMMPS builtin integration to link Torch when DeePMD was built with the PyTorch backend. This resolves shared LAMMPS builds that fail to resolve torch/c10 symbols from libdeepmd_cc.so. Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
📝 WalkthroughWalkthroughAdds four PyTorch-related variables to the CMake package config template ( ChangesPyTorch Torch Linking for LAMMPS Builtin Mode
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
source/lmp/builtin.cmake (1)
78-83: Proposed filtering change is defensive but addresses valid edge cases for multi-config CMake setups.The current filter (lines 78-83) keeps items that are CMake targets, existing files, or linker flags starting with "-", dropping everything else. While PyTorch's
TORCH_LIBRARIEStypically contains only absolute file paths (withoutoptimized/debug/generalkeywords per PyTorch's CMake design), the proposed fix is worth considering for robustness:
- It explicitly preserves
optimized/debug/generalkeyword pairs if they ever appear- It adds support for CMake generator expressions (
$<...>) which can be useful in multi-config scenarios- It relaxes filtering of unresolved library names
The current filtering isn't known to cause immediate issues with typical PyTorch setups, but the proposed change improves defensiveness against edge cases and future CMake configuration variations.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@source/lmp/builtin.cmake` around lines 78 - 83, The filtering condition in the foreach loop that checks each _deepmd_torch_library item is too restrictive for multi-config CMake setups. Expand the if condition to also preserve items that start with the keywords optimized, debug, or general (which may appear in multi-config scenarios), items that are CMake generator expressions (matching patterns like $<...>), and consider relaxing the filter to be more permissive with unresolved library names. Modify the condition following the TARGET, EXISTS, and "-" prefix checks to add these additional cases using logical OR operators to ensure robustness across different PyTorch CMake configurations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@source/lmp/builtin.cmake`:
- Around line 78-83: The filtering condition in the foreach loop that checks
each _deepmd_torch_library item is too restrictive for multi-config CMake
setups. Expand the if condition to also preserve items that start with the
keywords optimized, debug, or general (which may appear in multi-config
scenarios), items that are CMake generator expressions (matching patterns like
$<...>), and consider relaxing the filter to be more permissive with unresolved
library names. Modify the condition following the TARGET, EXISTS, and "-" prefix
checks to add these additional cases using logical OR operators to ensure
robustness across different PyTorch CMake configurations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3f506c85-e078-4d57-b661-53940cb5d751
📒 Files selected for processing (2)
source/cmake/Config.cmake.insource/lmp/builtin.cmake
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5535 +/- ##
==========================================
- Coverage 82.18% 82.18% -0.01%
==========================================
Files 890 890
Lines 101358 101358
Branches 4240 4240
==========================================
- Hits 83301 83300 -1
Misses 16756 16756
- Partials 1301 1302 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Problem
DeePMD::deepmd_c.libdeepmd_cc.socan still require torch/c10 symbols at the finallmplink step in shared LAMMPS builds.Change
source/lmp/builtin.cmaketo link Torch into the LAMMPS target when the installed DeePMD package reports PyTorch support.Verification
uvx --from cmakelang==0.6.13 cmake-format --check source/cmake/Config.cmake.in source/lmp/builtin.cmakelammpslinksDeePMD::deepmd_c;torch.Fixes #5516
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Summary by CodeRabbit