fix(deepmd/hdf5): skip empty optional frame arrays on dump (#996)#1011
fix(deepmd/hdf5): skip empty optional frame arrays on dump (#996)#1011CedricConday wants to merge 1 commit into
Conversation
…ing#996) The deepmd/hdf5 writer reshaped and wrote optional frame arrays (e.g. forces or virials that are empty when cal_force/cal_stress is disabled) as a (nframes, 0) dataset, which the loader then failed to reshape back to the full shape, raising 'cannot reshape array of size 0'. Skip empty optional arrays on dump, matching the existing deepmd/raw and deepmd/npy writers. Non-empty arrays are unaffected.
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1011 +/- ##
=======================================
Coverage 86.87% 86.87%
=======================================
Files 89 89
Lines 8264 8266 +2
=======================================
+ Hits 7179 7181 +2
Misses 1085 1085 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe DeepMD HDF5 dump function now skips writing optional per-frame property datasets (e.g., forces) when their data is empty but the system has frames, avoiding an unreshapeable zero-width dataset on reload. Regression tests were added to verify this behavior. ChangesEmpty optional array fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested labels: `dpdata` Suggested reviewers: `iProzd`, `wanghan-iapcm`, `njzjz` 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
Fixes #996.
The
deepmd/hdf5writer reshapes and writes every optional frame array, so an empty optional property (e.g.forces/virialswhencal_force/cal_stressis disabled) is stored as a(nframes, 0)dataset. On load,to_system_datatries to reshape that zero-width dataset back to(nframes, natoms, 3)and raisesValueError: cannot reshape array of size 0.Reproducer (fails on current
master):The
deepmd/rawanddeepmd/npywriters already skip this case; this makes the HDF5 writer consistent with them by skipping an optional array whose size is 0 while the system still has frames. Non-empty arrays are written and reloaded exactly as before.Added
TestHDF5EmptyOptionalArraycovering both the previously-failing empty round-trip and a non-empty round-trip to guard against regression. Thedeepmdtest suites pass (test_deepmd_hdf5,test_deepmd_raw,test_deepmd_comp,test_deepmd_mixed) andruffis clean.Disclosure: written with AI assistance; reviewed and tested before submitting.
Summary by CodeRabbit
Bug Fixes
Tests