Skip to content

Commit

Permalink
Safediv to avoid nan generation in conngould trust radius...
Browse files Browse the repository at this point in the history
This is necessary to avoid tripng the jax nan debugger
  • Loading branch information
unalmis committed Dec 22, 2024
1 parent 34dbac0 commit 6e9bdab
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions desc/optimize/least_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from scipy.optimize import OptimizeResult

from desc.backend import jnp, qr
from desc.utils import errorif, setdefault
from desc.utils import errorif, safediv, setdefault

from .bound_utils import (
cl_scaling_vector,
Expand Down Expand Up @@ -208,14 +208,12 @@ def lsqtr( # noqa: C901
# conngould : norm of the cauchy point, as recommended in ch17 of Conn & Gould
# scipy : norm of the scaled x, as used in scipy
# mix : geometric mean of conngould and scipy
scipy = jnp.linalg.norm(x * scale_inv / v**0.5)
conngould = safediv(jnp.sum(g_h**2), jnp.sum((J_h @ g_h) ** 2))
init_tr = {
"scipy": jnp.linalg.norm(x * scale_inv / v**0.5),
"conngould": jnp.sum(g_h**2) / jnp.sum((J_h @ g_h) ** 2),
"mix": jnp.sqrt(
jnp.sum(g_h**2)
/ jnp.sum((J_h @ g_h) ** 2)
* jnp.linalg.norm(x * scale_inv / v**0.5)
),
"scipy": scipy,
"conngould": conngould,
"mix": jnp.sqrt(conngould * scipy),
}
trust_radius = options.pop("initial_trust_radius", "scipy")
tr_ratio = options.pop("initial_trust_ratio", 1.0)
Expand Down

0 comments on commit 6e9bdab

Please sign in to comment.