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

Add result fallbacks #447

Merged
merged 10 commits into from
Aug 10, 2018
Merged

Add result fallbacks #447

merged 10 commits into from
Aug 10, 2018

Conversation

blegat
Copy link
Member

@blegat blegat commented Aug 3, 2018

As discussed in #442 and JuliaOpt/LinQuadOptInterface.jl#41, some solver API do not contain any getters for result informations that can be deduced for variable primals and constraint duals of non-variablewise constraints.

These include the following:

  • ObjectiveValue: can be deduced from VariablePrimal and ObjectiveFunction
  • ObjectiveBound: can be deduced from ConstraintDual and constants in ConstraintFunction's and ConstraintSet's
  • ConstraintPrimal: can be deduced from ConstraintFunction's and VariablePrimal's
  • ConstraintDual of variablewise constraints: can be deduced from ConstraintDual of non-variablewise constraints, ObjectiveFunction and ConstraintFunction's.

This PR

  • moves the fallback already used by MockOptimizer for ObjectiveValue and ConstraintPrimal to a new get_fallback function that is independent of the MockOptimizer.
  • creates a fallback for ConstraintDual and use it for MockOptimizer in the tests (it can also be useful for solving Farkas duals for variable bounds JuliaOpt/LinQuadOptInterface.jl#41)
  • Introduce set_dot and dot_coefficients as new set functions that need to be implemented. They have a default implementation for non-triangle sets.
  • renames evalobjective to eval_objective_value in MockOptimizer to make place to eval_objective_bound

TODO:

  • Document get_fallback

src/sets.jl Outdated
@@ -306,6 +365,29 @@ end

dimension(s::PositiveSemidefiniteConeSquare) = s.side_dimension^2

function square_dot(x::Vector{T}, y::Vector{T}, dim::Int, offset::Int) where T
@show x
Copy link
Member

Choose a reason for hiding this comment

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

Debugging code?

src/sets.jl Outdated
dimension(s::Union{LogDetConeSquare, RootDetConeSquare}) = 1 + s.side_dimension^2
#function set_dot(x::Vector, y::Vector, set::Union{LogDetConeSquare,
Copy link
Member

Choose a reason for hiding this comment

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

Commented code?

@@ -0,0 +1,196 @@
"""
Copy link
Member

Choose a reason for hiding this comment

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

Explain the purpose of this file and how solver wrappers should use it.

src/sets.jl Outdated
Return the scalar product between a vector `x` of the set `set` and a vector
`y` of the dual of the set `s`.
"""
function set_dot(x::Vector, y::Vector, set::AbstractVectorSet)
Copy link
Member

Choose a reason for hiding this comment

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

I think these methods belong in MOIU rather than MOI. They're helpers for implementing MOI and aren't necessary for the API.

Copy link
Member Author

Choose a reason for hiding this comment

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

If someone defines a new set with a non-trivial inner product, he is forced to define set_dot and dot_coefficients otherwise all codes using these functions fails. As this is mandatory, this is part of the API, isn't it ?

Copy link
Member

Choose a reason for hiding this comment

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

Is there code using these functions outside of MOIU? The get_fallback should be opt-in by the solver and not automatic.

@blegat blegat force-pushed the bl/resultfallback branch from 8e470e1 to 6daeee3 Compare August 6, 2018 16:49
@codecov-io
Copy link

codecov-io commented Aug 6, 2018

Codecov Report

Merging #447 into master will decrease coverage by 0.02%.
The diff coverage is 92.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #447      +/-   ##
==========================================
- Coverage   95.28%   95.26%   -0.03%     
==========================================
  Files          42       43       +1     
  Lines        4983     5087     +104     
==========================================
+ Hits         4748     4846      +98     
- Misses        235      241       +6
Impacted Files Coverage Δ
src/Utilities/mockoptimizer.jl 95.7% <100%> (+0.49%) ⬆️
src/sets.jl 100% <100%> (ø) ⬆️
src/Test/contconic.jl 100% <100%> (ø) ⬆️
src/attributes.jl 96.61% <100%> (+0.05%) ⬆️
src/Utilities/model.jl 97.1% <50%> (-0.4%) ⬇️
src/Utilities/results.jl 92.94% <92.94%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7c4d2d...62285b9. Read the comment docs.

@blegat blegat force-pushed the bl/resultfallback branch from 6daeee3 to 64b7db4 Compare August 8, 2018 16:21
@blegat
Copy link
Member Author

blegat commented Aug 8, 2018

Good to merge ?

Copy link
Member

@mlubin mlubin left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, busy week.

@@ -0,0 +1,283 @@
# This file contains the implementation of different methods for the
# `get_fallback` function. These methods can be used by solver wrappers as
# fallbacks for implemented the `get` method when the solver API does not
Copy link
Member

Choose a reason for hiding this comment

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

"for implemented" -> "for implementing"

func = MOI.get(model, MOI.ConstraintFunction(), constraint_index)
if (F == MOI.SingleVariable && func.variable == vi) ||
(F == MOI.VectorOfVariables && vi in func.variables)
error("Fallback getter for variable constraint dual does not support other variable-wise constraints on the variable.")
Copy link
Member

Choose a reason for hiding this comment

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

Nit: line break the error message (using * to concat strings)

::Type{<:Union{MOI.ScalarQuadraticFunction,
MOI.VectorQuadraticFunction}},
::Type{<:MOI.AbstractSet})
error("Fallback getter for variable constraint dual only supports affine constraint functions.")
Copy link
Member

Choose a reason for hiding this comment

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

What happens if a user sees this error message? Does it indicate an internal error in the solver wrapper or that the user did something wrong? (Same with similar errors below.)

Copy link
Member Author

Choose a reason for hiding this comment

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

An error on the wrapper, the wrapper shouldn't call this if there are double variable bounds or quadratic functions

Copy link
Member

@mlubin mlubin Aug 10, 2018

Choose a reason for hiding this comment

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

This should be reflected in the error messages to help users if they see it.

return 0.0
end

function variable_dual(::MOI.ModelLike,
Copy link
Member

Choose a reason for hiding this comment

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

This function has lots of methods that aren't obvious to understand. It needs a docstring or at least a comment.

@@ -380,6 +380,24 @@ it has non-integer coefficient and `F` is `ScalarAffineFunction{Int}`.
"""
struct ObjectiveFunction{F<:AbstractScalarFunction} <: AbstractModelAttribute end

"""
ObjectiveFunctionType()
Copy link
Member

Choose a reason for hiding this comment

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

Add this to the list of attributes in the docs.

Copy link
Member

@mlubin mlubin left a comment

Choose a reason for hiding this comment

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

Good to merge after tweaking the error message as discussed inline.

@blegat blegat merged commit 8c06b3c into master Aug 10, 2018
@blegat blegat deleted the bl/resultfallback branch August 28, 2018 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants