Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/gvec/core/run/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ def run(
self.success = (
self.success and self.state.rms_iota <= self.state.picard_current.iota_tol
)
# A stage cut short by totalIter, such as a free-boundary update that never started, did not
# finish, even when the interior solve before the cut is below minimize_tol.
if self._stop_reason == "Maximum number of iterations reached (totalIter).":
self.success = False
if self.success:
self.message = "Tolerance reached."
else:
Expand Down
23 changes: 23 additions & 0 deletions test-CI/unit-pygvec/test_free_boundary_axisym.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ def test_free_boundary_stop_above_interior_tolerance(tmp_path, criterion, caplog
assert str(recorded[-1].message) == f"GVEC run: {run.message}"


def test_free_boundary_newton_out_of_totaliter_is_no_success(tmp_path):
"""A budget that ends right after the converged start leaves the boundary unchanged: the run must not report
success, although the interior force is below minimize_tol."""
pytest.importorskip("fbtools")

def params(total_iter, updates): # gvec.run adds the coil set to the parameters it is given
p = _params()
p.update(minimize_tol=1e-5, totalIter=total_iter)
p["free_boundary"] = dict(updates=updates, tolerance=1e-12, method="newton")
return p

p = params(2000, 1) # start solve only
start = gvec.run(p, runpath=tmp_path / "start", coil_set=_axis_wire(1e6))
assert start.max_force <= p["minimize_tol"]

p = params(start.GVEC_iter_used + 1, 4)
with pytest.warns(UserWarning, match="GVEC run:"):
run = gvec.run(p, runpath=tmp_path / "fb", coil_set=_axis_wire(1e6))
assert run.max_force <= p["minimize_tol"]
assert not run.success
assert "totalIter" in run.message


def test_free_boundary_resolution_proposal_after_newton_stalls_at_update_0(tmp_path):
"""Newton that makes no step leaves only update 0 in the diagnostics; the resolution proposal at the end of
the stage must use that column, not the (still NaN) last one."""
Expand Down