You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: unify compute_output_stats across dp, pt, and pd backends (#5267)
- Fix elif → if for index classification: A system can have both global
and atomic labels simultaneously. The old elif logic meant a system with
both find_atom_energy and find_energy would only be indexed for atomic,
silently dropping its global label.
Changed to two independent if checks in all three backends.
- Add global_sampled_idx/atomic_sampled_idx parameters:
compute_output_stats_global and compute_output_stats_atomic in pt and pd
backends now accept precomputed index dicts (matching dpmodel's
signature) instead of re-scanning systems internally.
- Support mixed type in dpmodel: compute_output_stats_global in dpmodel
now checks for real_natoms_vec (previously hardcoded natoms_key =
"natoms").
- Apply atom_exclude_types mask to natoms in dpmodel: dpmodel was
missing the exclude-type mask on natoms that pt/pd already had.
- Fix in-place mutation of input data: All three backends were mutating
sampled[i]["natoms"] (or real_natoms_vec) in-place when
atom_exclude_types was present. Now the mask is applied to a local copy,
leaving the caller's data untouched.
- Add cross-backend consistency tests: New test file
source/tests/consistent/utils/test_stat.py with 48 tests covering
dp-vs-pt and dp-vs-pd consistency for compute_output_stats_global,
compute_output_stats_atomic, and the top-level
compute_output_stats, plus no-mutation verification.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Support excluding atom types from global natoms calculations.
* Allow a system to be counted in both global and atomic sampling
simultaneously.
* **Refactor**
* Switched statistics assembly to index-based gathering for robust
mixed-type handling.
* Standardized numeric assembly/reshaping across backends for consistent
merging.
* **Tests**
* Added comprehensive cross-backend consistency tests (global, atomic,
mixed types, exclusions).
* **Chores**
* Minor unpacking/cleanup to remove unused fields.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
0 commit comments