From 1c3cb27242a4b30f00877a37fcdbac150cd44b4a Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Sat, 21 Nov 2026 14:50:49 +0100 Subject: [PATCH 1/2] Report a run cut short by totalIter as unsuccessful A free-boundary Newton run whose budget ran out before the first update reported 'Tolerance reached.' because only the interior force was checked. --- python/gvec/core/run/abstract.py | 4 ++++ .../unit-pygvec/test_free_boundary_axisym.py | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) 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..629ec9e7 100644 --- a/test-CI/unit-pygvec/test_free_boundary_axisym.py +++ b/test-CI/unit-pygvec/test_free_boundary_axisym.py @@ -149,6 +149,26 @@ 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") + p = _params() + p["minimize_tol"] = 1e-5 + p["totalIter"] = 2000 + p["free_boundary"] = dict(updates=1, tolerance=1e-12, method="newton") # start solve only + start = gvec.run(p, runpath=tmp_path / "start", coil_set=_axis_wire(1e6)) + assert start.max_force <= p["minimize_tol"] + + p["totalIter"] = start.GVEC_iter_used + 1 + p["free_boundary"]["updates"] = 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.""" From 4f801527e1d30f475d6a46220b91b56cb1e2ffda Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Sat, 21 Nov 2026 14:53:54 +0100 Subject: [PATCH 2/2] Give each run of the totalIter test its own parameters --- test-CI/unit-pygvec/test_free_boundary_axisym.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test-CI/unit-pygvec/test_free_boundary_axisym.py b/test-CI/unit-pygvec/test_free_boundary_axisym.py index 629ec9e7..923e34be 100644 --- a/test-CI/unit-pygvec/test_free_boundary_axisym.py +++ b/test-CI/unit-pygvec/test_free_boundary_axisym.py @@ -153,15 +153,18 @@ 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") - p = _params() - p["minimize_tol"] = 1e-5 - p["totalIter"] = 2000 - p["free_boundary"] = dict(updates=1, tolerance=1e-12, method="newton") # start solve only + + 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["totalIter"] = start.GVEC_iter_used + 1 - p["free_boundary"]["updates"] = 4 + 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"]