Skip to content

Commit 93c308b

Browse files
arnavk23ChrisRackauckas
authored andcommitted
building
1 parent ba7d2bd commit 93c308b

File tree

5 files changed

+38
-168
lines changed

5 files changed

+38
-168
lines changed

benchmarks/OptimizationCUTEst/CUTEst_bounded.jmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ using OptimizationNLPModels
2020
using CUTEst
2121
using OptimizationOptimJL
2222
using OptimizationOptimisers
23-
using OptimizationOptimJL: LBFGS, ConjugateGradient, NelderMead, SimulatedAnnealing, ParticleSwarm
2423
using Ipopt
2524
using OptimizationMOI
2625
using OptimizationMOI: MOI as MOI
@@ -245,4 +244,7 @@ else
245244
end
246245
```
247246

248-
247+
```
248+
using SciMLBenchmarks
249+
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
250+
```

benchmarks/OptimizationCUTEst/CUTEst_quadratic.jmd

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ author: Alonso M. Cisneros
77

88
CUTEst, the Constraind and Unconstrained Testing Environment is, as the name suggests is a
99
collection of around 1500 problems for general nonlinear optimization used to test
10-
11-
```julia; eval = true; @setup
10+
optimization routines. The wrapper
11+
[CUTEst.jl](https://github.com/JuliaSmoothOptimizers/CUTEst.jl) provides convenient access
12+
to the problem collection, which we can leverage to test the optimizers made available by
13+
Optimization.jl.
14+
```julia
1215
using Pkg; Pkg.activate("."); Pkg.instantiate()
1316
using Optimization
1417
using OptimizationNLPModels
1518
using CUTEst
1619
using OptimizationOptimJL
1720
using OptimizationOptimisers
18-
using OptimizationOptimJL: LBFGS, ConjugateGradient, NelderMead, SimulatedAnnealing, ParticleSwarm
1921
using Ipopt
2022
using OptimizationMOI
2123
using OptimizationMOI: MOI as MOI
@@ -48,6 +50,8 @@ function run_benchmarks(problems, optimizers; chunk_size=1)
4850
solver = String[]
4951
retcode = Symbol[]
5052
optz = length(optimizers)
53+
n = length(problems)
54+
@info "Processing $(n) problems with $(optz) optimizers in chunks of $(chunk_size)"
5155
broadcast(c -> sizehint!(c, optz * n), [problem, n_vars, secs, solver, retcode])
5256
for chunk_start in 1:chunk_size:n
5357
chunk_end = min(chunk_start + chunk_size - 1, n)
@@ -128,6 +132,7 @@ constraints. There are 252 such problems in the suite.
128132

129133
# Select a moderate subset of quadratic problems for a realistic mix of successes and failures
130134
quad_problems = CUTEst.select_sif_problems(objtype="quadratic", contype="linear")
135+
@info "Testing $(length(quad_problems)) quadratic problems with linear constraints"
131136
quad_problems = quad_problems[1:min(30, length(quad_problems))]
132137
# Skip HIER13, BLOWEYA, LUKVLE8, PATTERNNE, READING2, NINENEW, READING6, DITTERT, CVXQP2, and MSS1 if present
133138
quad_problems = filter(p -> !(lowercase(p) in ["hier13", "bloweya", "s268", "stcqp1", "cvxqp3", "avgasb", "lukvle8", "sosqp2", "patternne", "reading2", "ninenew", "reading6", "dittert", "liswet9", "cleuven4", "cvxqp2", "mss1", "mpc2", "cmpc10", "cmpc3"]), quad_problems)
@@ -261,3 +266,7 @@ else
261266
end
262267
```
263268

269+
```julia, echo = false
270+
using SciMLBenchmarks
271+
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
272+
```

benchmarks/OptimizationCUTEst/CUTEst_safe_solvers.jmd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This benchmark extends the original CUTEst unconstrained benchmark to demonstrat
99

1010
This serves as a proof-of-concept for the expanded solver testing objective while maintaining reliability.
1111

12-
```julia; eval = true
12+
```julia
1313
using Optimization
1414
using OptimizationNLPModels
1515
using CUTEst
@@ -333,3 +333,8 @@ end
333333
"""
334334
NOTE: Ensure all code chunks are evaluated in order. If running in a notebook or Weave, do not skip any chunks.
335335
"""
336+
337+
```julia, echo = false
338+
using SciMLBenchmarks
339+
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
340+
```

benchmarks/OptimizationCUTEst/CUTEst_unbounded.jmd

Lines changed: 9 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -24,169 +24,13 @@ using Optimization
2424
using OptimizationNLPModels
2525
using CUTEst
2626
using OptimizationOptimJL
27-
using OptimizationOptimisers
28-
using OptimizationOptimJL: LBFGS, ConjugateGradient, NelderMead, SimulatedAnnealing, ParticleSwarm
2927
using Ipopt
3028
using OptimizationMOI
3129
using OptimizationMOI: MOI as MOI
32-
33-
# Harmonized analysis block for equality-constrained unbounded problems
34-
function run_unbounded_benchmarks(problems, optimizers; chunk_size=3)
35-
problem = String[]
36-
n_vars = Int64[]
37-
secs = Float64[]
38-
solver = String[]
39-
retcode = Symbol[]
40-
optz = length(optimizers)
41-
n = length(problems)
42-
@info "Processing $(n) unbounded problems with $(optz) optimizers in chunks of $(chunk_size)"
43-
broadcast(c -> sizehint!(c, optz * n), [problem, n_vars, secs, solver, retcode])
44-
for chunk_start in 1:chunk_size:n
45-
chunk_end = min(chunk_start + chunk_size - 1, n)
46-
chunk_problems = problems[chunk_start:chunk_end]
47-
@info "Processing chunk $(div(chunk_start-1, chunk_size)+1)/$(div(n-1, chunk_size)+1): problems $(chunk_start)-$(chunk_end)"
48-
for (idx, prob_name) in enumerate(chunk_problems)
49-
current_problem = chunk_start + idx - 1
50-
# Removed stray reference to current_problem (only valid inside benchmark functions)
51-
nlp_prob = nothing
52-
try
53-
nlp_prob = CUTEstModel(prob_name)
54-
if nlp_prob.meta.nvar > 10000
55-
@info " Skipping $(prob_name) (too large: $(nlp_prob.meta.nvar) variables)"
56-
finalize(nlp_prob)
57-
continue
58-
end
59-
prob = OptimizationNLPModels.OptimizationProblem(nlp_prob, Optimization.AutoForwardDiff())
60-
for (optimizer_name, optimizer) in optimizers
61-
try
62-
sol = solve(prob, optimizer; maxiters = 1000, maxtime = 30.0)
63-
@info "✓ Solved $(prob_name) with $(optimizer_name) - Status: $(sol.retcode)"
64-
vars, time, alg, code = get_stats(sol, optimizer_name)
65-
push!(problem, prob_name)
66-
push!(n_vars, vars)
67-
push!(secs, time)
68-
push!(solver, alg)
69-
push!(retcode, code)
70-
catch e
71-
push!(problem, prob_name)
72-
push!(n_vars, nlp_prob !== nothing ? nlp_prob.meta.nvar : -1)
73-
push!(secs, NaN)
74-
push!(solver, optimizer_name)
75-
push!(retcode, :FAILED)
76-
println("ERROR: ", e)
77-
println("Stacktrace:")
78-
for (i, frame) in enumerate(stacktrace(e))
79-
println(" ", i, ": ", frame)
80-
end
81-
end
82-
end
83-
catch e
84-
for (optimizer_name, optimizer) in optimizers
85-
push!(problem, prob_name)
86-
push!(n_vars, -1)
87-
push!(secs, NaN)
88-
push!(solver, optimizer_name)
89-
push!(retcode, :LOAD_FAILED)
90-
end
91-
println("LOAD ERROR: ", e)
92-
println("Stacktrace:")
93-
for (i, frame) in enumerate(stacktrace(e))
94-
println(" ", i, ": ", frame)
95-
end
96-
finally
97-
if nlp_prob !== nothing
98-
try
99-
finalize(nlp_prob)
100-
catch e
101-
end
102-
end
103-
end
104-
end
105-
GC.gc()
106-
@info "Completed chunk, memory usage cleaned up"
107-
end
108-
return DataFrame(problem = problem, n_vars = n_vars, secs = secs, solver = solver, retcode = retcode)
109-
end
110-
111-
@info "Problem $(current_problem)/$(n): $(prob_name)"
112-
println("Full results table for equality-constrained problems:")
113-
display(eq_unb_results)
114-
115-
# Calculate and display success rates for equality constrained
116-
successful_codes = [:Success, :MaxIters, :MaxTime, :FirstOrderOptimal]
117-
successful_results = filter(row -> row.retcode in successful_codes, eq_unb_results)
118-
total_attempts = nrow(eq_unb_results)
119-
successful_attempts = nrow(successful_results)
120-
success_rate = total_attempts > 0 ? round(successful_attempts / total_attempts * 100, digits=1) : 0
121-
122-
@info "EQUALITY CONSTRAINED SUCCESS RATE: $(success_rate)% ($(successful_attempts)/$(total_attempts))"
123-
124-
if nrow(eq_unb_results) > 0
125-
try
126-
@df eq_unb_results scatter(:n_vars, :secs,
127-
group = :solver,
128-
xlabel = "n. variables",
129-
ylabel = "secs.",
130-
title = "Time to solution by optimizer and number of vars",
131-
)
132-
println("Plotted equality-constrained results.")
133-
catch e
134-
println("Plotting failed: ", e)
135-
end
136-
else
137-
println("Warning: equality-constrained results DataFrame is empty. No data to plot.")
138-
println("Attempted problems:")
139-
println(eq_unb_problems)
140-
end
141-
nlp_prob = nothing
142-
try
143-
nlp_prob = CUTEstModel(prob_name)
144-
if nlp_prob.meta.nvar > 10000
145-
@info " Skipping $(prob_name) (too large: $(nlp_prob.meta.nvar) variables)"
146-
finalize(nlp_prob)
147-
continue
148-
end
149-
prob = OptimizationNLPModels.OptimizationProblem(nlp_prob, Optimization.AutoForwardDiff())
150-
for (optimizer_name, optimizer) in optimizers
151-
try
152-
sol = solve(prob, optimizer; maxiters = 1000, maxtime = 30.0)
153-
@info "✓ Solved $(prob_name) with $(optimizer_name) - Status: $(sol.retcode)"
154-
vars, time, alg, code = get_stats(sol, optimizer_name)
155-
push!(problem, prob_name)
156-
push!(n_vars, vars)
157-
push!(secs, time)
158-
push!(solver, alg)
159-
push!(retcode, code)
160-
catch e
161-
push!(problem, prob_name)
162-
push!(n_vars, nlp_prob !== nothing ? nlp_prob.meta.nvar : -1)
163-
push!(secs, NaN)
164-
push!(solver, optimizer_name)
165-
push!(retcode, :FAILED)
166-
end
167-
end
168-
catch e
169-
for (optimizer_name, optimizer) in optimizers
170-
push!(problem, prob_name)
171-
push!(n_vars, -1)
172-
push!(secs, NaN)
173-
push!(solver, optimizer_name)
174-
push!(retcode, :LOAD_FAILED)
175-
end
176-
finally
177-
if nlp_prob !== nothing
178-
try
179-
finalize(nlp_prob)
180-
catch e
181-
end
182-
end
183-
end
184-
end
185-
GC.gc()
186-
@info "Completed chunk, memory usage cleaned up"
187-
end
188-
return DataFrame(problem = problem, n_vars = n_vars, secs = secs, solver = solver, retcode = retcode)
189-
end
30+
using DataFrames
31+
using Plots
32+
using StatsPlots
33+
using StatsBase: countmap
19034
```
19135

19236
# Benchmarks
@@ -426,4 +270,8 @@ if total_attempts_ineq > 0
426270
else
427271
println(" No results to analyze")
428272
end
429-
```
273+
```
274+
```julia, echo = false
275+
using SciMLBenchmarks
276+
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
277+
```

benchmarks/OptimizationCUTEst/CUTEst_unconstrained.jmd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,10 @@ end
170170
ylabel = "secs.",
171171
title = "Time to solution by optimizer and number of vars",
172172
)
173-
```
173+
```
174+
175+
176+
```julia, echo = false
177+
using SciMLBenchmarks
178+
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
179+
```

0 commit comments

Comments
 (0)