Commit ed691aa
refactor(model): express analytical bridging as an explicit linear_ener composition (deepmodeling#5964)
Close deepmodeling#5948.
A bridged model IS a linear composition, but it was spelled as a
`bridging_method` flag on a non-composite model type. The type you
requested was not the type you got, and every builder that accepted the
flag re-implemented the composition (and drifted; see deepmodeling#5947).
## Canonical spelling
```json
"model": {
"type": "linear_ener", "weights": "sum", "type_map": ["Ni", "O"],
"models": [
{"type": "dpa4", "descriptor": {"...": "..."}, "fitting_net": {"...": "..."}},
{"type": "inner_potential", "mode": "zbl", "r_inner": 0.8, "r_outer": 1.2}
]
}
```
## Changes, by issue task
1. **`inner_potential` is a config-level model type.** Registered in
argcheck (`mode`, `r_inner`, `r_outer`), so it can be named as a
`linear_ener` child. It is buildable only inside a composition.
2. **The composition derives the descriptor coupling.** The linear
builder writes the learned sibling descriptor's
`inner_clamp_r_inner`/`_outer` from the `inner_potential` child at build
time. The radii are written once; one source of truth.
3. **`pair_exclude_types` belongs to the composition.** The canonical
builders do no promotion; the composition-level key governs both
children by construction. The legacy promotion semantics of the pt
`type: "dpa4"` builder survive only inside the sugar expansion, so the
two bridged routes of deepmodeling#5947 can no longer diverge (the ~80 eV builder
disagreement is gone: both spellings of the flag now expand
identically). Full deletion of the non-bridged promotion stays with
deepmodeling#5947's deprecation cycle.
4. **`bridging_method` is sugar with ONE owner.**
`deepmd.utils.bridging.expand_bridging_method` expands the flag into the
canonical form at every backend's `get_model` entry. The non-composite
builders (`get_standard_model`, `get_sezm_model`) fail fast on the flag
instead of composing — or, as pt's standard route used to do, silently
dropping it.
5. **pt and pt_expt land together.** dpmodel gains a real `linear_ener`
config builder (it previously had none); its child-parsing core is
shared with pt_expt. pt realizes the canonical form through its existing
`SeZMModel` implementation, so pt checkpoints and physics are unchanged.
Native-scheme spin combines with the canonical form: a top-level `spin`
section on a `linear_ener` config wraps the composition as
`NativeSpinEnergyModel` (dpmodel/pt_expt) or routes to the SeZM spin
builder (pt).
## Both spellings are supported, by design
The concise `type: "dpa4"` + `bridging_method` form is the **recommended
user interface** (it is shorter, and existing inputs/checkpoints keep
working with no migration). The explicit `linear_ener` +
`inner_potential` form is the **canonical internal semantics**: all
builders construct only it, so the concise form is pure rewriting and
cannot drift. `examples/water/dpa4/input-zbl.json` keeps the concise
form; `doc/model/dpa4.md` documents the concise form first and shows the
explicit equivalent.
## Tests
- `source/tests/common/test_bridging.py` (new): 16 normalizer unit tests
— key routing, promotion, mismatch error, spin passthrough, rejections,
inactive-flag passthrough.
- `source/tests/common/dpmodel/test_zbl_bridging.py`: canonical-vs-sugar
tests — identical energy (exact equality) and identical serialized wire
dict, plus shape rejections and the standard-builder fail-fast.
- `source/tests/pt/model/test_get_model_bridging.py` (new): canonical →
`SeZMModel` with identical serialization to the sugar form; rejections
(`weights != "sum"`, non-DPA4 sibling, two inner children); plain
`linear_ener` unaffected.
- `source/tests/pt_expt/model/test_get_model_bridging.py`: updated to
the new contract (flag on `type: standard` now composes through
`get_model`); canonical composition, canonical native-spin, serialize
parity, builder fail-fasts.
- Suites run locally and green: dpmodel common (1127 passed), pt_expt
`test_zbl_bridging` / `test_get_model_bridging` / `test_get_model_dpa4`
/ `test_linear_model`, pt sezm model + spin + linear suites, consistency
`test_linear_ener`, `test_examples`.
## Known limitations
- **pt is a mapping, not a composition.** The pt backend implements
bridging inside `SeZMModel`, so its linear builder maps the canonical
config back onto `SeZMModel` constructor arguments. Physics and
checkpoint format are byte-identical to the flag form (pinned by a
serialize-equality test), but pt's internal ownership still differs from
dpmodel/pt_expt.
- **pt is stricter on split exclusion scopes.** A canonical config whose
learned child sets `descriptor.exclude_types` different from the
composition's `pair_exclude_types` raises in pt (SeZM mismatch check)
while dpmodel/pt_expt accept the two scopes independently (deepmodeling#5947
territory).
- The non-bridged `descriptor.exclude_types` promotion in
`get_sezm_model` (pt, pt_expt) is untouched; removing it is deepmodeling#5947's
staged deprecation.
- No end-to-end `dp train` run or GPU `.pt2` export with a canonical
config in this PR; construction, argcheck, serialization, and energy
parity are unit-tested. Two locally failing AOTI freeze tests are the
known pre-existing torch 2.11 CPU-SIMD inductor bug (they pass with
`cpp.simdlen = 1`; master fails identically).
- Multi-task `shared_dict` combined with an `inner_potential` child is
rejected, not supported.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added linear-energy compositions combining learned, descriptor-based,
pair-tabulated, and analytical inner-potential models.
* Added native-spin support and configurable clamping radii for these
compositions.
* Added automatic ZBL bridging expansion with validation, shared
exclusions, and equivalent shorthand/canonical configurations.
* Added support for bridged models in inference, checkpoint freezing,
serialization, and model updates.
* **Documentation**
* Updated DPA4 ZBL bridging guidance, recommended configurations, and
compatibility details.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent 90aec0a commit ed691aa
18 files changed
Lines changed: 2357 additions & 241 deletions
File tree
- deepmd
- dpmodel/model
- pt_expt/model
- pt
- entrypoints
- infer
- model/model
- tf/model
- utils
- doc/model
- source/tests
- common
- dpmodel
- pt_expt/model
- pt/model
- tf
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 64 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
86 | 96 | | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
105 | 125 | | |
106 | 126 | | |
107 | 127 | | |
| |||
135 | 155 | | |
136 | 156 | | |
137 | 157 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
146 | 162 | | |
147 | 163 | | |
148 | 164 | | |
| |||
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
| 214 | + | |
198 | 215 | | |
199 | 216 | | |
200 | 217 | | |
201 | 218 | | |
202 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
203 | 223 | | |
0 commit comments