Skip to content

Commit 5be1d5e

Browse files
authored
Merge pull request #688 from bobmyhill/try_lag
Try/except for Lagrangian walk
2 parents 58d34be + 5a85a47 commit 5be1d5e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

burnman/optimize/nonlinear_solvers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,16 @@ def _lagrangian_walk_along_constraints(
444444
x_j = sol.x + lmda * dx
445445

446446
# Check feasibility
447-
x_j_min = sol.x + lmda_bounds_new[0] * dx
448-
F_j_min = self.F(x_j_min)
449-
dxbar_j_min = lu_solve(luJ, -F_j_min)
450-
dxbar_j_min_norm = np.linalg.norm(dxbar_j_min, ord=2)
451-
452-
if dxbar_j_min_norm > dx_norm or np.linalg.norm(dx, ord=2) < self.eps:
447+
try:
448+
x_j_min = sol.x + lmda_bounds_new[0] * dx
449+
F_j_min = self.F(x_j_min)
450+
dxbar_j_min = lu_solve(luJ, -F_j_min)
451+
dxbar_j_min_norm = np.linalg.norm(dxbar_j_min, ord=2)
452+
453+
if dxbar_j_min_norm > dx_norm or np.linalg.norm(dx, ord=2) < self.eps:
454+
persistent_bound_violation = True
455+
except Exception:
456+
# For example, if self.F(x_j_min) fails
453457
persistent_bound_violation = True
454458

455459
# Check newly violated inactive constraints

examples/example_equilibrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240

241241
# Run the equilibration
242242
pressure = 1.0e5
243-
temperatures = np.linspace(300.0, 601.0, 41)
243+
temperatures = np.linspace(300.0, 601.4, 301)
244244
equality_constraints = [("P", pressure), ("T", temperatures)]
245245

246246
sols, prm = equilibrate(composition, assemblage, equality_constraints)

0 commit comments

Comments
 (0)