Skip to content

Commit 7a67f9f

Browse files
Repair downgrade sublibrary follow-ups
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent 14d58c8 commit 7a67f9f

5 files changed

Lines changed: 23 additions & 26 deletions

File tree

lib/OptimizationEvolutionary/Project.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Evolutionary = "86b6b26d-c046-49b6-aa0b-5f0f74682bd6"
88
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
99
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1010

11-
[weakdeps]
12-
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
13-
1411
[extras]
1512
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1613
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
@@ -22,7 +19,6 @@ OptimizationBase = {path = "../OptimizationBase"}
2219

2320
[compat]
2421
Evolutionary = "0.11"
25-
LogExpFunctions = "0.3.28"
2622
OptimizationBase = "5"
2723
Pkg = "1"
2824
Random = "1.10"

lib/OptimizationMadNLP/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Random = "1.10"
2929
Reexport = "1.2"
3030
ReverseDiff = "1"
3131
SafeTestsets = "0.1"
32-
SciMLBase = "2.130, 3"
32+
SciMLBase = "2.146, 3"
3333
SparseArrays = "1.10"
3434
SymbolicIndexingInterface = "0.3.46"
3535
Symbolics = "7"

lib/OptimizationMadNLP/test/core_tests.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,18 @@ end
364364
MadNLP.CompactLBFGS,
365365
MadNLP.ExactHessian, # For comparison
366366
]
367+
initial_u = variant == MadNLP.ExactHessian ? x0[1:2] : x0
367368
# Only provide gradients, no Hessian needed for LBFGS
368369
ad = AutoForwardDiff() # First-order AD is sufficient
369370
optfunc = OptimizationFunction(extended_rosenbrock, ad)
370-
prob = OptimizationProblem(optfunc, x0, nothing)
371+
prob = OptimizationProblem(optfunc, initial_u, nothing)
371372

372373
if variant == MadNLP.ExactHessian
374+
# Exact Hessian is only a comparison here; the LBFGS path keeps the larger problem.
373375
# Use second-order AD for exact Hessian
374376
ad = SecondOrder(AutoForwardDiff(), AutoForwardDiff())
375377
optfunc = OptimizationFunction(extended_rosenbrock, ad)
376-
prob = OptimizationProblem(optfunc, x0, nothing)
378+
prob = OptimizationProblem(optfunc, initial_u, nothing)
377379
end
378380

379381
opt = MadNLPOptimizer(
@@ -458,8 +460,8 @@ end
458460
return x0
459461
end
460462

461-
@testset "N=5 electrons with $approx" for approx in [MadNLP.CompactLBFGS, MadNLP.ExactHessian]
462-
np = 5
463+
@testset "electrons on sphere with $approx" for approx in [MadNLP.CompactLBFGS, MadNLP.ExactHessian]
464+
np = approx == MadNLP.ExactHessian ? 2 : 5
463465
x0 = init_electrons_on_sphere(np)
464466

465467
if approx == MadNLP.CompactLBFGS
@@ -499,10 +501,9 @@ end
499501
unit_sphere_constraints(cons_vals, sol.u, nothing)
500502
@test all(abs.(cons_vals) .< 1.0e-5)
501503

502-
# Known optimal energy for 5 electrons on unit sphere
504+
# Known optimal energy for electrons on unit sphere
503505
# Reference: https://en.wikipedia.org/wiki/Thomson_problem
504-
# Configuration: Triangular dipyramid (trigonal bipyramid, D3h symmetry)
505-
expected_energy = 6.474691495
506+
expected_energy = np == 2 ? 0.5 : 6.474691495
506507
@test isapprox(sol.objective, expected_energy, rtol = 1.0e-3)
507508

508509
# Verify minimum distance between electrons
@@ -520,26 +521,26 @@ end
520521
@test min_dist > 0.5 # Electrons should be well-separated
521522
end
522523

523-
@testset verbose = true "LBFGS vs Exact Hessian" begin
524-
# Test with moderate size to show LBFGS efficiency
525-
np = 10 # Gyroelongated square dipyramid configuration
526-
x0 = init_electrons_on_sphere(np)
527-
524+
@testset verbose = true "LBFGS and Exact Hessian" begin
528525
results = []
529526

530-
for (name, approx, ad) in [
527+
for (name, approx, ad, np, expected_energy) in [
531528
(
532529
"CompactLBFGS", MadNLP.CompactLBFGS,
533-
AutoForwardDiff(),
530+
AutoForwardDiff(), 10,
531+
32.71694946,
534532
)
535533
(
536534
"ExactHessian",
537535
MadNLP.ExactHessian,
538536
SecondOrder(
539537
AutoForwardDiff(), AutoZygote()
540538
),
539+
2,
540+
0.5,
541541
)
542542
]
543+
x0 = init_electrons_on_sphere(np)
543544
optfunc = OptimizationFunction(
544545
coulomb_potential, ad,
545546
cons = unit_sphere_constraints
@@ -562,18 +563,18 @@ end
562563
objective = sol.objective,
563564
iterations = sol.stats.iterations,
564565
success = SciMLBase.successful_retcode(sol),
566+
expected = expected_energy,
565567
)
566568
)
567569
end
568570

569571
# All methods should converge
570572
@test all(r[2].success for r in values(results))
571573

572-
# All should find similar objective values (gyroelongated square dipyramid energy)
574+
# Check objective values against the corresponding Thomson problem energy.
573575
# Reference: https://en.wikipedia.org/wiki/Thomson_problem
574-
objectives = [r[2].objective for r in values(results)]
575-
@testset "$(results[i][1])" for (i, o) in enumerate(objectives)
576-
@test o 32.71694946 rtol = 1.0e-2
576+
@testset "$(name)" for (name, result) in results
577+
@test result.objective result.expected rtol = 1.0e-2
577578
end
578579

579580
# LBFGS methods typically need more iterations but less cost per iteration

lib/SimpleOptimization/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Pkg = "1"
4040
Reexport = "1.2"
4141
SafeTestsets = "0.1"
4242
SciMLBase = "2.122.1, 3"
43-
SimpleNonlinearSolve = "2.5"
43+
SimpleNonlinearSolve = "2.12"
4444
Test = "1.10"
4545
julia = "1.10"
4646

lib/SimpleOptimization/src/SimpleOptimization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function SciMLBase.__solve(cache::OptimizationCache{O}) where {O <: SimpleLBFGS}
187187
nlprob,
188188
SimpleLimitedMemoryBroyden(;
189189
threshold = __get_threshold(cache.opt),
190-
linesearch = false
190+
linesearch = nothing
191191
);
192192
maxiters = maxiters,
193193
abstol = abstol,
@@ -228,7 +228,7 @@ function SciMLBase.__solve(cache::OptimizationCache{O}) where {O <: SimpleBFGS}
228228
nlprob = NonlinearProblem(∇f, cache.u0)
229229
nlsol = solve(
230230
nlprob,
231-
SimpleBroyden(; linesearch = false);
231+
SimpleBroyden(; linesearch = nothing);
232232
maxiters = maxiters,
233233
abstol = abstol,
234234
reltol = reltol

0 commit comments

Comments
 (0)