-
Notifications
You must be signed in to change notification settings - Fork 579
feat(pt/test): add unit test for the compression of se_e3_tebd #5060
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
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughA new comprehensive test module is added to validate model compression and TEBD-based neural descriptors in DeepMD. The module includes setup helpers, five test case classes, and cleanup routines for testing model attributes, evaluations across multiple scenarios, consistency checks, and ASE-based integration testing. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive unit tests for model compression functionality of the se_e3_tebd descriptor in PyTorch. The tests verify that compressed models produce results consistent with the original frozen models.
Key Changes
- Added unit tests covering compression of se_e3_tebd descriptor models
- Tests include scenarios with PBC, no PBC, exclude_types, and skip-neighbor-stat options
- Verifies consistency between original and compressed models for energy, forces, and virial predictions
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## devel #5060 +/- ##
==========================================
+ Coverage 84.24% 84.32% +0.07%
==========================================
Files 709 709
Lines 70236 70278 +42
Branches 3623 3619 -4
==========================================
+ Hits 59169 59259 +90
+ Misses 9900 9851 -49
- Partials 1167 1168 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: OutisLi <137472077+OutisLi@users.noreply.github.com>
There was a problem hiding this 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
🧹 Nitpick comments (3)
source/tests/pt/test_model_compression_se_e3_tebd.py (3)
35-175: Sharedinput.jsonand duplicated cleanup paths are a bit surprisingAll three
_init_models*helpers write to the sametests_path / "input.json"andsetUpModulebinds bothINPUTandINPUT_ETto that path.tearDownModulethen deletes both, which works because_file_deleteis tolerant of missing files, but the implicit sharing is non-obvious and could become fragile if other tests also rely oninput.jsonin the same directory or if CWD differs.Similarly, the cleanup of artifacts like
"checkpoint"and"model-compression"uses bare relative paths, which assumes a particular working directory layout.Consider, as a low-priority cleanup:
- Giving each scenario its own input filename (e.g.
input-se-e3-tebd.json,input-se-e3-tebd-exclude-types.json,input-se-e3-tebd-skip-neighbor-stat.json) and deleting those explicitly.- Optionally prefixing the artifact paths with
tests_path(if appropriate for this test suite) to avoid depending on the process CWD.This would make the setup/teardown behavior more explicit and easier to maintain.
Also applies to: 177-198
205-225: Deduplicate repeated coordinate andatypeliterals across classesThe same
coordsandatypearrays are hard-coded in each test class. This works, but it does increase maintenance overhead and the risk of accidental drift if one copy is edited without updating the others.If you want to reduce duplication, consider factoring these into a shared helper or base mixin, e.g. a small function that returns
(coords, atype)or a common test base class that defines them as class attributes reused by all the subclasses.Based on learnings, similar refactors between closely related PBC/no-PBC tests have been done elsewhere in this repo, so this would be consistent with that direction.
Also applies to: 329-349, 438-457, 545-565, 670-689
510-538: Addpbc=TruetoAtomsobjects to exercise PBC code pathThe
test_asetest currently exercises only the non-PBC branch ofDP.calculate(). Althoughcellis provided to bothAtomsobjects, thepbcparameter defaults toFalsein ASE. TheDP.calculate()method checksif sum(self.atoms.get_pbc()) > 0:(lines 131-134) and only uses the cell when at least one PBC dimension is enabled; otherwise, it setscell = Nonebefore evaluation.To validate PBC behavior for the ASE-calculator integration, explicitly set
pbc=Trueon bothAtomsobjects:water0 = Atoms( "OHHOHH", positions=self.coords.reshape((-1, 3)), cell=self.box.reshape((3, 3)), + pbc=True, calculator=DP(FROZEN_MODEL), ) water1 = Atoms( "OHHOHH", positions=self.coords.reshape((-1, 3)), cell=self.box.reshape((3, 3)), + pbc=True, calculator=DP(COMPRESSED_MODEL), )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
source/tests/pt/test_model_compression_se_e3_tebd.py(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-08T15:32:11.479Z
Learnt from: njzjz
Repo: deepmodeling/deepmd-kit PR: 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.
Applied to files:
source/tests/pt/test_model_compression_se_e3_tebd.py
🧬 Code graph analysis (1)
source/tests/pt/test_model_compression_se_e3_tebd.py (1)
deepmd/calculator.py (1)
DP(36-159)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
- GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
- GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
- GitHub Check: Test Python (3, 3.9)
- GitHub Check: Test Python (5, 3.12)
- GitHub Check: Test Python (4, 3.12)
- GitHub Check: Test Python (6, 3.12)
- GitHub Check: Test Python (5, 3.9)
- GitHub Check: Test Python (2, 3.12)
- GitHub Check: Test Python (6, 3.9)
- GitHub Check: Test Python (4, 3.9)
- GitHub Check: Test Python (2, 3.9)
- GitHub Check: Test Python (3, 3.12)
- GitHub Check: Test Python (1, 3.12)
- GitHub Check: Test Python (1, 3.9)
- GitHub Check: Test C++ (true)
- GitHub Check: Test C++ (false)
- GitHub Check: Build wheels for cp311-win_amd64
- GitHub Check: Analyze (python)
- GitHub Check: Build wheels for cp310-manylinux_aarch64
- GitHub Check: Analyze (c-cpp)
- GitHub Check: Build wheels for cp311-manylinux_x86_64
- GitHub Check: Build wheels for cp311-manylinux_x86_64
- GitHub Check: Build wheels for cp311-macosx_x86_64
- GitHub Check: Build wheels for cp311-macosx_arm64
- GitHub Check: Build C++ (cuda120, cuda)
- GitHub Check: Build C++ (rocm, rocm)
- GitHub Check: Build C++ (cpu, cpu)
- GitHub Check: Build C++ (clang, clang)
- GitHub Check: Build C++ (cuda, cuda)
🔇 Additional comments (1)
source/tests/pt/test_model_compression_se_e3_tebd.py (1)
28-33: Utility_file_deleteis simple and robustThe helper correctly handles both files and directories and is safely idempotent for missing paths. No changes needed here.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.