@@ -24,169 +24,13 @@ using Optimization
2424using OptimizationNLPModels
2525using CUTEst
2626using OptimizationOptimJL
27- using OptimizationOptimisers
28- using OptimizationOptimJL: LBFGS, ConjugateGradient, NelderMead, SimulatedAnnealing, ParticleSwarm
2927using Ipopt
3028using OptimizationMOI
3129using 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
426270else
427271 println(" No results to analyze")
428272end
429- ```
273+ ```
274+ ```julia, echo = false
275+ using SciMLBenchmarks
276+ SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
277+ ```
0 commit comments