-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Add solve_time function #1928
Add solve_time function #1928
Changes from 5 commits
f019bde
cfd5f3f
6c68993
7d21bbc
9660ed2
9e40df3
ac31b89
a6f9dd5
b375de5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,6 +328,21 @@ function test_model() | |
@test optimizer.b == 2 | ||
end | ||
|
||
@testset "solve_time" begin | ||
@testset "NoOptimizer()" begin | ||
err = NoOptimizer() | ||
model = Model() | ||
@test_throws err solve_time(model) | ||
end | ||
|
||
@testset "OptimizeNotCalled()" begin | ||
err = OptimizeNotCalled() | ||
model = Model(with_optimizer(MOIU.MockOptimizer, | ||
SimpleLPModel{Float64}())) | ||
@test_throws err solve_time(model) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add a test where it works by using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not getting exactly how to do this. I have tried model = Model(with_optimizer(MOIU.MockOptimizer,
MOIU.UniversalFallback(JuMP._MOIModel{Float64}())))
JuMP.solve_time(model) but gives an error ERROR: OptimizeNotCalled()
Stacktrace:
[1] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{JuMP._MOIModel{Float64}}}, ::MathOptInterface.SolveTime) at /Users/guilhermebodin/Documents/JuMP.jl/src/JuMP.jl:594
[2] get(::Model, ::MathOptInterface.SolveTime) at /Users/guilhermebodin/Documents/JuMP.jl/src/JuMP.jl:609
[3] solve_time(::Model) at /Users/guilhermebodin/Documents/JuMP.jl/src/JuMP.jl:448
[4] top-level scope at none:0 and model = Model(with_optimizer(MOIU.MockOptimizer,
MOIU.UniversalFallback(JuMP._MOIModel{Float64}())))
optimize!(model)
JuMP.solve_time(model) gives the same error ERROR: OptimizeNotCalled()
Stacktrace:
[1] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{JuMP._MOIModel{Float64}}}, ::MathOptInterface.SolveTime) at /Users/guilhermebodin/Documents/JuMP.jl/src/JuMP.jl:594
[2] get(::Model, ::MathOptInterface.SolveTime) at /Users/guilhermebodin/Documents/JuMP.jl/src/JuMP.jl:609
[3] solve_time(::Model) at /Users/guilhermebodin/Documents/JuMP.jl/src/JuMP.jl:448
[4] top-level scope at none:0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can try mock = MOIU.MockOptimizer(MOIU.UniversalFallback(JuMP._MOIModel{Float64}())))
mock.optimize! = mock -> begin
MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL)
MOI.set(mock, MOI.SolveTime(), 2.0)
end
model = direct_model(mock)
optimize!(model)
@test solve_time(model) == 2.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives this error ERROR: ArgumentError: `supports` is not defined for MathOptInterface.SolveTime(), it is only defined for attributes such that `is_copyable` returns `true`.
Stacktrace:
[1] supports(::JuMP._MOIModel{Float64}, ::MathOptInterface.SolveTime) at /Users/guilhermebodin/.julia/packages/MathOptInterface/C3lip/src/attributes.jl:118
[2] set(::MathOptInterface.Utilities.UniversalFallback{JuMP._MOIModel{Float64}}, ::MathOptInterface.SolveTime, ::Float64) at /Users/guilhermebodin/.julia/packages/MathOptInterface/C3lip/src/Utilities/universalfallback.jl:284
[3] set(::MathOptInterface.Utilities.MockOptimizer{MathOptInterface.Utilities.UniversalFallback{JuMP._MOIModel{Float64}}}, ::MathOptInterface.SolveTime, ::Float64) at /Users/guilhermebodin/.julia/packages/MathOptInterface/C3lip/src/Utilities/mockoptimizer.jl:157
[4] (::getfield(Main, Symbol("##17#18")))(::MathOptInterface.Utilities.MockOptimizer{MathOptInterface.Utilities.UniversalFallback{JuMP._MOIModel{Float64}}}) at ./REPL[61]:3
[5] optimize!(::MathOptInterface.Utilities.MockOptimizer{MathOptInterface.Utilities.UniversalFallback{JuMP._MOIModel{Float64}}}) at /Users/guilhermebodin/.julia/packages/MathOptInterface/C3lip/src/Utilities/mockoptimizer.jl:113
[6] #optimize!#79(::Bool, ::Bool, ::Function, ::Model, ::Nothing) at /Users/guilhermebodin/Documents/JuMP.jl/src/optimizer_interface.jl:132
[7] optimize! at /Users/guilhermebodin/Documents/JuMP.jl/src/optimizer_interface.jl:105 [inlined] (repeats 2 times)
[8] top-level scope at none:0 because of the MOI function """
is_set_by_optimize(::AnyAttribute)
Return a `Bool` indicating whether the value of the attribute is modified
during an [`optimize!`](@ref) call, that is, the attribute is used to query
the result of the optimization.
## Important note when defining new attributes
This function returns `false` by default so it should be implemented for
attributes that are modified by [`optimize!`](@ref).
"""
is_set_by_optimize(::AnyAttribute) = false
function is_set_by_optimize(::Union{ObjectiveValue,
ObjectiveBound,
RelativeGap,
SolveTime,
SimplexIterations,
BarrierIterations,
NodeCount,
RawSolver,
ResultCount,
TerminationStatus,
RawStatusString,
PrimalStatus,
DualStatus,
VariablePrimal,
ConstraintPrimal,
ConstraintDual,
ConstraintBasisStatus})
return true
end is there another way to call the optimizer, I mean without having to call the optimize! function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, you can leave a TODO while jump-dev/MathOptInterface.jl#707 is not solved |
||
end | ||
|
||
@testset "solver_name" begin | ||
@testset "Not attached" begin | ||
model = Model() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the solve time is not available? This is useful to document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, today it returns
but we could redesign as
@blegat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think 9e40df3 is needed. Catching all ArumentError is too wide and the error message is already quite clear. Adding a sentence in the docstring is enough