diff --git a/python/gvec/core/run/abstract.py b/python/gvec/core/run/abstract.py index ab652108..4c903cf0 100644 --- a/python/gvec/core/run/abstract.py +++ b/python/gvec/core/run/abstract.py @@ -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: diff --git a/test-CI/unit-pygvec/test_free_boundary_axisym.py b/test-CI/unit-pygvec/test_free_boundary_axisym.py index 1c6bbd25..923e34be 100644 --- a/test-CI/unit-pygvec/test_free_boundary_axisym.py +++ b/test-CI/unit-pygvec/test_free_boundary_axisym.py @@ -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."""