Skip to content

Commit

Permalink
Use MOI.instantiate to create a new optimizer (#431)
Browse files Browse the repository at this point in the history
* Use MOI.instantiate to create a new optimizer

* Update test_utilities.jl
  • Loading branch information
odow committed Mar 27, 2021
1 parent 4068f80 commit 422f4fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,9 @@ function load_MOI_model!(model, problem::Problem{T}) where {T}
return id_to_variables, conic_constr_to_constr, conic_constraints, var_to_indices, constraint_indices
end

function solve!(problem::Problem{T}, optimizer; kwargs...) where {T}
if Base.applicable(optimizer)
return solve!(problem, optimizer(); kwargs...)
else
throw(ArgumentError("MathProgBase solvers like `solve!(problem, SCSSolver())` are no longer supported. Use instead e.g. `solve!(problem, SCS.Optimizer)`."))
end
function solve!(problem::Problem{T}, optimizer_factory; kwargs...) where {T}
optimizer = MOI.instantiate(optimizer_factory)
return solve!(problem, optimizer; kwargs...)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end
@testset "`solve!` with MPB solver errors" begin
x = Variable()
p = satisfy(x >= 0)
@test_throws ArgumentError solve!(p, SCSSolver())
@test_throws ErrorException solve!(p, SCSSolver())
end

@testset "Complex objective function errors" begin
Expand Down

0 comments on commit 422f4fc

Please sign in to comment.