Skip to content

Commit

Permalink
Merge branch 'master' into select_gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
YigitElma authored Dec 24, 2024
2 parents f90973b + e357a9b commit 23e2ece
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
12 changes: 6 additions & 6 deletions desc/optimize/aug_lagrangian.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from scipy.optimize import BFGS, NonlinearConstraint, OptimizeResult

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

from .bound_utils import (
cl_scaling_vector,
Expand Down Expand Up @@ -350,12 +350,12 @@ def laghess(z, y, mu, *args):
# 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
tr_scipy = jnp.linalg.norm(z * scale_inv / v**0.5)
conngould = safediv(g_h @ g_h, abs(g_h @ H_h @ g_h))
init_tr = {
"scipy": jnp.linalg.norm(z * scale_inv / v**0.5),
"conngould": (g_h @ g_h) / abs(g_h @ H_h @ g_h),
"mix": jnp.sqrt(
(g_h @ g_h) / abs(g_h @ H_h @ g_h) * jnp.linalg.norm(z * scale_inv / v**0.5)
),
"scipy": tr_scipy,
"conngould": conngould,
"mix": jnp.sqrt(conngould * tr_scipy),
}
trust_radius = options.pop("initial_trust_radius", "conngould")
tr_ratio = options.pop("initial_trust_ratio", 1.0)
Expand Down
14 changes: 6 additions & 8 deletions desc/optimize/aug_lagrangian_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from scipy.optimize import NonlinearConstraint, 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 @@ -289,14 +289,12 @@ def lagjac(z, y, mu, *args):
# 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
tr_scipy = jnp.linalg.norm(z * 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(z * 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(z * scale_inv / v**0.5)
),
"scipy": tr_scipy,
"conngould": conngould,
"mix": jnp.sqrt(conngould * tr_scipy),
}
trust_radius = options.pop("initial_trust_radius", "conngould")
tr_ratio = options.pop("initial_trust_ratio", 1.0)
Expand Down
12 changes: 6 additions & 6 deletions desc/optimize/fmin_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from scipy.optimize import BFGS, OptimizeResult

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

from .bound_utils import (
cl_scaling_vector,
Expand Down Expand Up @@ -247,12 +247,12 @@ def fmintr( # 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
tr_scipy = jnp.linalg.norm(x * scale_inv / v**0.5)
conngould = safediv(g_h @ g_h, abs(g_h @ H_h @ g_h))
init_tr = {
"scipy": jnp.linalg.norm(x * scale_inv / v**0.5),
"conngould": (g_h @ g_h) / abs(g_h @ H_h @ g_h),
"mix": jnp.sqrt(
(g_h @ g_h) / abs(g_h @ H_h @ g_h) * jnp.linalg.norm(x * scale_inv / v**0.5)
),
"scipy": tr_scipy,
"conngould": conngould,
"mix": jnp.sqrt(conngould * tr_scipy),
}
trust_radius = options.pop("initial_trust_radius", "scipy")
tr_ratio = options.pop("initial_trust_ratio", 1.0)
Expand Down
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
tr_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": tr_scipy,
"conngould": conngould,
"mix": jnp.sqrt(conngould * tr_scipy),
}
trust_radius = options.pop("initial_trust_radius", "scipy")
tr_ratio = options.pop("initial_trust_ratio", 1.0)
Expand Down

0 comments on commit 23e2ece

Please sign in to comment.