Skip to content

Commit f47c45a

Browse files
fix type annotations and refine docstrings
1 parent 8c29799 commit f47c45a

14 files changed

Lines changed: 117 additions & 45 deletions

File tree

deepmd/pd/model/atomic_model/base_atomic_model.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,16 @@ def get_type_map(self) -> list[str]:
134134
"""Get the type map."""
135135
return self.type_map
136136

137-
def get_buffer_type_map(self) -> list[str]:
138-
"""Get the type map."""
137+
def get_buffer_type_map(self) -> paddle.Tensor:
138+
"""
139+
Return the type map as a buffer-style Tensor for JIT saving.
140+
141+
The original type map (e.g., ['Ni', 'O']) is first joined into a single space-separated string
142+
(e.g., "Ni O"). Each character in this string is then converted to its ASCII code using `ord()`,
143+
and the resulting integer sequence is stored as a 1D paddle.Tensor of dtype int.
144+
145+
This format allows the type map to be serialized as a raw byte buffer during JIT model saving.
146+
"""
139147
return self.buffer_type_map
140148

141149
def get_compute_stats_distinguish_types(self) -> bool:
@@ -602,7 +610,7 @@ def _store_out_stat(
602610
def get_ntypes(self):
603611
return len(self.type_map)
604612

605-
def get_buffer_ntypes(self):
613+
def get_buffer_ntypes(self) -> paddle.Tensor:
606614
return self.buffer_ntypes
607615

608616
def _fetch_out_stat(

deepmd/pd/model/atomic_model/dp_atomic_model.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,23 @@ def get_sel(self) -> list[int]:
160160
return self.sel
161161

162162
def get_buffer_type_map(self) -> paddle.Tensor:
163-
"""Get the neighbor selection."""
163+
"""
164+
Return the type map as a buffer-style Tensor for JIT saving.
165+
166+
The original type map (e.g., ['Ni', 'O']) is first joined into a single space-separated string
167+
(e.g., "Ni O"). Each character in this string is then converted to its ASCII code using `ord()`,
168+
and the resulting integer sequence is stored as a 1D paddle.Tensor of dtype int.
169+
170+
This format allows the type map to be serialized as a raw byte buffer during JIT model saving.
171+
"""
164172
return self.buffer_type_map
165173

166174
def get_buffer_rcut(self) -> paddle.Tensor:
167-
"""Get the cut-off radius."""
175+
"""Get the cut-off radius as a buffer-style Tensor."""
168176
return self.descriptor.get_buffer_rcut()
169177

170178
def get_buffer_sel(self) -> paddle.Tensor:
171-
"""Get the neighbor selection."""
179+
"""Get the neighbor selection as a buffer-style Tensor."""
172180
return self.descriptor.get_buffer_sel()
173181

174182
def set_case_embd(self, case_idx: int) -> None:
@@ -400,7 +408,7 @@ def get_dim_fparam(self) -> int:
400408
return self.fitting_net.get_dim_fparam()
401409

402410
def get_buffer_dim_fparam(self) -> paddle.Tensor:
403-
"""Get the number (dimension) of frame parameters of this atomic model."""
411+
"""Get the number (dimension) of frame parameters of this atomic model as a buffer-style Tensor."""
404412
return self.fitting_net.get_buffer_dim_fparam()
405413

406414
def has_default_fparam(self) -> bool:
@@ -412,7 +420,7 @@ def get_dim_aparam(self) -> int:
412420
return self.fitting_net.get_dim_aparam()
413421

414422
def get_buffer_dim_aparam(self) -> paddle.Tensor:
415-
"""Get the number (dimension) of atomic parameters of this atomic model."""
423+
"""Get the number (dimension) of atomic parameters of this atomic model as a buffer-style Tensor."""
416424
return self.fitting_net.get_buffer_dim_aparam()
417425

418426
def get_sel_type(self) -> list[int]:

deepmd/pd/model/descriptor/dpa1.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,16 @@ def get_rcut(self) -> float:
325325
"""Returns the cut-off radius."""
326326
return self.se_atten.get_rcut()
327327

328-
def get_buffer_rcut(self) -> float:
329-
"""Returns the cut-off radius."""
328+
def get_buffer_rcut(self) -> paddle.Tensor:
329+
"""Returns the cut-off radius as a buffer-style Tensor."""
330330
return self.se_atten.get_buffer_rcut()
331331

332332
def get_rcut_smth(self) -> float:
333333
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
334334
return self.se_atten.get_rcut_smth()
335335

336-
def get_buffer_rcut_smth(self) -> float:
337-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
336+
def get_buffer_rcut_smth(self) -> paddle.Tensor:
337+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
338338
return self.se_atten.get_buffer_rcut_smth()
339339

340340
def get_nsel(self) -> int:
@@ -354,7 +354,15 @@ def get_type_map(self) -> list[str]:
354354
return self.type_map
355355

356356
def get_buffer_type_map(self) -> paddle.Tensor:
357-
"""Get the name to each type of atoms."""
357+
"""
358+
Return the type map as a buffer-style Tensor for JIT saving.
359+
360+
The original type map (e.g., ['Ni', 'O']) is first joined into a single space-separated string
361+
(e.g., "Ni O"). Each character in this string is then converted to its ASCII code using `ord()`,
362+
and the resulting integer sequence is stored as a 1D paddle.Tensor of dtype int.
363+
364+
This format allows the type map to be serialized as a raw byte buffer during JIT model saving.
365+
"""
358366
return self.buffer_type_map
359367

360368
def get_dim_out(self) -> int:

deepmd/pd/model/descriptor/dpa2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def get_buffer_rcut(self) -> paddle.Tensor:
345345
return self.repinit.get_buffer_rcut()
346346

347347
def get_buffer_rcut_smth(self) -> paddle.Tensor:
348-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
348+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
349349
return self.repinit.get_buffer_rcut_smth()
350350

351351
def get_nsel(self) -> int:

deepmd/pd/model/descriptor/dpa3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ def get_rcut_smth(self) -> float:
230230
return self.rcut_smth
231231

232232
def get_buffer_rcut(self) -> paddle.Tensor:
233-
"""Returns the cut-off radius."""
233+
"""Returns the cut-off radius as a buffer-style Tensor."""
234234
return self.repflows.get_buffer_rcut()
235235

236236
def get_buffer_rcut_smth(self) -> paddle.Tensor:
237-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
237+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
238238
return self.repflows.get_buffer_rcut_smth()
239239

240240
def get_nsel(self) -> int:
@@ -246,7 +246,7 @@ def get_sel(self) -> list[int]:
246246
return self.sel
247247

248248
def get_buffer_sel(self) -> paddle.Tensor:
249-
"""Returns the number of selected atoms for each type."""
249+
"""Returns the number of selected atoms for each type as a buffer-style Tensor."""
250250
return self.repflows.get_sel()
251251

252252
def get_ntypes(self) -> int:
@@ -258,7 +258,15 @@ def get_type_map(self) -> list[str]:
258258
return self.type_map
259259

260260
def get_buffer_type_map(self) -> paddle.Tensor:
261-
"""Get the name to each type of atoms."""
261+
"""
262+
Return the type map as a buffer-style Tensor for JIT saving.
263+
264+
The original type map (e.g., ['Ni', 'O']) is first joined into a single space-separated string
265+
(e.g., "Ni O"). Each character in this string is then converted to its ASCII code using `ord()`,
266+
and the resulting integer sequence is stored as a 1D paddle.Tensor of dtype int.
267+
268+
This format allows the type map to be serialized as a raw byte buffer during JIT model saving.
269+
"""
262270
return self.buffer_type_map
263271

264272
def get_dim_out(self) -> int:

deepmd/pd/model/descriptor/repflows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def get_rcut(self) -> float:
361361
return self.e_rcut
362362

363363
def get_buffer_rcut(self) -> paddle.Tensor:
364-
"""Returns the cut-off radius."""
364+
"""Returns the cut-off radius as a buffer-style Tensor."""
365365
return self.buffer_rcut
366366

367367
def get_rcut_smth(self) -> float:
@@ -377,7 +377,7 @@ def get_sel(self) -> list[int]:
377377
return self.sel
378378

379379
def get_buffer_sel(self) -> paddle.Tensor:
380-
"""Returns the number of selected atoms for each type."""
380+
"""Returns the number of selected atoms for each type as a buffer-style Tensor."""
381381
return self.buffer_sel
382382

383383
def get_ntypes(self) -> int:

deepmd/pd/model/descriptor/repformers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ def get_rcut_smth(self) -> float:
330330
return self.rcut_smth
331331

332332
def get_buffer_rcut(self) -> paddle.Tensor:
333-
"""Returns the cut-off radius."""
333+
"""Returns the cut-off radius as a buffer-style Tensor."""
334334
return self.buffer_rcut
335335

336336
def get_buffer_rcut_smth(self) -> paddle.Tensor:
337-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
337+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
338338
return self.buffer_rcut_smth
339339

340340
def get_nsel(self) -> int:

deepmd/pd/model/descriptor/se_a.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ def get_rcut_smth(self) -> float:
128128
return self.sea.get_rcut_smth()
129129

130130
def get_buffer_rcut(self) -> paddle.Tensor:
131-
"""Returns the cut-off radius."""
131+
"""Returns the cut-off radius as a buffer-style Tensor."""
132132
return self.sea.get_buffer_rcut()
133133

134134
def get_buffer_rcut_smth(self) -> paddle.Tensor:
135-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
135+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
136136
return self.sea.get_buffer_rcut_smth()
137137

138138
def get_nsel(self) -> int:
@@ -152,7 +152,15 @@ def get_type_map(self) -> list[str]:
152152
return self.type_map
153153

154154
def get_buffer_type_map(self) -> paddle.Tensor:
155-
"""Get the name to each type of atoms."""
155+
"""
156+
Return the type map as a buffer-style Tensor for JIT saving.
157+
158+
The original type map (e.g., ['Ni', 'O']) is first joined into a single space-separated string
159+
(e.g., "Ni O"). Each character in this string is then converted to its ASCII code using `ord()`,
160+
and the resulting integer sequence is stored as a 1D paddle.Tensor of dtype int.
161+
162+
This format allows the type map to be serialized as a raw byte buffer during JIT model saving.
163+
"""
156164
return self.buffer_type_map
157165

158166
def get_dim_out(self) -> int:
@@ -536,11 +544,11 @@ def get_rcut_smth(self) -> float:
536544
return self.rcut_smth
537545

538546
def get_buffer_rcut(self) -> paddle.Tensor:
539-
"""Returns the cut-off radius."""
547+
"""Returns the cut-off radius as a buffer-style Tensor."""
540548
return self.buffer_rcut
541549

542550
def get_buffer_rcut_smth(self) -> paddle.Tensor:
543-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
551+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
544552
return self.buffer_rcut_smth
545553

546554
def get_nsel(self) -> int:

deepmd/pd/model/descriptor/se_atten.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ def get_rcut_smth(self) -> float:
285285
return self.rcut_smth
286286

287287
def get_buffer_rcut(self) -> paddle.Tensor:
288-
"""Returns the cut-off radius."""
288+
"""Returns the cut-off radius as a buffer-style Tensor."""
289289
return self.buffer_rcut
290290

291291
def get_buffer_rcut_smth(self) -> paddle.Tensor:
292-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
292+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
293293
return self.buffer_rcut_smth
294294

295295
def get_nsel(self) -> int:

deepmd/pd/model/descriptor/se_t_tebd.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,15 @@ def get_type_map(self) -> list[str]:
214214
return self.type_map
215215

216216
def get_buffer_type_map(self) -> paddle.Tensor:
217-
"""Get the name to each type of atoms."""
217+
"""
218+
Return the type map as a buffer-style Tensor for JIT saving.
219+
220+
The original type map (e.g., ['Ni', 'O']) is first joined into a single space-separated string
221+
(e.g., "Ni O"). Each character in this string is then converted to its ASCII code using `ord()`,
222+
and the resulting integer sequence is stored as a 1D paddle.Tensor of dtype int.
223+
224+
This format allows the type map to be serialized as a raw byte buffer during JIT model saving.
225+
"""
218226
return self.buffer_type_map
219227

220228
def get_dim_out(self) -> int:
@@ -631,11 +639,11 @@ def get_rcut_smth(self) -> float:
631639
return self.rcut_smth
632640

633641
def get_buffer_rcut(self) -> paddle.Tensor:
634-
"""Returns the cut-off radius."""
642+
"""Returns the cut-off radius as a buffer-style Tensor."""
635643
return self.buffer_rcut
636644

637645
def get_buffer_rcut_smth(self) -> paddle.Tensor:
638-
"""Returns the radius where the neighbor information starts to smoothly decay to 0."""
646+
"""Returns the radius where the neighbor information starts to smoothly decay to 0 as a buffer-style Tensor."""
639647
return self.buffer_rcut_smth
640648

641649
def get_nsel(self) -> int:

0 commit comments

Comments
 (0)