Commit 2ee0f579 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'CG_paranoia' into 'NIFTy_8'

check for NaN values during CG iteration

See merge request !677
parents 05fbdc34 02714e25
Pipeline #109793 passed with stages
in 31 minutes and 34 seconds
......@@ -15,6 +15,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import numpy as np
from ..logger import logger
from .minimizer import Minimizer
......@@ -71,6 +72,9 @@ class ConjugateGradient(Minimizer):
d = r if preconditioner is None else preconditioner(r)
previous_gamma = r.s_vdot(d).real
if np.isnan(previous_gamma):
logger.error("Error: ConjugateGradient: previous_gamma==NaN")
return energy, controller.ERROR
if previous_gamma == 0:
return energy, controller.CONVERGED
......@@ -78,6 +82,9 @@ class ConjugateGradient(Minimizer):
while True:
q = energy.apply_metric(d)
curv = d.s_vdot(q).real
if np.isnan(curv):
logger.error("Error: ConjugateGradient: curv==NaN")
return energy, controller.ERROR
if curv == 0.:
logger.error("Error: ConjugateGradient: curv==0.")
return energy, controller.ERROR
......@@ -99,6 +106,9 @@ class ConjugateGradient(Minimizer):
s = r if preconditioner is None else preconditioner(r)
gamma = r.s_vdot(s).real
if np.isnan(gamma):
logger.error("Error: ConjugateGradient: gamma==NaN")
return energy, controller.ERROR
if gamma < 0:
"Positive definiteness of preconditioner violated!")
......@@ -197,6 +197,8 @@ class NewtonCG(DescentMinimizer):
e, conv = ConjugateGradient(ic, nreset=self._nreset)(e, p)
if self._history is not None:
self._history += ic.history
if conv == ic.ERROR:
raise ValueError("Cannot find descent direction")
return -e.position
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment