Skip to content

Commit c45108a

Browse files
committed
quit solve on invalid step when J=singular
1 parent 57dd66a commit c45108a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

burnman/optimize/nonlinear_solvers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,16 @@ def solve(self) -> Solution:
708708
and not converged
709709
):
710710
sol.J = self.J(sol.x)
711+
condition_number = np.linalg.cond(sol.J)
711712
luJ = lu_factor(sol.J)
712713
dx = lu_solve(luJ, -sol.F)
713714
dx_norm = np.linalg.norm(dx, ord=2)
714715

716+
is_singular = condition_number > self.max_condition_number
717+
if is_singular and any(np.isnan(dx)):
718+
lmda_bounds = [0.0, 0.0]
719+
break
720+
715721
lmda_bounds = self.lambda_bounds(dx, sol.x)
716722
h = (
717723
lmda
@@ -742,7 +748,6 @@ def solve(self) -> Solution:
742748
F_j = self.F(x_j)
743749

744750
# Regularise ill-conditioned Jacobian
745-
condition_number = np.linalg.cond(sol.J)
746751
if condition_number < self.cond_lu_thresh:
747752
dxbar_j = lu_solve(luJ, -F_j)
748753
else:

burnman/tools/equilibration.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,12 @@ def lambda_bounds(dx, x, endmembers_per_phase):
498498
]
499499
)
500500
if np.isnan(max_lmda):
501-
raise ValueError("NaN in lambda bounds calculation.\n"
502-
f"dx: {dx}\n"
503-
f"x: {x}\n"
504-
f"endmembers_per_phase: {endmembers_per_phase}.")
501+
raise ValueError(
502+
"NaN in lambda bounds calculation.\n"
503+
f"dx: {dx}\n"
504+
f"x: {x}\n"
505+
f"endmembers_per_phase: {endmembers_per_phase}."
506+
)
505507
return (1.0e-8, max_lmda)
506508

507509

0 commit comments

Comments
 (0)