Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for MOI.TimeLimitSec #101

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@ end

MOI.supports(::Optimizer, ::MOI.TimeLimitSec) = true

function MOI.set(optimizer::Optimizer, ::MOI.TimeLimitSec, value)
function MOI.set(optimizer::Optimizer, ::MOI.TimeLimitSec, value::Real)
optimizer.options.time_limit = value
return
end

function MOI.set(optimizer::Optimizer, ::MOI.TimeLimitSec, ::Nothing)
optimizer.options.time_limit = 3600_00.0
return
end

function MOI.get(optimizer::Optimizer, ::MOI.TimeLimitSec)
return optimizer.options.time_limit
value = optimizer.options.time_limit
return value == 3600_00.0 ? nothing : value
end

MOI.supports(::Optimizer, ::MOI.NumberOfThreads) = false
Expand Down Expand Up @@ -291,7 +298,7 @@ function _optimize!(dest::Optimizer, src::OptimizerCache)
#
end # timeit

#=
#=
Solve modified problem
=#

Expand Down Expand Up @@ -327,7 +334,7 @@ function _optimize!(dest::Optimizer, src::OptimizerCache)
close(f)
end

#=
#=
Fix solution
=#

Expand Down
36 changes: 17 additions & 19 deletions test/moitest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const optimizer_bridged = MOI.instantiate(
()->ProxSDP.Optimizer(
tol_gap = 1e-6, tol_feasibility= 1e-6,
# max_iter = 100_000,
time_limit = 3., #seconds FAST
time_limit = 30.0, #seconds FAST
warn_on_limit = true,
# log_verbose = true, log_freq = 100000
),
Expand Down Expand Up @@ -49,7 +49,7 @@ function test_runtests()
opt = ProxSDP.Optimizer(
tol_gap = 1e-6, tol_feasibility= 1e-6,
# max_iter = 100_000,
time_limit = 1.0, #seconds FAST
time_limit = 5.0, #seconds FAST
warn_on_limit = true,
# log_verbose = true, log_freq = 100000
)
Expand All @@ -66,24 +66,9 @@ function test_runtests()
"test_model_LowerBoundAlreadySet",
# poorly scaled problem (solved bellow with higher accuracy)
"test_linear_add_constraints",
# time limit hit
"test_linear_INFEASIBLE",
"test_solve_DualStatus_INFEASIBILITY_CERTIFICATE_VariableIndex_LessThan_max",
],
)

MOI.set(model, MOI.RawOptimizerAttribute("time_limit"), 5.0)
MOI.empty!(model)
MOI.Test.test_solve_DualStatus_INFEASIBILITY_CERTIFICATE_VariableIndex_LessThan_max(
model,
config,
)
MOI.empty!(model)
MOI.Test.test_linear_INFEASIBLE(
model,
config,
)

MOI.set(model, MOI.RawOptimizerAttribute("tol_primal"), 1e-7)
MOI.set(model, MOI.RawOptimizerAttribute("tol_dual"), 1e-7)
MOI.set(model, MOI.RawOptimizerAttribute("tol_gap"), 1e-7)
Expand Down Expand Up @@ -113,7 +98,7 @@ end
include("base_mimo.jl")
include("moi_mimo.jl")
for i in 2:5
@testset "MIMO n = $(i)" begin
@testset "MIMO n = $(i)" begin
moi_mimo(optimizer_bridged, 123, i, test = true)
end
end
Expand All @@ -125,7 +110,7 @@ end
# include("base_randsdp.jl")
# include("moi_randsdp.jl")
# for n in 10:11, m in 10:11
# @testset "RANDSDP n=$n, m=$m" begin
# @testset "RANDSDP n=$n, m=$m" begin
# moi_randsdp(optimizer, 123, n, m, test = true, atol = 1e-1)
# end
# end
Expand Down Expand Up @@ -171,3 +156,16 @@ end
end

include("test_terminationstatus.jl")

@testset "test_attribute_TimeLimitSec" begin
model = ProxSDP.Optimizer()
@test MOI.supports(model, MOI.TimeLimitSec())
@test MOI.get(model, MOI.TimeLimitSec()) === nothing
MOI.set(model, MOI.TimeLimitSec(), 0.0)
@test MOI.get(model, MOI.TimeLimitSec()) == 0.0
MOI.set(model, MOI.TimeLimitSec(), nothing)
@test MOI.get(model, MOI.TimeLimitSec()) === nothing
MOI.set(model, MOI.TimeLimitSec(), 1.0)
@test MOI.get(model, MOI.TimeLimitSec()) == 1.0
return
end
Loading