Skip to content

Commit 26593a1

Browse files
author
Han Wang
committed
chore(dpa4): clear CodeQL notes/warning (cyclic-import, unnecessary-delete, import-and-import-from)
- Break the base_model<->dpa4_native_spin_model static import cycle by making the BaseModel import lazy inside deserialize (its only use). - Drop an unnecessary 'del keepalive' at end of a test. - Align a mixed 'import module' with the file's 'import from' style. Leaves only the py/inheritance/signature-mismatch warnings, a pre-existing repo-wide pattern on descriptor .call() overrides (present on unmodified descriptors too).
1 parent 144f245 commit 26593a1

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

deepmd/dpmodel/model/dpa4_native_spin_model.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
from deepmd.dpmodel.common import (
1313
NativeOP,
1414
)
15-
from deepmd.dpmodel.model.base_model import (
16-
BaseModel,
17-
)
1815
from deepmd.dpmodel.output_def import (
1916
FittingOutputDef,
2017
ModelOutputDef,
2118
)
19+
20+
# NOTE: ``BaseModel`` is imported lazily inside ``deserialize`` (its only use).
21+
# ``base_model`` dispatches to this module in its own ``deserialize``, so a
22+
# top-level import here would form a static import cycle (py/cyclic-import).
2223
from deepmd.utils.spin import (
2324
Spin,
2425
)
@@ -264,6 +265,12 @@ def serialize(self) -> dict:
264265

265266
@classmethod
266267
def deserialize(cls, data: dict) -> "DPA4NativeSpinModel":
268+
# Lazy import to avoid a static import cycle with ``base_model`` (which
269+
# dispatches to this module in its own ``deserialize``).
270+
from deepmd.dpmodel.model.base_model import (
271+
BaseModel,
272+
)
273+
267274
data = data.copy()
268275
data.pop("@class", None)
269276
data.pop("@version", None)

source/tests/pt_expt/model/test_dpa4_graph_lower.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def test_dpa4_exchange_border_op_self_communication() -> None:
220220
torch.testing.assert_close(out[:nlocal], x_in[:nlocal]) # owned untouched
221221
for gi, owner in enumerate(owners):
222222
torch.testing.assert_close(out[nlocal + gi], x_in[int(owner)])
223-
del keepalive
224223

225224

226225
def test_dpa4_exchange_schedule_counts() -> None:
@@ -242,7 +241,7 @@ def test_dpa4_exchange_schedule_counts() -> None:
242241
``use_env_seed`` attributes below, not hardcoded (it would differ for a
243242
fixture with an SO2-free block, which this one does not have).
244243
"""
245-
import deepmd.pt_expt.descriptor.dpa4_nn.block as blk_mod
244+
from deepmd.pt_expt.descriptor.dpa4_nn import block as blk_mod
246245

247246
device = env.DEVICE
248247
dd = _make_message_sensitive_model(device).atomic_model.descriptor

0 commit comments

Comments
 (0)