Skip to content

Commit

Permalink
time_limit tests for univariate solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhauschel committed Apr 23, 2024
1 parent 0ad5f43 commit 3b8e4c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/univariate/solvers/brent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@
@test Optim.converged(result)
@test Optim.minimum(result) == -1.0

## time limit
function slow_obj(x)
sleep(0.05)
return sin(x)
end
result = optimize(x -> slow_obj(x), 0, 2π, Brent(); time_limit=0.01)
@test result.f_calls == 1

result = Optim.optimize(x->sin(x), 0, 2π, Optim.Brent(); abs_tol=1e-4, store_trace=false, show_trace=true, iterations=2)
end
8 changes: 8 additions & 0 deletions test/univariate/solvers/golden_section.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@
@test Optim.minimum(result) == 2.0
@test_throws ErrorException optimize(identity, 2.0, 1.0, GoldenSection())

## time limit
function slow_obj(x)
sleep(0.05)
return sin(x)
end
result = optimize(x -> slow_obj(x), 0, 2π, GoldenSection(); time_limit=0.01)
@test result.f_calls == 1

result = Optim.optimize(x->sin(x), 0, 2π, Optim.GoldenSection(); abs_tol=1e-4, store_trace=false, show_trace=true, iterations=2)
end

0 comments on commit 3b8e4c6

Please sign in to comment.