-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Test code:
using PRIMA
using Test # To use @testset
println("PRIMA Version: ", PRIMA.VERSION) # Print the version
println("Julia Version: ", VERSION)
Simple objective
function my_obj(x::Vector{Float64})::Float64
return (x[1] - 2.0)^2 + (x[2] - 3.0)^2
end
x0 = Float64[0.0, 0.0]
xl = Float64[-5.0, -5.0]
xu = Float64[5.0, 5.0]
rhobeg = 0.5
rhoend = 1e-5
maxeval = 500
println("\nTesting simple call (no keywords):")
try
x_opt1, info1 = prima(my_obj, x0)
println(" Simple call OK. Result: x=$(x_opt1), fx=$(info1.fx), status=$(info1.status)")
@test issuccess(info1)
catch e
println(" Simple call FAILED. Error: $e")
# If this errors, PRIMA itself is broken
end
println("\nTesting call with keywords:")
try
# Use the general prima function first
x_opt2, info2 = prima(my_obj, x0; xl=xl, xu=xu, rhobeg=rhobeg, rhoend=rhoend, maxeval=maxeval)
println(" Keyword call (prima) OK. Result: x=$(x_opt2), fx=$(info2.fx), status=$(info2.status)")
@test issuccess(info2)
catch e
println(" Keyword call (prima) FAILED. Error: $e")
# This is where you expect the MethodError based on your results
@test e isa MethodError # Check if it's the expected error
end
println("\nTesting call with cobyla and keywords:")
try
# Test cobyla explicitly
x_opt3, info3 = PRIMA.cobyla(my_obj, x0; xl=xl, xu=xu, rhobeg=rhobeg, rhoend=rhoend, maxeval=maxeval)
println(" Keyword call (cobyla) OK. Result: x=$(x_opt3), fx=$(info3.fx), status=$(info3.status)")
@test issuccess(info3)
catch e
println(" Keyword call (cobyla) FAILED. Error: $e")
# This is where you expect the MethodError based on your results
@test e isa MethodError # Check if it's the expected error
end
Output:
julia> include("MRE.jl")
PRIMA Version: 1.11.4
Julia Version: 1.11.4
Testing simple call (no keywords):
Simple call OK. Result: x=[2.0, 3.0], fx=0.0, status=SMALL_TR_RADIUS
Testing call with keywords:
Keyword call (prima) FAILED. Error: MethodError(Core.kwcall, ((xl = [-5.0, -5.0], xu = [5.0, 5.0], rhobeg = 0.5, rhoend = 1.0e-5, maxeval = 500), PRIMA.prima!, Main.my_obj, [0.0, 0.0]), 0xffffffffffffffff)
Testing call with cobyla and keywords:
Keyword call (cobyla) FAILED. Error: MethodError(Core.kwcall, ((xl = [-5.0, -5.0], xu = [5.0, 5.0], rhobeg = 0.5, rhoend = 1.0e-5, maxeval = 500), PRIMA.cobyla!, Main.my_obj, [0.0, 0.0]), 0xffffffffffffffff)
Test Passed
My operating system is Ubuntu.
(@v1.11) pkg> st PRIMA
Status ~/.julia/environments/v1.11/Project.toml
[0a7d04aa] PRIMA v0.2.2