Skip to content

Commit

Permalink
Add primal/dual warm starts (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jan 4, 2022
1 parent 12f994e commit 89698da
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
67 changes: 49 additions & 18 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,25 @@ end
### MOI.AbstractVariableAttribute
###

# TODO(odow): support variable primal starts
# function MOI.supports(
# ::Optimizer,
# ::MOI.VariablePrimalStart,
# ::Type{MOI.VariableIndex},
# )
# return true
# end
function MOI.supports(
::Optimizer,
::MOI.VariablePrimalStart,
::Type{MOI.VariableIndex},
)
return true
end

###
### MOI.AbstractConstraintAttribute
###

# TODO(odow): support constraint primal and dual starts
# function MOI.supports(
# ::Optimizer,
# ::Union{MOI.ConstraintPrimalStart,MOI.ConstraintDualStart},
# ::Type{<:MOI.ConstraintIndex},
# )
# return true
# end
function MOI.supports(
::Optimizer,
::Union{MOI.ConstraintPrimalStart,MOI.ConstraintDualStart},
::Type{<:MOI.ConstraintIndex},
)
return true
end

function MOI.supports_constraint(
::Optimizer,
Expand Down Expand Up @@ -248,11 +246,43 @@ function MOI.optimize!(
end
# Set starting values and throw error for other variable attributes
vis_src = MOI.get(src, MOI.ListOfVariableIndices())
MOI.Utilities.pass_attributes(dest, src, index_map, vis_src)
for attr in MOI.get(src, MOI.ListOfVariableAttributesSet())
if attr == MOI.VariableName()
# Skip
elseif attr == MOI.VariablePrimalStart()
for (i, x) in enumerate(vis_src)
dest.sol.primal[i] = something(MOI.get(src, attr, x), 0.0)
end
else
throw(MOI.UnsupportedAttribute(attr))
end
end
# Set starting values and throw error for other constraint attributes
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
cis_src = MOI.get(src, MOI.ListOfConstraintIndices{F,S}())
MOI.Utilities.pass_attributes(dest, src, index_map, cis_src)
for attr in MOI.get(src, MOI.ListOfConstraintAttributesSet{F,S}())
if attr == MOI.ConstraintName()
# Skip
elseif attr == MOI.ConstraintPrimalStart()
for ci in cis_src
start = MOI.get(src, attr, ci)
if start !== nothing
rows = MOI.Utilities.rows(Ab, ci)
dest.sol.slack[rows] .= start
end
end
elseif attr == MOI.ConstraintDualStart()
for ci in cis_src
start = MOI.get(src, attr, ci)
if start !== nothing
rows = MOI.Utilities.rows(Ab, ci)
dest.sol.dual[rows] .= start
end
end
else
throw(MOI.UnsupportedAttribute(attr))
end
end
end
options = copy(dest.options)
if dest.silent
Expand Down Expand Up @@ -284,6 +314,7 @@ function MOI.optimize!(
dest.sol.primal,
dest.sol.dual,
dest.sol.slack;
warm_start = true,
options...,
)
# If the solution is an infeasibility certificate, the objective values are
Expand Down
2 changes: 2 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function _test_runtests(linear_solver)
exclude = String[
# TODO(odow): unimplemented features
"test_attribute_SolverVersion",
# TODO(odow): get not supported for primal/dual starts
"test_model_ModelFilter_AbstractConstraintAttribute",
# Expected test failures:
# ArgumentError: The number of constraints must be greater than 0
"test_attribute_RawStatusString",
Expand Down

6 comments on commit 89698da

@kalmarek
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odow could we tag 0.8.2 on this commit maybe?

@odow
Copy link
Member Author

@odow odow commented on 89698da Jan 18, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odow
Copy link
Member Author

@odow odow commented on 89698da Jan 18, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kalmarek
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odow it's the last one before merging SCS-3.0.
I know that I do have the permissions, but since I'm not the only maintainer I prefer to communicate before non-obvious decisions ;)

@kalmarek
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/52709

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.2 -m "<description of version>" 89698da8319fd8b71a8913967dac19d4ad565115
git push origin v0.8.2

Please sign in to comment.