feat(lammps): load installed backends dynamically#5707
Conversation
📝 WalkthroughWalkthroughThe PR refactors ChangesLAMMPS environment refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant lmp as deepmd/lmp.py (import time)
participant tfHelper as _get_tensorflow_library_paths
participant ptHelper as _get_pytorch_library_paths
participant env as os.environ
lmp->>tfHelper: get TF lib/preload paths
tfHelper-->>lmp: paths or empty (if TF missing)
lmp->>ptHelper: get PyTorch lib path
ptHelper-->>lmp: path or empty (if torch missing)
lmp->>lmp: compute CUDA paths (Linux)
lmp->>env: set preload_env via get_env
lmp->>env: set lib_env via get_env
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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/tests/test_lmp.py (1)
33-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a test for the TF ≥ 2.12 branch.
Current coverage only exercises the
TF_VERSION < 2.12path (libpython preload). Add a complementary test withTF_VERSION="2.12.0"(or later) asserting the preload list stays empty, to guard the version-gated branch in_get_tensorflow_library_pathsagainst regressions.🤖 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/tests/test_lmp.py` around lines 33 - 54, Add a complementary test for the TF_VERSION >= 2.12 branch in _get_tensorflow_library_paths, similar to test_tensorflow_library_paths_include_libpython_for_old_tensorflow. Mock deepmd.tf.env with TF_VERSION set to 2.12.0 or later and assert the returned TensorFlow library paths are still correct while the libpython preload list is empty, ensuring the version-gated logic does not regress.
🤖 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/tests/test_lmp.py`:
- Around line 33-54: Add a complementary test for the TF_VERSION >= 2.12 branch
in _get_tensorflow_library_paths, similar to
test_tensorflow_library_paths_include_libpython_for_old_tensorflow. Mock
deepmd.tf.env with TF_VERSION set to 2.12.0 or later and assert the returned
TensorFlow library paths are still correct while the libpython preload list is
empty, ensuring the version-gated logic does not regress.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 256487fb-b134-4331-9a78-ff4abb1c8d12
📒 Files selected for processing (3)
deepmd/lmp.pydoc/install/easy-install.mdsource/tests/test_lmp.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5707 +/- ##
==========================================
- Coverage 81.22% 81.19% -0.04%
==========================================
Files 980 990 +10
Lines 109352 111035 +1683
Branches 4205 4232 +27
==========================================
+ Hits 88821 90153 +1332
- Misses 19011 19355 +344
- Partials 1520 1527 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
source/tests/test_lmp.py (1)
57-154: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: extract a shared
import_modulefake/fixture.The
fake_import_moduleclosure with anAssertionErrorfallback for unexpected imports is repeated near-identically across these five tests. A small parametrized helper (e.g., mappingmodule_name -> return value or exception) would reduce duplication, but current tests are correct and readable as-is.🤖 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/tests/test_lmp.py` around lines 57 - 154, The five tests repeat the same `fake_import_module` pattern with only the module-specific return/raise behavior changing. Extract a shared helper or fixture around `fake_import_module` used by `_get_tensorflow_library_paths()` and `_get_pytorch_library_paths()`, ideally driven by a module-name-to-result mapping, so the tests stay concise while preserving the current `AssertionError` fallback for unexpected imports.
🤖 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/tests/test_lmp.py`:
- Around line 57-154: The five tests repeat the same `fake_import_module`
pattern with only the module-specific return/raise behavior changing. Extract a
shared helper or fixture around `fake_import_module` used by
`_get_tensorflow_library_paths()` and `_get_pytorch_library_paths()`, ideally
driven by a module-name-to-result mapping, so the tests stay concise while
preserving the current `AssertionError` fallback for unexpected imports.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 38afed2c-fb79-4c84-9767-372c267b9b92
📒 Files selected for processing (1)
source/tests/test_lmp.py
Summary
Tests
Fork CI runs:
Summary by CodeRabbit