-
Notifications
You must be signed in to change notification settings - Fork 26
test: Add comprehensive test coverage for core modules #31
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
Add 6 new test files and expand existing calculator tests to improve coverage from ~39% toward target of 65%: New test files: - tests/conftest.py: Shared fixtures for molecules, models, GPU checks - tests/test_nbops.py: Neighbor operations (25 tests) - set_nb_mode, calc_masks, mask_ij_, mask_i_, get_ij, mol_sum - All three neighbor modes (0, 1, 2) with gradient flow tests - tests/test_ops.py: Mathematical operations (34 tests) - Cutoff functions, distance calculations, Coulomb matrices - NSE charge equilibration, transition functions - tests/test_config.py: Configuration system (28 tests) - get_module, load_yaml with Jinja2, build_module - dict_to_dotted/dotted_to_dict conversions - tests/test_lr.py: Long-range Coulomb module (21 tests) - Simple, DSF, and Ewald methods with gradient tests - tests/test_calculator_gpu.py: GPU-specific tests (12 tests) - CUDA inference, GPU/CPU consistency, memory management Expanded tests/test_calculator.py (44 new tests): - Input validation and error handling - Coulomb method switching - Batch processing (2D and 3D formats) - Force, stress, Hessian calculations - Translation and rotation invariance Total: 152 tests passing (up from 18)
Code Review - PR #31: Comprehensive Test CoverageOverall AssessmentThis is an excellent PR that significantly improves test coverage from ~39% to ~65% by adding 134 new tests (18→152). The tests are well-structured, comprehensive, and follow good testing practices. Great work! 🎉 StrengthsTest Organization
Test Coverage
Code Quality
Issues Found🔴 Critical: Code Duplication in GPU TestsLocation: The CPU calculator initialization code is duplicated across multiple tests. This is a maintenance burden and violates DRY principle. Recommendation: Extract to a helper function or fixture: @pytest.fixture
def cpu_calculator():
"""Create CPU calculator instance for comparison tests."""
calc_cpu = AIMNet2Calculator.__new__(AIMNet2Calculator)
calc_cpu.device = "cpu"
from aimnet.calculators.model_registry import get_model_path
p = get_model_path("aimnet2")
calc_cpu.model = torch.jit.load(p, map_location="cpu")
calc_cpu.cutoff = calc_cpu.model.cutoff
calc_cpu.lr = hasattr(calc_cpu.model, "cutoff_lr")
calc_cpu.cutoff_lr = getattr(calc_cpu.model, "cutoff_lr", float("inf")) if calc_cpu.lr else None
calc_cpu.max_density = 0.2
calc_cpu.nb_threshold = 0
calc_cpu._batch = None
calc_cpu._max_mol_size = 0
calc_cpu._saved_for_grad = {}
calc_cpu._coulomb_method = "simple"
return calc_cpu🟡 Medium: Potential Missing Attribute InitializationLocation: Using Recommendation: Either:
🟡 Medium: Hard-coded Magic NumbersLocation: assert memory_allocated < 2e9 # Less than 2GB allocated
assert memory_reserved < 4e9 # Less than 4GB reserved
assert growth < 100e6 # Less than 100MB growthThese thresholds may fail on different GPU models or under different conditions. Recommendation: Make these configurable or calculate dynamically based on available memory. 🟢 Minor: Inconsistent Error Message MatchingLocation: Some tests use specific error message matching ( Recommendation: Consistently verify error messages to catch regression in error reporting quality. 🟢 Minor: Missing Device Fixture in Some TestsLocation:
Recommendation: Use the Performance Considerations✅ Good Practices
💡 Suggestions
Security Considerations✅ No security issues identified. The tests:
Test Coverage QualityExcellent Coverage Of:
Potential Gaps:
Recommendations SummaryMust Fix (Before Merge):
Should Fix (High Priority):
Nice to Have:
ConclusionThis is production-ready code with just one required refactoring (deduplication). The test suite is comprehensive, well-organized, and significantly improves the project's reliability. Once the duplication is addressed, this should be merged. Approval Status: ✅ Approved with minor changes requested Great work on improving test coverage! 🚀 Review generated by Claude Code |
Addresses code review feedback by extracting duplicated CPU calculator initialization code into a reusable create_cpu_calculator() helper function.
Comprehensive Test Coverage ReviewThank you for this substantial contribution! This PR significantly improves test coverage from ~39% toward 65% with 152 tests. StrengthsCode Quality
Test Design
Issues & Recommendations1. GPU Test CPU Calculator Creation (High Priority)Location: tests/test_calculator_gpu.py:36-59 The create_cpu_calculator() function uses new to bypass init, manually setting attributes. This is fragile and will break if the calculator structure changes. Recommendation: Use unittest.mock.patch to control device or add a device parameter to init. 2. Code DuplicationThe load_mol helper appears in both test_calculator.py and test_calculator_gpu.py. Move to conftest.py to maintain DRY principle. 3. Test Assertions
4. Missing Test CoverageConsider adding:
5. Performance Considerations
6. Best Practices
Priority Fixes
ConclusionThis is an excellent contribution that substantially improves test coverage and reliability. The tests are well-structured and comprehensive. The issues identified are mostly minor refinements. After addressing the high-priority create_cpu_calculator() issue, this PR will be in great shape to merge. Recommendation: Approve after addressing Issue 1 Great work! |
Signed-off-by: isayev <olexandr@olexandrisayev.com>
Signed-off-by: isayev <olexandr@olexandrisayev.com>
Code Review: PR #31 - Comprehensive Test CoverageSummaryThis PR significantly improves test coverage from ~39% to ~65% by adding 134 new tests across 6 new test files. The changes include both new test modules and important bug fixes in the core codebase. Overall, this is an excellent contribution that will greatly improve code reliability. Positive Highlights ✅Test Organization
Code Quality
Bug Fixes
Issues & Recommendations1. GPU Test CPU Fallback Implementation
|
Summary
New Test Files
tests/conftest.pytests/test_nbops.pytests/test_ops.pytests/test_config.pytests/test_lr.pytests/test_calculator_gpu.pyExpanded Calculator Tests
44 new tests in
test_calculator.py:Test plan
pytest tests/- 152 tests passingmake check- linting passespytest -m gpu