From 28d0208992cd11c0f57bab6684ab3e7fd80c7c9b Mon Sep 17 00:00:00 2001 From: "James R. Maddison" Date: Thu, 13 Nov 2025 12:45:10 +0000 Subject: [PATCH 1/2] Only set the gradient norm if we have set up the Riesz map elsewhere --- pyadjoint/optimization/tao_solver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyadjoint/optimization/tao_solver.py b/pyadjoint/optimization/tao_solver.py index 1d0f07a5..06d58f8a 100644 --- a/pyadjoint/optimization/tao_solver.py +++ b/pyadjoint/optimization/tao_solver.py @@ -699,9 +699,6 @@ def objective_gradient(tao, x, g): hessian_mat.getPythonContext().update, H=hessian_mat, P=Pmat or hessian_mat) - Minv_mat = RieszMapMat(rf.controls, comm=comm) - tao.setGradientNorm(Minv_mat) - if problem.bounds is not None: lbs = [] ubs = [] @@ -727,6 +724,9 @@ def objective_gradient(tao, x, g): if tao.getType() in {PETSc.TAO.Type.LMVM, PETSc.TAO.Type.BLMVM}: n, N = vec_interface.n, vec_interface.N + Minv_mat = RieszMapMat(rf.controls, comm=comm) + tao.setGradientNorm(Minv_mat) + class InitialHessian: """:class:`petsc4py.PETSc.Mat` context. """ From 13cb63f578c5e464f8574864a37324053d00562e Mon Sep 17 00:00:00 2001 From: "James R. Maddison" Date: Mon, 17 Nov 2025 13:47:07 +0000 Subject: [PATCH 2/2] Riesz map documentation --- pyadjoint/optimization/tao_solver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyadjoint/optimization/tao_solver.py b/pyadjoint/optimization/tao_solver.py index 06d58f8a..ec1b6c0f 100644 --- a/pyadjoint/optimization/tao_solver.py +++ b/pyadjoint/optimization/tao_solver.py @@ -636,6 +636,11 @@ class TAOConvergenceError(Exception): class TAOSolver(OptimizationSolver): """Use TAO to solve an optimization problem. + Only `LMVM` and `BLMVM` types use the Riesz map to configure the optimizer + -- specifically to define the gradient norm using `TaoSetGradientNorm` and + to define the initial Hessian inverse approximation using `TaoLMVMGetH0`. + Other types use PETSc defaults. + Args: problem (MinimizationProblem): Defines the optimization problem to be solved. parameters (Mapping): TAO options.