Commit b634aa3
fix(dpmodel): preserve virtual spin atom types (deepmodeling#5854)
Closes deepmodeling#5663.
## Summary
- preserve negative placeholder types when creating dense and
lower-interface spin partners
- use one array-API-safe lookup that maps virtual atom types to zero
instead of applying Python negative indexing
- zero placeholder spin displacements, virial corrections, magnetic
outputs, and magnetic masks
- add dense, lower, end-to-end invariance, and Array API strict
regressions
## Why existing tests missed this
Existing spin consistency tests use only nonnegative real atom types,
including their lower-interface ghost atoms. Negative-type tests cover
base atomic models and neighbor-list builders, where masking happens
before type-dependent work, but not `SpinModel` preprocessing, which
runs earlier. Cross-backend spin tests therefore never supplied a
nonzero padded spin or asserted that both the real placeholder and its
generated spin partner remained negative.
## Validation
- `pytest source/tests/common/dpmodel/test_spin_model_virtual_types.py
source/tests/common/dpmodel/test_finetune_spin.py
source/tests/common/dpmodel/test_spin_model_legacy_routing.py -q` (12
passed)
- `ruff format .` (1664 files unchanged on final pass)
- `ruff check .` (passed)
- `git diff --check` (passed)
Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Bug Fixes**
- Improved spin-model handling of padded and virtual atom placeholders.
- Prevented placeholder atoms from receiving displacement, virial,
scaling, or magnetic-output corrections.
- Ensured consistent behavior across standard and lower-level spin
processing paths.
- Improved compatibility across supported array backends and processing
devices.
- **Tests**
- Added regression coverage for virtual placeholders, masking, output
handling, and consistency between model backends.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: njzjz-bot <njzjz.bot@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent 1b3c9e9 commit b634aa3
4 files changed
Lines changed: 463 additions & 35 deletions
File tree
- deepmd
- dpmodel/model
- pt/model/model
- source/tests
- common/dpmodel
- pt/model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
86 | 100 | | |
87 | 101 | | |
88 | 102 | | |
| |||
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
105 | 122 | | |
106 | 123 | | |
107 | 124 | | |
| |||
153 | 170 | | |
154 | 171 | | |
155 | 172 | | |
156 | | - | |
157 | 173 | | |
158 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
159 | 178 | | |
160 | 179 | | |
161 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
162 | 185 | | |
163 | 186 | | |
164 | 187 | | |
| |||
224 | 247 | | |
225 | 248 | | |
226 | 249 | | |
227 | | - | |
228 | | - | |
229 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
230 | 262 | | |
231 | 263 | | |
232 | 264 | | |
| |||
250 | 282 | | |
251 | 283 | | |
252 | 284 | | |
253 | | - | |
254 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
255 | 295 | | |
256 | 296 | | |
257 | | - | |
258 | | - | |
| 297 | + | |
| 298 | + | |
259 | 299 | | |
260 | 300 | | |
261 | 301 | | |
262 | 302 | | |
263 | 303 | | |
264 | | - | |
265 | | - | |
| 304 | + | |
| 305 | + | |
266 | 306 | | |
267 | 307 | | |
268 | 308 | | |
| |||
700 | 740 | | |
701 | 741 | | |
702 | 742 | | |
703 | | - | |
704 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
705 | 747 | | |
706 | 748 | | |
707 | 749 | | |
| |||
883 | 925 | | |
884 | 926 | | |
885 | 927 | | |
886 | | - | |
887 | | - | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
888 | 934 | | |
889 | 935 | | |
890 | 936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
107 | | - | |
108 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
| |||
140 | 148 | | |
141 | 149 | | |
142 | 150 | | |
143 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
193 | 206 | | |
194 | 207 | | |
195 | 208 | | |
196 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
197 | 214 | | |
198 | 215 | | |
199 | 216 | | |
| |||
0 commit comments