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 MethodError principle in MOIU/model #1278

Closed
wants to merge 1 commit into from
Closed

Fix MethodError principle in MOIU/model #1278

wants to merge 1 commit into from

Conversation

odow
Copy link
Member

@odow odow commented Mar 9, 2021

Closes #1277

Now we get nice error messages

julia> MOI.set(model, MOI.ConstraintFunction(), c, MOI.SingleVariable(x))
ERROR: ArgumentError: Cannot modify functions of different types.
Constraint type is MathOptInterface.ScalarAffineFunction{Float64} while the replacement
function is of type MathOptInterface.SingleVariable.
Stacktrace:
 [1] throw_set_error_fallback(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintFunction, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.SingleVariable; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/oscar/.julia/dev/MathOptInterface/src/attributes.jl:1255
 [2] throw_set_error_fallback(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintFunction, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.SingleVariable) at /Users/oscar/.julia/dev/MathOptInterface/src/attributes.jl:1255
 [3] set(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintFunction, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.SingleVariable) at /Users/oscar/.julia/dev/MathOptInterface/src/attributes.jl:396
 [4] top-level scope at REPL[8]:1

julia> MOI.set(model, MOI.ConstraintSet(), c, MOI.LessThan(1.0))
ERROR: ArgumentError: Cannot modify sets of different types. Constraint
type is MathOptInterface.EqualTo{Float64} while the replacement set is of
type MathOptInterface.LessThan{Float64}. Use `transform` instead.
Stacktrace:
 [1] throw_set_error_fallback(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintSet, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.LessThan{Float64}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/oscar/.julia/dev/MathOptInterface/src/attributes.jl:1284
 [2] throw_set_error_fallback(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintSet, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.LessThan{Float64}) at /Users/oscar/.julia/dev/MathOptInterface/src/attributes.jl:1284
 [3] set(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintSet, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.LessThan{Float64}) at /Users/oscar/.julia/dev/MathOptInterface/src/attributes.jl:396
 [4] top-level scope at REPL[9]:1

@odow odow added Submodule: Utilities About the Utilities submodule Type: Bug labels Mar 9, 2021
@odow odow requested a review from blegat March 10, 2021 08:00
::MOI.ConstraintFunction,
ci::CI{MOI.SingleVariable},
change::MOI.AbstractFunction,
::MOI.ConstraintIndex{MOI.SingleVariable,<:MOI.AbstractSet},
Copy link
Member

Choose a reason for hiding this comment

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

AbstractScalarSet

@blegat
Copy link
Member

blegat commented Mar 10, 2021

Again, I'd rather merge #1245 first :)

@odow
Copy link
Member Author

odow commented Mar 11, 2021

Closing in favor of #1284. The diff was a pain to rebase so I made a new PR.

@odow odow closed this Mar 11, 2021
@odow odow deleted the od/method branch March 11, 2021 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Submodule: Utilities About the Utilities submodule Type: Bug
Development

Successfully merging this pull request may close these issues.

MOI.Utilities violates the MethodError principle
2 participants