From 116730d01f3549b129c9117b1437355c22c70d83 Mon Sep 17 00:00:00 2001 From: Michael Friedlander Date: Sun, 6 Oct 2024 09:32:15 -0700 Subject: [PATCH] Ensure that the preconditioner is pos def. This doesn't seem to be a great preconditioner, but it does test the precon option. --- test/runtests.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 3eb0c48e..52d49958 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,11 +82,12 @@ end @testset "Preconditioner in Trunk" begin x0 = [-1.2; 1.0] nlp = ADNLPModel(x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, x0) - DiagPrecon(x) = Diagonal(inv( [200 + 800 * x[1]^2 - 400 * x[2] 0.0; - 0.0 200] )) - + function DiagPrecon(x) + H = Matrix(hess(nlp, x)) + λmin = minimum(eigvals(H)) + Diagonal(H + λmin * I) + end M = DiagPrecon(x0) - # implement `ldiv!` for `Diagonal` to avoid copying function LinearAlgebra.ldiv!(y, M::Diagonal, x) y .= M \ x end @@ -95,5 +96,4 @@ end end stats = trunk(nlp, callback=callback, M=M) @test stats.status == :first_order - end \ No newline at end of file