Skip to content

Commit e7e617f

Browse files
author
Han Wang
committed
fix(loss): drop dead None stores flagged by CodeQL
The inv/_nf/_nloc locals are only read inside if maskf is not None guards, so the = None fallbacks in the else branch were dead stores (their None value is never read). CodeQL flagged all three per file as unused. Remove them and note why the names can stay unset when maskf is None. Pure no-op: no runtime behavior change.
1 parent 4990db2 commit e7e617f

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

deepmd/dpmodel/loss/ener.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,9 @@ def call(
232232
_nf = maskf.shape[0]
233233
_nloc = maskf.shape[1]
234234
else:
235+
# inv, _nf, _nloc are only read inside ``if maskf is not None`` guards,
236+
# so leaving them unset here is safe (and avoids dead-store warnings).
235237
maskf = None
236-
inv = None
237-
_nf = None
238-
_nloc = None
239238

240239
if self.enable_atom_ener_coeff:
241240
# when ener_coeff (\nu) is defined, the energy is defined as

deepmd/dpmodel/loss/ener_spin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ def call(
141141
_nf = maskf.shape[0]
142142
_nloc = maskf.shape[1]
143143
else:
144+
# inv, _nf, _nloc are only read inside ``if maskf is not None`` guards,
145+
# so leaving them unset here is safe (and avoids dead-store warnings).
144146
maskf = None
145-
inv = None
146-
_nf = None
147-
_nloc = None
148147

149148
if self.has_e:
150149
energy_pred = model_dict["energy"]

deepmd/pt/loss/ener.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ def forward(
248248
_nf = maskf.shape[0]
249249
_nloc = maskf.shape[1]
250250
else:
251+
# inv, _nf, _nloc are only read inside ``if maskf is not None`` guards,
252+
# so leaving them unset here is safe (and avoids dead-store warnings).
251253
maskf = None
252-
inv = None
253-
_nf = None
254-
_nloc = None
255254
# Normalization exponent controls loss scaling with system size:
256255
# - norm_exp=2 (intensive_ener_virial=True): loss uses 1/N² scaling, making it independent of system size
257256
# - norm_exp=1 (intensive_ener_virial=False, legacy): loss uses 1/N scaling, which varies with system size

deepmd/pt/loss/ener_spin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ def forward(
169169
_nf = maskf.shape[0]
170170
_nloc = maskf.shape[1]
171171
else:
172+
# inv, _nf, _nloc are only read inside ``if maskf is not None`` guards,
173+
# so leaving them unset here is safe (and avoids dead-store warnings).
172174
maskf = None
173-
inv = None
174-
_nf = None
175-
_nloc = None
176175

177176
if self.has_e and "energy" in model_pred and "energy" in label:
178177
energy_pred = model_pred["energy"]

0 commit comments

Comments
 (0)