Skip to content

Commit e63f2d8

Browse files
meta-forces: nan to zero
1 parent 71c6395 commit e63f2d8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

theforce/calculator/active.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from theforce.descriptor.atoms import TorchAtoms, AtomsData, LocalsData
44
from theforce.similarity.sesoap import SeSoapKernel
55
from theforce.math.sesoap import DefaultRadii
6-
from theforce.util.tensors import padded
6+
from theforce.util.tensors import padded, nan_to_num
77
from theforce.util.util import date, timestamp
88
from theforce.io.sgprio import SgprIO
99
from ase.calculators.calculator import Calculator, all_changes
@@ -343,7 +343,9 @@ def reduce(self, local_energies, op='=', retain_graph=False, reduced=False, is_m
343343
if self.atoms.is_distributed and not reduced:
344344
torch.distributed.all_reduce(energy)
345345
forces, stress = self.grads(energy, retain_graph=retain_graph)
346-
if not is_meta:
346+
if is_meta:
347+
forces = nan_to_num(forces, 0.)
348+
else:
347349
mean = self.model.mean(self.atoms)
348350
if mean.grad_fn: # only constant mean
349351
raise RuntimeError('mean has grad_fn!')

0 commit comments

Comments
 (0)