Skip to content

Commit b106f8a

Browse files
committed
add test for OptimziationMadNLP when σ == 0 in lag_h
1 parent 8e8cdb6 commit b106f8a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/OptimizationMadNLP/test/runtests.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using MadNLP
44
using Test
55
import Zygote, ForwardDiff, ReverseDiff
66
using SparseArrays
7-
using DifferentiationInterface
7+
using DifferentiationInterface: SecondOrder
88
using Random
99

1010
@testset "rosenbrock" begin
@@ -553,6 +553,35 @@ end
553553
# LBFGS methods typically need more iterations but less cost per iteration
554554
@test results[1][2].iterations > results[1][2].iterations broken=true
555555
end
556+
557+
@testset "Exact Hessian and sparse KKT that hits σ == 0 in lag_h" begin
558+
np = 12
559+
# x0 = init_electrons_on_sphere(np)
560+
x0 = [-0.10518691576929745, 0.051771801773795686, -0.9003045175547166, 0.23213937667116594, -0.02874270928423086, -0.652270178114126, -0.5918025628300999, 0.2511988210810674, -0.016535391659614228, 0.5949770074227214, -0.4492781383448046, -0.29581324890382626, -0.8989309486672202, 0.10678505987872657, -0.4351575519144031, -0.9589360279618278, 0.02680807390998832, 0.40670966862867725, 0.08594698464206306, -0.9646178134393677, -0.004187961953999249, -0.09107912492873807, -0.6973104772728601, 0.40182616259664583, 0.4252750430946946, -0.9929333469713824, 0.009469988512801456, 0.1629509253594941, -0.9992272933803594, -0.6396333795127627, -0.8014878928958706, 0.08007263129768477, -0.9998545103150432, 0.7985655600140281, -0.5584865734204564, -0.8666200187082093]
561+
562+
approx = MadNLP.ExactHessian
563+
ad = SecondOrder(AutoForwardDiff(), AutoForwardDiff())
564+
565+
optfunc = OptimizationFunction(
566+
coulomb_potential, ad,
567+
cons = unit_sphere_constraints
568+
)
569+
570+
prob = OptimizationProblem(optfunc, x0;
571+
lcons = zeros(np),
572+
ucons = zeros(np)
573+
)
574+
575+
opt = MadNLPOptimizer(
576+
hessian_approximation = approx,
577+
kkt_system = MadNLP.SparseKKTSystem
578+
)
579+
580+
sol = solve(prob, opt; abstol = 1e-6, maxiters = 300, verbose = false)
581+
582+
@test SciMLBase.successful_retcode(sol)
583+
@test sol.objective 49.165253058 rtol=1e-2
584+
end
556585
end
557586

558587
@testset "LBFGS with damped update" begin

0 commit comments

Comments
 (0)