Skip to content

Commit 178fe36

Browse files
Copilotnjzjz
andcommitted
feat(paddle): Enable ANN rule for 3 additional utility files with type annotations
- Enable ANN rule for 3 more files, expanding from 31 to 34 total files: - utils/serialization.py: Serialization utilities (already complete) - utils/region.py: Region computation functions with tensor type annotations - utils/exclude_mask.py: Atom and pair exclusion mask classes with proper type hints - Added return type annotation to b_to_face_distance function in region.py - Added comprehensive type annotations to AtomExcludeMask and PairExcludeMask classes - Fixed getter methods with proper return types: list[int], paddle.Tensor, set[tuple[int, int]] - Progress: 34 files now have ANN rule fully enabled (3,300% increase from initial 1 file) Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
1 parent f673c2e commit 178fe36

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

deepmd/pd/utils/exclude_mask.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def reinit(
3232
)
3333
self.type_mask = to_paddle_tensor(self.type_mask).reshape([-1])
3434

35-
def get_exclude_types(self):
35+
def get_exclude_types(self) -> list[int]:
3636
return self.exclude_types
3737

38-
def get_type_mask(self):
38+
def get_type_mask(self) -> paddle.Tensor:
3939
return self.type_mask
4040

4141
def forward(
@@ -98,7 +98,7 @@ def reinit(
9898
self.type_mask = to_paddle_tensor(self.type_mask).reshape([-1])
9999
self.no_exclusion = len(self._exclude_types) == 0
100100

101-
def get_exclude_types(self):
101+
def get_exclude_types(self) -> set[tuple[int, int]]:
102102
return self._exclude_types
103103

104104
# may have a better place for this method...

deepmd/pd/utils/region.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def to_face_distance(
7575
return dist.reshape(list(cshape[:-2]) + [3]) # noqa:RUF005
7676

7777

78-
def b_to_face_distance(cell):
78+
def b_to_face_distance(cell: paddle.Tensor) -> paddle.Tensor:
7979
volume = paddle.linalg.det(cell)
8080
c_yz = paddle.cross(cell[:, 1], cell[:, 2], axis=-1)
8181
_h2yz = volume / paddle.linalg.norm(c_yz, axis=-1)

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ runtime-evaluated-base-classes = ["torch.nn.Module"]
460460
"deepmd/pd/model/descriptor/__init__.py" = ["TID253"] # ✅ Fully typed
461461
"deepmd/pd/model/task/ener.py" = ["TID253"] # ✅ Fully typed
462462
"deepmd/pd/model/model/dp_model.py" = ["TID253"] # ✅ Fully typed
463+
"deepmd/pd/utils/serialization.py" = ["TID253"] # ✅ Fully typed
464+
"deepmd/pd/utils/region.py" = ["TID253"] # ✅ Fully typed
465+
"deepmd/pd/utils/exclude_mask.py" = ["TID253"] # ✅ Fully typed
463466
# TODO: Complete type hints and remove ANN exclusion for remaining files:
464467
"deepmd/pd/train/**" = ["TID253", "ANN"] # 🚧 Partial progress - training.py still needs work
465468
"deepmd/pd/utils/**" = ["TID253", "ANN"] # 🚧 Partial progress - utils.py partially done

0 commit comments

Comments
 (0)