Commit a7a50bf
## Summary
Fixes #977.
When an ABACUS SCF run converges but does **not** compute forces/stress
(e.g. `cal_force`/`cal_stress` disabled — which is what users hit with
the new GPU `cusolver` `ks_solver`), dpdata's ABACUS parser correctly
produces a `LabeledSystem` with size-0 forces (this is an intended
state, covered by `TestABACUSLabeledOutputNoFS`).
The bug is in the **deepmd dump→load round-trip**:
- `dump` did `np.reshape(forces, [nframes, -1])`, which for empty forces
writes `force.npy` of shape `(nframes, 0)`.
- On load, `np.reshape((nframes, 0)-array, [nframes, natoms, 3])`
raises:
```
ValueError: cannot reshape array of size 0 into shape (20,64,3)
```
This is exactly the traceback reported in #977 (surfacing in dpgen's
`post_fp_check_fail`).
## Root cause investigation
- ABACUS (LTSv3.10.0) prints forces via `ModuleIO::print_force`
independent of the KS solver; `cusolver` fills the wavefunctions just
like `genelpa`/`scalapack_gvx`, and forces are computed from the density
matrix afterward. There is no code path that disables force output for
`cusolver`/`device gpu`.
- dpdata parses the v3.10.0 `FmtTable` force block correctly **when
present**.
- The crash therefore only requires a converged log with **no
`TOTAL-FORCE` block**, which dpdata represents as empty forces — and the
deepmd round-trip then corrupts it.
## Fix
In both `dpdata/formats/deepmd/comp.py` (npy) and
`dpdata/formats/deepmd/raw.py` (raw) `dump`, skip an optional frame
property whose array is empty while the system still has frames, rather
than writing a meaningless `(nframes, 0)` array:
```python
if nframes > 0 and np.asarray(data[dtype.name]).size == 0:
continue
```
A missing `force`/`virial` file is already a supported state on load
(`_cond_load_data` returns `None` and skips it), so the round-trip is
now consistent.
## Tests
Added two tests to `TestABACUSLabeledOutputNoFS` (reusing the existing
`INPUT.ch4-noforcestress` fixture):
- `test_noforcestress_deepmd_roundtrip`
- `test_noforcestress_deepmd_raw_roundtrip`
Both fail on `master` with the reported `ValueError` and pass with this
change. abacus + deepmd comp/raw/mixed/empty suites pass (312 tests); no
new failures in the full suite.
## Out of scope (user/dpgen side)
This makes dpdata robust to force-less ABACUS results. Producing usable
training labels still requires `cal_force 1`/`cal_stress 1` in the
generated `INPUT` and adding `cusolver` to dpgen's `ks_solver`
whitelist.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Bug Fixes
* Fixed an issue where empty optional properties (such as forces and
virials) were incorrectly exported as invalid empty arrays in DeePMD
format files. These properties are now properly skipped during export
when data is unavailable.
## Tests
* Added validation tests for proper handling of missing optional
properties during DeePMD format conversions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
1 parent c71799f commit a7a50bf
3 files changed
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
155 | 161 | | |
156 | 162 | | |
157 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
166 | 195 | | |
167 | 196 | | |
168 | 197 | | |
0 commit comments