Giter Club home page Giter Club logo

Comments (10)

odow avatar odow commented on July 17, 2024 1

No, it results in the same issue and it is the reproducer. I have identified the fix.

I don't know what you've done to your Julia instance, but you must be @evaling some code somewhere to get the world age issue.

from mathoptinterface.jl.

odow avatar odow commented on July 17, 2024 1

I mean, one could argue that they should be supported via falling back to the non-linear constraints

HiGHS does not support nonlinear constraints either. It is a mixed-integer linear solver, with additional support for continuous linear problems with a quadratic objective function.

from mathoptinterface.jl.

odow avatar odow commented on July 17, 2024 1

would it be useful to file an issue here about potentially bridging

No. We won't bridge constraints based on some numerical structure. Bridges must (with some limited exceptions) support any input data. In this case, you are asking if ScalarQuadraticFunction-in-EqualTo can be bridged to a collection of affine indicator constraints. This is only possible in your case where at least one element in each quadratic term is binary.

Instead of trying to write JuMP models using the high-level syntax like --> etc, if you know that you want to use HiGHS to solve the problem then I strongly encourage you to write out the MIP reformulation by hand.

from mathoptinterface.jl.

odow avatar odow commented on July 17, 2024

Reproducer:

julia> using JuMP, HiGHS

julia> model = Model(HiGHS.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: HiGHS

julia> @variable(model, x)
x

julia> @variable(model, z, Bin)
z

julia> @constraint(model, z --> {x * z == 0})
z --> {x*z = 0}

julia> optimize!(model)
Running HiGHS 1.7.0 (git hash: 50670fd4c): Copyright (c) 2024 HiGHS under MIT licence terms
ERROR: MethodError: no method matching bridge_constraint(::Type{…}, ::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, ::MathOptInterface.VectorQuadraticFunction{…}, ::MathOptInterface.Indicator{…})

Closest candidates are:
  bridge_constraint(::Type{MathOptInterface.Bridges.Constraint.VectorSlackBridge{T, F, S}}, ::Any, ::MathOptInterface.AbstractVectorFunction, ::S) where {T, F, S}
   @ MathOptInterface ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/Constraint/bridges/slack.jl:351
  bridge_constraint(::Type{<:MathOptInterface.Bridges.Constraint.MultiSetMapBridge{T, S1, G}}, ::MathOptInterface.ModelLike, ::G, ::S1) where {T, S1, G}
   @ MathOptInterface ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/Constraint/set_map.jl:37
  bridge_constraint(::Type{MathOptInterface.Bridges.Constraint.NumberConversionBridge{T, F1, S1, F2, S2}}, ::MathOptInterface.ModelLike, ::F1, ::S1) where {T, F1, S1, F2, S2}
   @ MathOptInterface ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/Constraint/bridges/number_conversion.jl:46
  ...

Stacktrace:
  [1] add_bridged_constraint(b::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, BridgeType::Type, f::MathOptInterface.VectorQuadraticFunction{…}, s::MathOptInterface.Indicator{…})
    @ MathOptInterface.Bridges ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/bridge_optimizer.jl:1786
  [2] add_constraint(b::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, f::MathOptInterface.VectorQuadraticFunction{…}, s::MathOptInterface.Indicator{…})
    @ MathOptInterface.Bridges ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/bridge_optimizer.jl:1916
  [3] _copy_constraints(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, src::MathOptInterface.Utilities.UniversalFallback{…}, index_map::MathOptInterface.Utilities.IndexMap, index_map_FS::MathOptInterface.Utilities.DoubleDicts.IndexDoubleDictInner{…}, cis_src::Vector{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2CULs/src/Utilities/copy.jl:259
  [4] _copy_constraints(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, src::MathOptInterface.Utilities.UniversalFallback{…}, index_map::MathOptInterface.Utilities.IndexMap, cis_src::Vector{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2CULs/src/Utilities/copy.jl:271
  [5] pass_nonvariable_constraints_fallback(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, src::MathOptInterface.Utilities.UniversalFallback{…}, index_map::MathOptInterface.Utilities.IndexMap, constraint_types::Vector{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2CULs/src/Utilities/copy.jl:282
  [6] pass_nonvariable_constraints(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, src::MathOptInterface.Utilities.UniversalFallback{…}, idxmap::MathOptInterface.Utilities.IndexMap, constraint_types::Vector{…})
    @ MathOptInterface.Bridges ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/bridge_optimizer.jl:445
  [7] _pass_constraints(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, src::MathOptInterface.Utilities.UniversalFallback{…}, index_map::MathOptInterface.Utilities.IndexMap, variable_constraints_not_added::Vector{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2CULs/src/Utilities/copy.jl:330
  [8] default_copy_to(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, src::MathOptInterface.Utilities.UniversalFallback{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2CULs/src/Utilities/copy.jl:505
  [9] copy_to
    @ ~/.julia/packages/MathOptInterface/2CULs/src/Bridges/bridge_optimizer.jl:455 [inlined]
 [10] optimize!
    @ ~/.julia/packages/MathOptInterface/2CULs/src/MathOptInterface.jl:84 [inlined]
 [11] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2CULs/src/Utilities/cachingoptimizer.jl:316
 [12] optimize!(model::Model; ignore_optimize_hook::Bool, _differentiation_backend::MathOptInterface.Nonlinear.SparseReverseMode, kwargs::@Kwargs{})
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/optimizer_interface.jl:457
 [13] optimize!(model::Model)
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/optimizer_interface.jl:409
 [14] top-level scope
    @ REPL[264]:1
Some type information was truncated. Use `show(err)` to see complete types.

from mathoptinterface.jl.

LebedevRI avatar LebedevRI commented on July 17, 2024

That reproducer results in

Running HiGHS 1.6.0: Copyright (c) 2023 HiGHS under MIT licence terms
KERNEL EXCEPTION
MethodError: no method matching namemap(::Type{MathOptInterface.ActivationCondition})
The applicable method may be too new: running in world age 31466, while current world is 31501.

Closest candidates are:
  namemap(::Type{MathOptInterface.ActivationCondition}) (method too new to be called from this world context.)
   @ MathOptInterface Enums.jl:214
  namemap(::Type{MathOptInterface.OptimizationSense}) (method too new to be called from this world context.)
   @ MathOptInterface Enums.jl:214
  namemap(::Type{LibGit2.Consts.GIT_TRACE_LEVEL})
   @ LibGit2 Enums.jl:214
  ...

which seems like a different issue from the one i posted.

from mathoptinterface.jl.

odow avatar odow commented on July 17, 2024

Fix is #2507

Your underlying issue is that you cannot solve this constraint with HiGHS.jl. The next version of MOI will throw a better error instead of the uninformative MethodError.

[f=1:NUM_FRAMES, s=1:NUM_SWITCHES],  SwitchDrivePower[f,s] --> { SwitchDriveDirection[f,s] == SwitchDrivePower[f,s] * SwitchDriveState[f,s] - 1 }

from mathoptinterface.jl.

LebedevRI avatar LebedevRI commented on July 17, 2024

@odow thank you for taking a look!

Yup, i very much expected that it would be too good to work :)
The more faithful repro, which also does not work is

using JuMP, HiGHS
model = Model(HiGHS.Optimizer)
@variable(model, -1 <= x <= 1, Int)
@variable(model, -1 <= y <= 1, Int)
@variable(model, z, Bin)

# Variant using indicator constraints, works, but indicator constraints...
#@constraint(model, !z --> { y == 0 } )
#@constraint(model, z --> { y == x - 1 } )

@constraint(model, y == z * (x-1))
# You'd think it'd work, but:
# Constraints of type MathOptInterface.ScalarQuadraticFunction{Float64}-in-MathOptInterface.EqualTo{Float64} are not supported by the solver.

optimize!(model)

from mathoptinterface.jl.

odow avatar odow commented on July 17, 2024

HiGHS does not support quadratic constraints.

from mathoptinterface.jl.

LebedevRI avatar LebedevRI commented on July 17, 2024

Yes, i've understood that from the docs.
(I mean, one could argue that they should be supported via falling back to the non-linear constraints.)
I'm just showing the true snippet i was going for.
@odow thank you!

from mathoptinterface.jl.

LebedevRI avatar LebedevRI commented on July 17, 2024

@odow thank you.

Question:
would it be useful to file an issue here about potentially bridging

using JuMP, HiGHS
model = Model(HiGHS.Optimizer)
@variable(model, -1 <= x <= 1, Int)
@variable(model, -1 <= y <= 1, Int)
@variable(model, z, Bin)

@constraint(model, y == z * x)
   =>
@constraint(model, !z --> { y == 0 } )
@constraint(model, z --> { y == x } )

?

I mean, one could argue that they should be supported via falling back to the non-linear constraints

HiGHS does not support nonlinear constraints either. It is a mixed-integer linear solver, with additional support for continuous linear problems with a quadratic objective function.

Again, i get that :) What i meant is, there seems to be (some?) support in JuMP for user-defined functions,
so perhaps the unsupported function types could be wrapped into such functions instead.

from mathoptinterface.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.