Skip to content

Commit

Permalink
Fix issuccess (issue #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmt committed Feb 5, 2024
1 parent bda4ba7 commit 9bb1b29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/PRIMA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Base.:(==)(a::Info, b::Info) =

LinearAlgebra.issuccess(info::Info) = issuccess(info.status)
LinearAlgebra.issuccess(status::Status) =
status == SMALL_TR_RADIUS || status == FTARGET_ACHIEVED

"""
PRIMA.reason(info::PRIMA.Info) -> str
Expand Down
17 changes: 15 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ end
maxfun = 200n, npt = 2n + 1, iprint = PRIMA.MSG_EXIT)
x, info = @inferred PRIMA.newuoa(f, x0; kwds...)
print_1(x, info)
@test issuccess(info)
@test x [3,2] atol=2e-2 rtol=0
@test f(x) info.fx
@test x0 == x0_sav
Expand All @@ -119,6 +120,7 @@ end
maxfun = 200n, iprint = PRIMA.MSG_EXIT)
x, info = @inferred PRIMA.uobyqa(f, x0; kwds...)
print_1(x, info)
@test issuccess(info)
@test x [3,2] atol=2e-2 rtol=0
@test f(x) info.fx
@test x0 == x0_sav
Expand All @@ -136,6 +138,7 @@ end
maxfun = 200n, npt = 2n + 1, iprint = PRIMA.MSG_EXIT)
x, info = @inferred PRIMA.bobyqa(f, x0; kwds...)
print_1(x, info)
@test issuccess(info)
@test x [3,2] atol=2e-2 rtol=0
@test f(x) info.fx
@test x0 == x0_sav
Expand All @@ -160,6 +163,7 @@ end
x, info = @inferred PRIMA.cobyla(f, x0; kwds...,
nonlinear_ineq = c_ineq)
print_3(x, info)
@test issuccess(info)
@test x [3,2] atol=2e-2 rtol=0
@test f(x) info.fx
@test x0 == x0_sav
Expand Down Expand Up @@ -190,6 +194,7 @@ end
maxfun = 200*n, npt = 2n + 1, iprint = PRIMA.MSG_EXIT)
x, info = @inferred PRIMA.lincoa(f, x0; kwds...)
print_2(x, info)
@test issuccess(info)
@test x [3,2] atol=2e-2 rtol=0
@test f(x) info.fx
@test x0 == x0_sav
Expand Down Expand Up @@ -281,6 +286,7 @@ end
continue
end
print_1(x, info)
@test issuccess(info)
@test x [1,1] rtol=0 atol=(optim == :cobyla ? 3e-2 : 2e-2)
@test f(x) info.fx

Expand All @@ -303,6 +309,7 @@ end
continue
end
print_1(x, info)
@test issuccess(info)
@test x [1.095247,1.2] rtol=0 atol=2e-2
@test f(x) info.fx
end
Expand All @@ -322,6 +329,7 @@ end
continue
end
print_1(x, info)
@test issuccess(info)
@test x [1.0,1.0] rtol=0 atol=(optim == :cobyla ? 3e-2 : 2e-2)
@test f(x) info.fx

Expand All @@ -339,6 +347,7 @@ end
continue
end
print_1(x, info)
@test issuccess(info)
@test x [1.0,1.0] rtol=0 atol=(optim == :cobyla ? 3e-2 : 2e-2)
@test f(x) info.fx

Expand All @@ -357,6 +366,7 @@ end
continue
end
print_1(x, info)
@test issuccess(info)
@test x [1.441832,2.077557] rtol=0 atol=(optim == :cobyla ? 3e-2 : 2e-2)
@test f2(x) info.fx
end
Expand All @@ -371,15 +381,18 @@ end
:cobyla, :lincoa, :prima)
optim = optimizer(algo)
x1, res = @inferred optim(cost_func, x0; opts...)
@test issuccess(res)
@test maximum(abs.(x1)) 1e-8
end
end
end

if Sys.WORD_SIZE > 32
@testset "Unconstrained CUTEst problem $name" for name in ("TOINTQOR", "OSBORNEB", "LANCZOS1LS",)
x1, res = @inferred PRIMA.prima_CUTEst(name; maxfun=5000)
x2, res = @inferred PRIMA.newuoa_CUTEst(name; maxfun=5000)
x1, res1 = @inferred PRIMA.prima_CUTEst(name; maxfun=5000)
@test issuccess(res1)
x2, res2 = @inferred PRIMA.newuoa_CUTEst(name; maxfun=5000)
@test issuccess(res2)
@test x1 x2
end
end
Expand Down

0 comments on commit 9bb1b29

Please sign in to comment.