From d9526191bc91449d8a1a152b04ad2dbde0bc143e Mon Sep 17 00:00:00 2001 From: jacobdparker Date: Mon, 27 Jul 2026 18:06:31 -0600 Subject: [PATCH] Fix the convergence check being skipped when verbose=True The convergence test in MartInverter.__call__ was an elif chained behind the verbose print statement, so any run with verbose output could never stop at the convergence threshold and always ran to num_iteration. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01HuYXL1BkWsWGAxYnpD8Kqz --- ctis/inverters/_iterative/_mart/_mart.py | 2 +- ctis/inverters/_iterative/_mart/_mart_test.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ctis/inverters/_iterative/_mart/_mart.py b/ctis/inverters/_iterative/_mart/_mart.py index e45c41b..8275554 100644 --- a/ctis/inverters/_iterative/_mart/_mart.py +++ b/ctis/inverters/_iterative/_mart/_mart.py @@ -131,7 +131,7 @@ def __call__( if verbose: # pragma: nocover print(f"merit: {merit}") - elif (merit_old - merit) < self.threshold_convergence: + if (merit_old - merit) < self.threshold_convergence: message = f"Achieved merit less than {self.threshold_convergence}." success = True num_iteration = i + 1 diff --git a/ctis/inverters/_iterative/_mart/_mart_test.py b/ctis/inverters/_iterative/_mart/_mart_test.py index b354523..55570db 100644 --- a/ctis/inverters/_iterative/_mart/_mart_test.py +++ b/ctis/inverters/_iterative/_mart/_mart_test.py @@ -114,3 +114,19 @@ def test__call__( assert isinstance(fig, plt.Figure) for ax in axs: assert isinstance(ax, plt.Axes) + + +def test__call__verbose_convergence(): + """ + Verbose output must not disable the convergence check. + """ + a = ctis.inverters.MartInverter( + instrument=instrument, + num_iteration=50, + threshold_convergence=1e-2, + ) + + result = a(images, verbose=True) + + assert result.success + assert result.num_iteration < a.num_iteration